Sleep is essential to cognitive function and health in humans, yet the ultimate reasons for sleep-i.e. 'why' sleep evolved-remain mysterious. We integrate findings from human sleep studies, the ethnographic record, and the ecology and evolution of mammalian sleep to better understand sleep along the human lineage and in the modern world. Compared to other primates, sleep in great apes has undergone substantial evolutionary change, with all great apes building a sleeping platform or 'nest'. Further evolutionary change characterizes human sleep, with humans having the shortest sleep duration, yet the highest proportion of rapid eye movement sleep among primates. These changes likely reflect that our ancestors experienced fitness benefits from being active for a greater portion of the 24-h cycle than other primates, potentially related to advantages arising from learning, socializing and defending against predators and hostile conspecifics. Perspectives from evolutionary medicine have implications for understanding sleep disorders; we consider these perspectives in the context of insomnia, narcolepsy, seasonal affective disorder, circadian rhythm disorders and sleep apnea. We also identify how human sleep today differs from sleep through most of human evolution, and the implications of these changes for global health and health disparities. More generally, our review highlights the importance of phylogenetic comparisons in understanding human health, including well-known links between sleep, cognitive performance and health in humans.