There are a few things we literally cannot live without. Oxygen is one. Another is food and water. And then there is sleep: forcibly keep an animal awake for long enough and you will kill it. The same almost certainly applies to humans.

This fact alone tells us that sleep must be doing something pretty important. But despite decades of intense scientific study there still is no consensus on exactly what that something is.

Researchers have found that sleep is beneficial to humans in many ways: it helps us process memories, and keeps our social and emotional lives on track. Yet we still do not really know how, why or even exactly when sleep evolved.

At first glance, sleep really should not exist. It makes very little sense for animals to deliberately lose consciousness, sometimes for hours on end every single day.

A sleeping animal is significantly more likely to be caught and eaten than a waking animal

“The cost of losing consciousness to survival is astronomical,” says Matthew Walker at the University of California in Berkeley. Whatever functions sleep performs, they must be so fundamentally important that they far outweigh the obvious vulnerability associated with being asleep.

This means we can confidently reject one of the simplest theories of sleep: that we drift off simply because we have nothing better to do.

This could be described as the indolence theory of sleep. Once an animal has eaten, seen off any rivals and exhausted any potential mating opportunities, it effectively has an empty schedule. With no urgent business to attend to, losing consciousness kills time for a few hours.

It is a fun idea, but considering that a sleeping animal is significantly more likely to be caught and eaten than a waking animal, this hypothesis makes “zero sense”, says Walker.

We might as well cross another theory of sleep off the list, too.

Some researchers have suggested that sleep is a good way to save valuable energy, given that mammalian core body temperatures often drop during some stages of sleep.

Does a housefly sleep? How about an earthworm?

However, Walker and many other sleep researchers are not convinced. Crunching the numbers makes it clear that sleep does not serve this purpose.

“The amount of energy humans save by falling asleep, versus simply lying on the couch, is about what you find in a slice of brown bread,” he says. “Losing consciousness just isn’t worth saving 120 calories.”

But what is sleep for, if these ideas are out? Before we can really think about answering that question, it would be helpful to address something more fundamental: who sleeps?

We have no problem recognising that humans sleep. Most people can tell that pet cats and dogs sleep too.

But we might feel less confident about identifying when, or even if, a pet goldfish sleeps. And when it comes to smaller or more distantly related animals we would be even less sure. Does a housefly sleep? How about an earthworm?

Sleep now appears to be an almost universal feature of animal life

There is now an emerging consensus on the behavioural features that define sleep, and these features can be used to look for sleep in simple animals, says Ravi Allada at Northwestern University in Evanston, Illinois.

There are three main elements. First and foremost, sleep renders an animal quiet and still: muscles are not very active during sleep.

Second, sleep makes animals slower to respond. For instance, if you make a loud noise near a sleeping animal, it will react more slowly than an awake animal.

And finally, we can recognise sleep because it keeps animals from getting tired. If you keep an animal up all night, it will compensate the next day by sleeping for longer than it normally would. This is sometimes called “sleep rebound”.

Using these criteria, there is growing confidence that even relatively simple animals like fruit flies and microscopic nematode worms do in fact sleep. “There are now lots of publications on these model systems,” says Allada.

“I believe that the behavioural features used to characterise sleep are quite reliable for identifying this behaviour in animals… and to differentiate sleep from a simple rest,” says Paul-Antoine Libourel at the Lyon Neuroscience Research Center in France.

Birds, like mammals, have REM sleep

According to Libourel, sleep now appears to be an almost universal feature of animal life. “This suggests that sleep is fundamental for the survival of species. Natural selection did not suppress it.”

In fact, natural selection did the exact opposite: it built on the concept of sleep, adding in new stages and new functions. At some point in prehistory, the most famous of all stages of sleep appeared: rapid eye movement (REM) sleep.

“If there’s a new kid on the block it’s REM sleep,” says Walker. “Non-REM sleep was the original form.”

The origins of REM sleep particularly bother researchers like Libourel.

We know that humans possess REM sleep. It seems pretty clear that almost all other mammals do so too, even very “primitive” egg-laying mammals like the duck-billed platypus. This means we can be reasonably confident that it was present in some of the first mammals that walked the Earth, about 220 million years ago.

The proto-mammals began spending the hours of daylight asleep below ground in dark burrows

As it happens, dinosaurs first appeared on Earth around this time too. Many of them disappeared about 65 million years ago, but one group of dinosaurs lives on: we call them birds. And birds, like mammals, have REM sleep.

Perhaps REM sleep emerged in some distant common ancestor of mammals and the bird-dinosaurs, says Libourel, or perhaps it originated independently in the two groups. But either way, why did REM sleep appear?

