The anus is an opening at the opposite end of an animal's digestive tract from the mouth. It is used for expelling unwanted solid matter produced during digestion, which, depending on the type of animal, may be one or more of: matter which the animal cannot digest, such as bones; food material after all the nutrients have been extracted, for example cellulose or lignin; ingested matter which would be toxic if it remained in the digestive tract; and dead or excess gut bacteria and other endosymbionts.
Amphibians, "reptiles" and birds use the same orifice for excreting liquid and solid wastes, and for copulation and egg-laying; this orifice is known as the cloaca. Monotreme mammals also have a cloaca, which is thought to be a feature inherited from the earliest amniotes via the therapsids. Marsupials have two nether orifices: one for excreting both solids and liquids; the other for reproduction, which appears as a vagina in females and a penis in males. Female placental mammals have completely separate orifices for defecation, urination and reproduction; males have one opening for defecation and another for both urination and reproduction, although the channels flowing to that orifice are almost completely separate.
The development of the anus was an important stage in the evolution of multicellular animals. In fact it appears to have happened at least twice, following different paths in protostomes and deuterostomes. This accompanied or facilitated other important evolutionary developments: the bilaterian body plan; the coelom, an internal cavity that provided space for a circulatory system and, in some animals, formed a hydrostatic skeleton which enables worm-like animals to burrow; metamerism, in which the body was built of repeated "modules" which could later specialize, for example the heads of most arthropods are composed of fused, specialized segments.
In animals at least as complex as an earthworm, the embryo forms a dent on one side, the blastopore, which deepens to become the archenteron, the first phase in the growth of the gut. In deuterostomes, the original dent becomes the anus while the gut eventually tunnels through to make another opening, which forms the mouth. The protostomes were so named because it used to be thought that in their embryos the dent formed the mouth while the anus was formed later, at the opening made by the other end of the gut. More recent research, however, shows that in protostomes the edges of the dent close up in the middle, leaving openings at the ends which become the mouth and anus.