Leeches are segmented parasitic or predatory worms that comprise the subclass Hirudinea within the phylum Annelida. They are closely related to the oligochaetes, which include the earthworm, and like them have soft, muscular segmented bodies that can lengthen and contract. Both groups are hermaphrodites and have a clitellum, but leeches typically differ from the oligochaetes in having suckers at both ends and in having ring markings that do not correspond with their internal segmentation. The body is muscular and relatively solid, and the coelom, the spacious body cavity found in other annelids, is reduced to small channels.
 The majority of leeches live in freshwater habitats, while some species can be found in terrestrial or marine environments. The best-known species, such as the medicinal leech, Hirudo medicinalis, are hematophagous, attaching themselves to a host with a sucker and feeding on blood, having first secreted the peptide hirudin to prevent the blood from clotting. The jaws used to pierce the skin are replaced in other species by a proboscis which is pushed into the skin. A minority of leech species are predatory, mostly preying on small invertebrates.
 The eggs are enclosed in a cocoon, which in aquatic species is usually attached to an underwater surface; members of one family, Glossiphoniidae, exhibit parental care, the eggs being brooded by the parent. In terrestrial species, the cocoon is often concealed under a log, in a crevice or buried in damp soil. Almost seven hundred species of leech are currently recognised, of which some hundred are marine, ninety terrestrial and the remainder freshwater.
 Leeches have been used in medicine from ancient times until the 19th century to draw blood from patients. In modern times, leeches find medical use in treatment of joint diseases such as epicondylitis and osteoarthritis, extremity vein diseases, and in microsurgery, while hirudin is used as an anticoagulant drug to treat blood-clotting disorders.
 The leech appears in the biblical Book of Proverbs as an archetype of insatiable greed. The term "leech" is used to characterise a person who takes without giving, living at the expense of others.
 Some 680 species of leech have been described, of which around 100 are marine, 480 freshwater and the remainder terrestrial. Among Euhirudinea, the true leeches, the smallest is about 1 cm (1⁄2 in) long, and the largest is the giant Amazonian leech, Haementeria ghilianii, which can reach 30 cm (12 in). Except for Antarctica, leeches are found throughout the world but are at their most abundant in temperate lakes and ponds in the northern hemisphere. The majority of freshwater leeches are found in the shallow, vegetated areas on the edges of ponds, lakes and slow-moving streams; very few species tolerate fast-flowing water. In their preferred habitats, they may occur in very high densities; in a favourable environment with water high in organic pollutants, over 10,000 individuals were recorded per square metre (over 930 per square foot) under rocks in Illinois. Some species aestivate during droughts, burying themselves in the sediment, and can lose up to 90% of their bodyweight and still survive. Among the freshwater leeches are the Glossiphoniidae, dorso-ventrally flattened animals mostly parasitic on vertebrates such as turtles, and unique among annelids in both brooding their eggs and carrying their young on the underside of their bodies.
 The terrestrial Haemadipsidae are mostly native to the tropics and subtropics, while the aquatic Hirudinidae have a wider global range; both of these feed largely on mammals, including humans. A distinctive family is the Piscicolidae, marine or freshwater ectoparasites chiefly of fish, with cylindrical bodies and usually well-marked, bell-shaped, anterior suckers. Not all leeches feed on blood; the Erpobdelliformes, freshwater or amphibious, are carnivorous and equipped with a relatively large, toothless mouth to ingest insect larvae, molluscs, and other annelid worms, which are swallowed whole. In turn, leeches are prey to fish, birds, and invertebrates.
 The name for the subclass, Hirudinea, comes from the Latin hirudo (genitive hirudinis), a leech; the element -bdella found in many leech group names is from the Greek βδέλλα bdella, also meaning leech. The name Les hirudinées was given by Jean-Baptiste Lamarck in 1818. Leeches were traditionally divided into two infraclasses, the Acanthobdellidea (primitive leeches) and the Euhirudinea (true leeches). The Euhirudinea are divided into the proboscis-bearing Rhynchobdellida and the rest, including some jawed species, the "Arhynchobdellida", without a proboscis.
 The phylogenetic tree of the leeches and their annelid relatives is based on molecular analysis (2019) of DNA sequences. Both the former classes "Polychaeta" (bristly marine worms) and "Oligochaeta" (including the earthworms) are paraphyletic: in each case the complete groups (clades) would include all the other groups shown below them in the tree. The Branchiobdellida are sister to the leech clade Hirudinida, which approximately corresponds to the traditional subclass Hirudinea. The main subdivision of leeches is into the Rhynchobdellida and the Arhynchobdellida, though the Acanthobdella are sister to the clade that contains these two groups.
 "Polychaeta" (exc. "Oligochaeta") 
 "Oligochaeta" (exc. Lumbriculidae) 
 Lumbriculidae (blackworms) 
 
 Acanthobdella 
 Erpobdelliformes 
 Hirudiniformes 
 Glossiphoniidae 
 Piscicolidae 
 Ozobranchidae 
 The most ancient annelid group consists of the free-living polychaetes that evolved in the Cambrian period, being plentiful in the Burgess Shale about 500 million years ago. Oligochaetes evolved from polychaetes and the leeches branched off from the oligochaetes. The oldest leech fossils are from the middle Permian period around 266 million years ago, there is also unpublished study about possible leech from Virgilian (Late Carboniferous) of New Mexico. Although fossil with external ring markings found from Silurian strata in Wisconsin is sometimes identified as leech, but assignment of fossil is still putative and contentious, and the animal was also alternatively interpreted as a member of Cycloneuralia.
 Leeches show a remarkable similarity to each other in morphology, very different from typical annelids which are cylindrical with a fluid-filled space, the coelom (body cavity). In leeches, most of the coelom is filled with botryoidal tissue, a loose connective tissue composed of clusters of cells of mesodermal origin. The remaining body cavity has been reduced to four slender longitudinal channels. Typically, the body is dorso-ventrally flattened and tapers at both ends. Longitudinal and circular muscles in the body wall are supplemented by diagonal muscles, giving the leech the ability to adopt a large range of body shapes and show great flexibility. Most leeches have a sucker at both the anterior (front) and posterior (back) ends, but some primitive leeches have a single sucker at the back.
 Like most annelids, with a few exceptions like Sipuncula, Echiura and Diurodrilus, the leech is a segmented animal, but unlike other annelids, the segmentation is masked by secondary external ring markings (annuli). The number of annulations varies, both between different regions of the body and between species. In one species, the body surface is divided into 102 annuli. All leech species, however, have 32 segments, called somites, (34 if two head segments, which have different organization, are counted). Of these segments, the first five are designated as the head and include the anterior brain, several ocelli (eyespots) dorsally and the sucker ventrally. The following 21 mid-body segments each contain a nerve ganglion, and between them contain two reproductive organs, a single female gonopore and nine pairs of testes. The last seven segments contain the posterior brain and are fused to form the animal's tail sucker. The septa that separates the body segments—and the mesenteries which in turn separates each segment into a left and right half—in the majority of annelids, have been lost in leeches except for the primitive genus Acanthobdella, which still have some septa and mesenteries.
 The body wall consists of a cuticle, an epidermis and a thick layer of fibrous connective tissue in which are embedded the circular muscles, the diagonal muscles and the powerful longitudinal muscles. There are also dorso-ventral muscles. In leeches the original blood vascular system has been lost and replaced by the modified coelom known as the haemocoelomic system, and the coelomic fluid, called the haemocoelomic fluid, has taken over the role as blood. The haemocoelomic channels run the full length of the body, the two main ones being on either side. Part of the lining epithelium consists of chloragogen cells which are used for the storage of nutrients and in excretion. There are 10 to 17 pairs of metanephridia (excretory organs) in the mid-region of the leech. From these, ducts typically lead to a urinary bladder, which empties to the outside at a nephridiopore.
 Leeches are hermaphrodites, with the male reproductive organs, the testes, maturing first and the ovaries later. In hirudinids, a pair will line up with the clitellar regions in contact, with the anterior end of one leech pointing towards the posterior end of the other; this results in the male gonopore of one leech being in contact with the female gonopore of the other. The penis passes a spermatophore into the female gonopore and sperm is transferred to, and probably stored in, the vagina.
 Some jawless leeches (Rhynchobdellida) and proboscisless leeches (Arhynchobdellida) lack a penis, and in these, sperm is passed from one individual to another by hypodermic injection. The leeches intertwine and grasp each other with their suckers. A spermatophore is pushed by one through the integument of the other, usually into the clitellar region. The sperm is liberated and passes to the ovisacs, either through the coelomic channels or interstitially through specialist "target tissue" pathways.
 Some time after copulation, the small, relatively yolkless eggs are laid. In most species, an albumin-filled cocoon is secreted by the clitellum and receives one or more eggs as it passes over the female gonopore. In the case of the North American Erpobdella punctata, the clutch size is about five eggs, and some ten cocoons are produced. Each cocoon is fixed to a submerged object, or in the case of terrestrial leeches, deposited under a stone or buried in damp soil. The cocoon of Hemibdella soleae is attached to a suitable fish host. The glossiphoniids brood their eggs, either by attaching the cocoon to the substrate and covering it with their ventral surface, or by securing the cocoon to their ventral surface, and even carrying the newly hatched young to their first meal.
 When breeding, most marine leeches leave their hosts and become free-living in estuaries. Here they produce their cocoons, after which the adults of most species die. When the eggs hatch, the juveniles seek out potential hosts when these approach the shore. Leeches mostly have an annual or biannual life cycle.
 About three quarters of leech species are parasites that feed on the blood of a host, while the remainder are predators. Leeches either have a pharynx that they can protrude, commonly called a proboscis, or a pharynx that they cannot protrude, which in some groups is armed with jaws.
 In the proboscisless leeches, the jaws (if any) of Arhynchobdellids are at the front of the mouth, and have three blades set at an angle to each other. In feeding, these slice their way through the skin of the host, leaving a Y-shaped incision. Behind the blades is the mouth, located ventrally at the anterior end of the body. It leads successively into the pharynx, a short oesophagus, a crop (in some species), a stomach and a hindgut, which ends at an anus located just above the posterior sucker. The stomach may be a simple tube, but the crop, when present, is an enlarged part of the midgut with a number of pairs of ceca that store ingested blood. The leech secretes an anticoagulant, hirudin, in its saliva which prevents the blood from clotting before ingestion. A mature medicinal leech may feed only twice a year, taking months to digest a blood meal.
 The bodies of predatory leeches are similar, though instead of a jaw many have a protrusible proboscis, which for most of the time they keep retracted into the mouth. Such leeches are often ambush predators that lie in wait until they can strike prey with the proboscises in a spear-like fashion. Predatory leeches feed on small invertebrates such as snails, earthworms and insect larvae. The prey is usually sucked in and swallowed whole. Some Rhynchobdellida however suck the soft tissues from their prey, making them intermediate between predators and blood-suckers.
 Blood-sucking leeches use their anterior suckers to connect to hosts for feeding. Once attached, they use a combination of mucus and suction to stay in place while they inject hirudin into the hosts' blood. In general, blood-feeding leeches are non host-specific, and do little harm to their host, dropping off after consuming a blood meal. Some marine species however remain attached until it is time to reproduce. If present in great numbers on a host, these can be debilitating, and in extreme cases, cause death.
 Leeches are unusual in that they do not produce certain digestive enzymes such as amylases, lipases or endopeptidases. A deficiency of these enzymes and of B complex vitamins is compensated for by enzymes and vitamins produced by endosymbiotic microflora. In Hirudo medicinalis, these supplementary factors are produced by an obligatory mutualistic relationship with the bacterial species, Aeromonas veronii. Non-bloodsucking leeches, such as Erpobdella octoculata, are host to more bacterial symbionts. In addition, leeches produce intestinal exopeptidases which remove amino acids from the long protein molecules one by one, possibly aided by proteases from endosymbiotic bacteria in the hindgut. This evolutionary choice of exopeptic digestion in Hirudinea distinguishes these carnivorous clitellates from oligochaetes, and may explain why digestion in leeches is so slow.
 A leech's nervous system is formed of a few large nerve cells. Their large size makes leeches convenient as model organisms for the study of invertebrate nervous systems. The main nerve centre consists of the cerebral ganglion above the gut and another ganglion beneath it, with connecting nerves forming a ring around the pharynx a little way behind the mouth. A nerve cord runs backwards from this in the ventral coelomic channel, with 21 pairs of ganglia in segments six to 26. In segments 27 to 33, other paired ganglia fuse to form the caudal ganglion. Several sensory nerves connect directly to the cerebral ganglion; there are sensory and motor nerve cells connected to the ventral nerve cord ganglia in each segment.
 Leeches have between two and ten pigment spot ocelli, arranged in pairs towards the front of the body. There are also sensory papillae arranged in a lateral row in one annulation of each segment. Each papilla contains many sensory cells. Some rhynchobdellids have the ability to change colour dramatically by moving pigment in chromatophore cells; this process is under the control of the nervous system but its function is unclear as the change in hue seems unrelated to the colour of the surroundings.
 Leeches can detect touch, vibration, movement of nearby objects, and chemicals secreted by their hosts; freshwater leeches crawl or swim towards a potential host standing in their pond within a few seconds. Species that feed on warm-blooded hosts move towards warmer objects. Many leeches avoid light, though some blood feeders move towards light when they are ready to feed, presumably increasing the chances of finding a host.
 Leeches live in damp surroundings and in general respire through their body wall. The exception to this is in the Piscicolidae, where branching or leaf-like lateral outgrowths from the body wall form gills. Some rhynchobdellid leeches have an extracellular haemoglobin pigment, but this only provides for about half of the leech's oxygen transportation needs, the rest occurring by diffusion.
 Leeches move using their longitudinal and circular muscles in a modification of the locomotion by peristalsis, self-propulsion by alternately contracting and lengthening parts of the body, seen in other annelids such as earthworms. They use their posterior and anterior suckers (one on each end of the body) to enable them to progress by looping or inching along, in the manner of geometer moth caterpillars. The posterior end is attached to the substrate, and the anterior end is projected forward peristaltically by the circular muscles until it touches down, as far as it can reach, and the anterior end is attached. Then the posterior end is released, pulled forward by the longitudinal muscles, and reattached; then the anterior end is released, and the cycle repeats. Leeches explore their environment with head movements and body waving. The Hirudinidae and Erpobdellidae can swim rapidly with up-and-down or sideways undulations of the body; the Glossiphoniidae in contrast are poor swimmers and curl up and fall to the sediment below when disturbed.
 Leech bites are generally alarming rather than dangerous, though a small percentage of people have severe allergic or anaphylactic reactions and require urgent medical care. Symptoms of these reactions include red blotches or an itchy rash over the body, swelling around the lips or eyes, a feeling of faintness or dizziness, and difficulty in breathing. An externally attached leech will detach and fall off on its own accord when it is satiated on blood, which may take from twenty minutes to a few hours; bleeding from the wound may continue for some time. Internal attachments, such as inside the nose, are more likely to require medical intervention.
 Bacteria, viruses, and protozoan parasites from previous blood sources can survive within a leech for months, so leeches could potentially act as vectors of pathogens. Nevertheless, only a few cases of leeches transmitting pathogens to humans have been reported.
 Leech saliva is commonly believed to contain anaesthetic compounds to numb the bite area, but some authorities disagree. Although morphine-like substances have been found in leeches, they have been found in the neural tissues, not the salivary tissues. They are used by the leeches in modulating their own immunocytes and not for anaesthetising bite areas on their hosts. Depending on the species and size, leech bites can be barely noticeable or they can be fairly painful.
 The medicinal leech Hirudo medicinalis, and some other species, have been used for clinical bloodletting for at least 2,500 years: Ayurvedic texts describe their use for bloodletting in ancient India. In ancient Greece, bloodletting was practised according to the theory of humours found in the Hippocratic Corpus of the fifth century BC, which maintained that health depended on a balance of the four humours: blood, phlegm, black bile and yellow bile. Bloodletting using leeches enabled physicians to restore balance if they considered blood was present in excess.
 Pliny the Elder reported in his Natural History that the horse leech could drive elephants mad by climbing up inside their trunks to drink blood. Pliny also noted the medicinal use of leeches in ancient Rome, stating that they were often used for gout, and that patients became addicted to the treatment. In Old English, lǣce was the name for a physician as well as for the animal, though the words had different origins, and lǣcecraft, leechcraft, was the art of healing.
 William Wordsworth's 1802 poem "Resolution and Independence" describes one of the last of the leech-gatherers, people who travelled Britain catching leeches from the wild, and causing a sharp decline in their abundance, though they remain numerous in Romney Marsh. By 1863, British hospitals had switched to imported leeches, some seven million being imported to hospitals in London that year. 

 In the nineteenth century, demand for leeches was sufficient for hirudiculture, the farming of leeches, to become commercially viable. Leech usage declined with the demise of humoral theory, but made a small-scale comeback in the 1980s after years of decline, with the advent of microsurgery, where venous congestion can arise due to inefficient venous drainage. Leeches can reduce swelling in the tissues and promote healing, helping in particular to restore circulation after microsurgery to reattach body parts. Other clinical applications include varicose veins, muscle cramps, thrombophlebitis, and joint diseases such as epicondylitis and osteoarthritis.
 Leech secretions contain several bioactive substances with anti-inflammatory, anticoagulant and antimicrobial effects. One active component of leech saliva is a small protein, hirudin. It is widely used as an anticoagulant drug to treat blood-clotting disorders, and manufactured by recombinant DNA technology.
 In 2012 and 2018, Ida Schnell and colleagues trialled the use of Haemadipsa leeches to gather data on the biodiversity of their mammalian hosts in the tropical rainforest of Vietnam, where it is hard to obtain reliable data on rare and cryptic mammals. They showed that mammal mitochondrial DNA, amplified by the polymerase chain reaction, can be identified from a leech's blood meal for at least four months after feeding. They detected Annamite striped rabbit, small-toothed ferret-badger, Truong Son muntjac, and serow in this way.
 Exposure to synthetic estrogen as used in contraceptive medicines, which may enter freshwater ecosystems from municipal wastewater, can affect leeches' reproductive systems. Although not as sensitive to these compounds as fish, leeches showed physiological changes after exposure, including longer sperm sacs and vaginal bulbs, and decreased epididymis weight.