The evolution of mammals has passed through many stages since the first appearance of their synapsid ancestors in the late Carboniferous period. The most ancestral forms in the class Mammalia are the egg-laying mammals in the subclass Prototheria. By the mid-Triassic, there were many synapsid species that looked like mammals. The lineage leading to today's mammals split up in the Jurassic; synapsids from this period include Dryolestes, more closely related to extant placentals and marsupials than to monotremes, as well as Ambondro, more closely related to monotremes. Later on, the eutherian and metatherian lineages separated; the metatherians are the animals more closely related to the marsupials, while the eutherians are those more closely related to the placentals. Since Juramaia, the earliest known eutherian, lived 160 million years ago in the Jurassic, this divergence must have occurred in the same period.
After the Cretaceous–Paleogene extinction event wiped out the non-avian dinosaurs (birds are generally regarded as the surviving dinosaurs) and several mammalian groups, placental and marsupial mammals diversified into many new forms and ecological niches throughout the Paleogene and Neogene, by the end of which all modern orders had appeared.
Mammals are the only living synapsids. The synapsid lineage became distinct from the sauropsid lineage in the late Carboniferous period, between 320 and 315 million years ago. The sauropsids are today's reptiles and birds along with all the extinct animals more closely related to them than to mammals. This does not include the mammal-like reptiles, a group more closely related to the mammals.