Some researchers think there is no functional explanation, and that REM sleep is just a byproduct of other evolutionary changes. For instance, according to Ruben Rial at the University of the Balearic Islands in Majorca, Spain, it is probably significant that both mammals and birds are warm-blooded.

Rial and his colleagues suggest that the appearance of warm-blooded animals triggered a complicated chain of causes and consequences, which ultimately saw proto-mammals adopt a nocturnal existence – quite unlike their daytime-active reptilian ancestors.

The proto-mammals began spending the hours of daylight asleep below ground in dark burrows, which offered protection both from predators and from intense sunlight that would damage their sensitive night-adapted vision.

Our brains are remarkably active during REM sleep

“However, they conserved most of the neural mechanisms that controlled their ancient behavioural output,” says Rial.

Reptiles go through two main behavioural phases each day: a passive phase in which they lie still and bask to warm up their bodies, and an active phase in which they forage, protect themselves from predators, socialise or breed.

Rial says that some of the more “primitive” regions of the proto-mammals’ brains continued to follow these ancient patterns of activity, even as more “advanced” brain regions made sure that any reptilian-like mental activity was not converted into actual behaviours.

This means we can see non-REM sleep as a direct descendant of reptilian basking, and REM sleep as an inherited form of reptilian daytime activity. “However, this activity was enclosed within a paralysed body,” he says. “This was the origin of REM and dreams.”

This might sound more like a story than a provable hypothesis, but some established facts do support the idea.

For instance, there is good evidence that the earliest mammals were nocturnal – and this nocturnal bottleneck did influence behaviour.

Sleep – and in particular REM sleep – helps recalibrate emotional functions in the brain

We also know that our brains are remarkably active during REM sleep: so active, in fact, that an REM brain looks like the brain of an animal, like a reptile, that is fully awake. For this reason, REM sleep is sometimes called “active sleep” or even “paradoxical sleep”.

Even so, other researchers do not share the view that REM sleep is a mere side-effect of broader evolutionary change.

Walker, for one, is convinced that REM sleep has a real and important function. “We’ve done a lot of work that suggests sleep – and in particular REM sleep – helps recalibrate emotional functions in the brain,” he says.

Think back to your childhood, says Walker. If you try to recall the strongest earliest memories you have, almost all of them will be memories of an emotional event: perhaps a particularly exciting birthday, or the frightening experience of being separated from your parents on your first day at school.

People with PTSD often experience emotionally overwhelming flashbacks

“What’s striking now, though, is that you can recall these are memories of an emotional event but they are no longer themselves emotional. They do not elicit the same visceral reaction,” he says.

We have REM sleep to thank for the change, says Walker. It carries out a very important function: allowing us to remember and learn from important experiences, without being crippled by the emotional baggage that they originally carried.

“REM sleep provides overnight therapy,” says Walker. “[It helps] the brain perform an elegant trick of divorcing the emotional bitter rind from the information-rich orange.”

This hypothesis even offers an explanation for distressing conditions like post-traumatic stress disorder (PTSD).

People with PTSD often experience emotionally overwhelming flashbacks.

“A soldier with PTSD walks into a carpark and hears a car backfire. Not only do they have a flashback to a combat situation, but they have an emotional reaction: their heart races, their palms sweat,” says Walker. “It tells us that the brain has not separated the emotion from the memory.”

It was the people who had experienced the longest, most miserable dreams that gained clinical resolution from their depression

Walker points out that repetitive nightmares are a hallmark of PTSD. He says we can interpret this as the brain offering up a highly emotional memory so that REM sleep can peel away the emotion.

But, for some reason, REM fails to do so. The memory remains emotional. So the next night the brain tries again, with the same result, and so on.

Even the vivid dreams we experience during REM sleep appear to be adaptive, and part of this process. We know as much from the seminal work of Chicago-based sleep researcher Rosalind Cartwright in the 1980s and 1990s.

Cartwright studied the dream habits of people who were showing signs of depression, as a consequence of bitter divorces.

After a year, it was the people who had experienced the longest, most miserable dreams that gained clinical resolution from their depression. Paradoxically, the test subjects whose dreams were more like those of people without depression remained depressed.

It was a staggering finding, says Walker.

We spend about 25% of our sleep in an REM state, whereas for most other primates the figure is just 5-10%

Previously it had seemed plausible that dreams were just a curious side-effect of sleep: rather like the way an incandescent lightbulb gives out heat as a consequence of its primary light-giving function. “But if that were really true, Rosalind Cartwright’s results would make no sense whatsoever,” says Walker.

Taken together, these findings suggest to Walker that REM sleep evolved in birds and mammals because both groups are cognitively and socially advanced. They use sleep, and dreams, to help make sense of their waking world. “I think the warm-blooded connection is a little bit of a red herring,” he says.

This could explain why human sleep is so unusual. A study published at the end of 2015 found that we spend about 25% of our sleep in an REM state, whereas for most other primates the figure is just 5-10%. This makes sense if you consider how much more complicated our social interactions are, says Walker.

We may be closing in on understanding why mammals and birds evolved REM sleep. But what about non-REM sleep, which evolved first and is seen in many more animals?

Sleep must have originated for a reason. Whatever that reason is, it must be related to some biological feature, or features, shared by all animals that sleep: not just mammals and birds.

Over time, a sea of neurotransmitter molecules can build up in the synapse

Robert Cantor at Dartmouth College in Hanover, New Hampshire thinks he has identified that common feature: a relatively complex brain and nervous system. Specifically, a complex brain through which signals are transmitted by molecules called neurotransmitters.

There are small junctions called synapses between nerve cells. When one cell has a message to pass to its neighbour, it often sends it in chemical form as a swarm of neurotransmitter molecules, which latch onto receptors on the receiving cell.

“This molecular process is common to all organisms that sleep,” says Cantor. “It exists in the vast majority of synapses in nervous systems, regardless of complexity.”

But, says Cantor, this process comes with a catch.

Over time, a sea of neurotransmitter molecules can build up in the synapse, interfering with its ability to function properly. What is needed is a process to flush away those molecules. That process happens most efficiently when we sleep, he says.

Cantor had been toying with this idea for some time when, in 2012, it received a significant boost. Neuroscientists discovered a previously unrecognised network of vessels in the brain that flush out the fluids between brain cells: the “glymphatic system”. A year later it emerged that the glymphatic system is most active during sleep.

Evolution has a tendency to repurpose things

“I’ve read quite a bit about the glymphatic system over the past few years,” says Cantor. “What has struck me as rather surprising is that, to my knowledge, nobody has systematically analysed exactly what solutes are present in the fluid that is washed out.”

He suspects that neurotransmitters are particularly abundant in the fluid. If that is true, it offers an explanation for the origin of sleep: flushing out neurotransmitters is so important to the nervous system that, in order to get it done, animals began to sleep – despite the disadvantages that come with losing consciousness.

Sleep almost certainly does play a part in this sort of brain-cleaning activity, says Walker. But we cannot be sure that this was the single factor that triggered the origin of sleep.

The trouble is that sleep might have evolved first, and then the brain and nervous system harnessed the opportunity it provides to flush out unwanted molecules from the brain.

Sleep impacts every major system in the body

This is a common problem that evolutionary biologists face when trying to work out why particular features first evolved: evolution has a tendency to repurpose things.

For instance, breathing is very important for bringing in oxygen and removing carbon dioxide, but it is also now crucial for human speech and singing. “Nobody would affirm that the [respiratory] system [originally] served to allow the production of words,” says Rial.

Pinpointing the driving factor, or factors, that led to the origination of sleep is going to be a challenge because sleep has so many beneficial effects.

Sleep impacts every major system in the body. Cut down on sleep and it is not just your brain that struggles: the reproductive, metabolic, cardiovascular, thermoregulatory and immune systems all suffer too, says Walker. In principle, the evolution of sleep could have been driven by the benefits it brings to any one of these systems.

Sleep is a state we enter to fix the systems that are put under stress when we are awake

“We used to ask the question; ‘Does sleep do any good, or serve any function?’” says Walker. “Now we’ve been forced to upend the question and ask if there is anything that isn’t improved by sleep, or impaired by sleep deprivation. And currently the answer is ‘no’.”

Fortunately, Earth is still home to living representatives of some of the earliest groups of animals: things like jellyfish, which may show a primitive form of sleep. It is probably by studying these more "primitive" animals that we will figure out what originally drove the appearance of sleep, says Allada.

Even single-celled organisms, at least those that live for longer than 24 hours, might hold clues. “They show stages of what we would call passive and active cellular activity,” says Walker. “That could be seen as a precursor of sleep.”

Walker offers one final thought. “This is an idea that has been put out there by some other researchers, but: we may be asking entirely the wrong question.”

What about this hypothesis: sleep was the first state of life and it was from sleep that wakefulness emerged

All the explanations for sleep we have looked at ultimately boil down to the same thing: sleep is a state we enter to fix the systems that are put under stress when we are awake. The debate has been over which system is the crucial one.

But you could turn this argument on its head, and say that sleep is so beneficial that the question is really why animals ever bother to wake up. Maybe it is actually the harmful state of wakefulness that is an evolutionary mystery, not sleep.

“What about this hypothesis: sleep was the first state of life and it was from sleep that wakefulness emerged,” says Walker. “I think it’s probably a ridiculous hypothesis – but it’s also not entirely unreasonable.”