In 1920, the night before Easter Sunday, Otto Loewi woke up, seemingly possessed of an important idea. He wrote it down on a piece of paper and promptly returned to sleep. When he reawakened, he found that his scribbles were illegible. But fortunately, the next night, the idea returned. It was the design of a simple experiment that eventually proved something Loewi had long hypothesized: Nerve cells communicate by exchanging chemicals, or neurotransmitters. The confirmation of that idea earned him a Nobel Prize in medicine in 1936.

Almost a century later after Loewi’s fateful snoozes, many experiments have shown that sleep promotes creative problem-solving. Now, Penny Lewis from Cardiff University and two of her colleagues have collated and combined those discoveries into a new theory that explains why sleep and creativity are linked. Specifically, their idea explains how the two main phases of sleep—REM and non-REM—work together to help us find unrecognized links between what we already know, and discover out-of-the-box solutions to vexing problems.

As you start to fall asleep, you enter non-REM sleep. That includes a light phase that takes up most of the night, and a period of much heavier slumber called slow-wave sleep, or SWS, when millions of neurons fire simultaneously and strongly, like a cellular Greek chorus. “It’s something you don’t see in a wakeful state at all,” says Lewis. “You’re in a deep physiological state of sleep and you’d be unhappy if you were woken up.”

During that state, the brain replays memories. For example, the same neurons that fired when a rat ran through a maze during the day will spontaneously fire while it sleeps at night, in roughly the same order. These reruns help to consolidate and strengthen newly formed memories, integrating them into existing knowledge. But Lewis explains that they also help the brain extract generalities from specifics—an idea that others have also supported.

“Let’s say you replay memories of birthday parties,” she says. “They all involve presents, cake, and maybe balloons. The areas of the brain that represent those things will be more strongly activated than areas that represent who was at each party, or other idiosyncrasies.” Over time, the details may fade from memory, while the gist remains. “That’s how you might form your representation of what a birthday party is.” (Some scientists have argued that dreaming is the conscious manifestation of this process; it’s effectively your brain watching itself replaying and transforming its own memories.)

This process happens all the time, but Lewis argues that it’s especially strong during SWS because of a tight connection between two parts of the brain. The first—the hippocampus—is a seahorse-shaped region in the middle of the brain that captures memories of events and places. The second—the neocortex—is the outer layer of the brain and, among other things, it’s where memories of facts, ideas, and concepts are stored. Lewis’s idea is that the hippocampus nudges the neocortex into replaying memories that are thematically related—that occur in the same place, or share some other detail. That makes it much easier for the neocortex to pull out common themes.

The other phase of sleep—REM, which stands for rapid eye movement—is very different. That Greek chorus of neurons that sang so synchronously during non-REM sleep descends into a cacophonous din, as various parts of the neocortex become activated, seemingly at random. Meanwhile, a chemical called acetylcholine—the same one that Loewi identified in his sleep-inspired work—floods the brain, disrupting the connection between the hippocampus and the neocortex, and placing both in an especially flexible state, where connections between neurons can be more easily formed, strengthened, or weakened.

These traits, Lewis suggests, allow the neocortex to unconsciously search for similarities between seemingly unrelated concepts like, say, the way the planets revolve around the sun and the way electrons orbit the nucleus of an atom. “Suppose you’re working on a problem and you’re stuck,” she says. In REM sleep, “the neocortex will replay abstracted, simplified elements [of that problem], but also other things that are randomly activated. It’ll then strengthen the commonalities between those things. When you wake up the next day, that slight strengthening might allow you to see what you were working on in a slightly different way. That might just allow you to crack the problem.”

“Many of these ideas have been out there,” says Lewis. “Some people argued that slow wave sleep is important for creativity and others argued that it’s REM. We’re saying it’s both.” Essentially, non-REM sleep extracts concepts, and REM sleep connects them.

Crucially, they build on one another. The sleeping brain goes through one cycle of non-REM and REM sleep every 90 minutes or so. Over the course of a night—or several nights—the hippocampus and neocortex repeatedly sync up and decouple, and the sequence of abstraction and connection repeats itself. “An analogy would be two researchers who initially work on the same problem together, then go away and each think about it separately, then come back together to work on it further,” Lewis writes.

“The obvious implication is that if you’re working on a difficult problem, allow yourself enough nights of sleep,” she adds. “Particularly if you’re trying to work on something that requires thinking outside the box, maybe don’t do it in too much of a rush.”

Parts of this framework are based on strong data, but others are still conjectures that need to be tested. For example, there isn’t much evidence to support Lewis’s hunch that the hippocampus prods the neocortex into replaying related memories during non-REM sleep. “I realize it’s a little bit of a stretch,” she admits, but she notes that in several studies, slow-wave improves the ability to identify common concepts. In one widely used task, people have to learn a word list—night, dark, coal—that revolves around an unseen theme. If they sleep afterwards, they’re more likely to (falsely) remember that they also learned the theme word—in this case, “black.” However, Jessica Payne from the University of Notre Dame notes that in one of her experiments, SWS had the opposite effect.

Still, that “small disagreement” aside, Payne feels that Lewis is mostly on the right track, especially when it comes to the role of REM sleep in combining conceptual knowledge “in ways that can be preposterous and creative,” she says. “I think the general idea is going to be right.”

There’s another weakness to Lewis’s framework that she finds more troubling: People can be deprived of REM sleep without suffering from any obvious mental problems. One Israeli man, for example, lost most REM sleep after a brain injury; “he’s a high-functioning lawyer and he writes puzzles for his local newspaper,” Lewis says. “That is definitely a problem for us.”

“I’m sure [the theory] isn’t 100 percent right,” she adds, laughing, “but we just got back a set of results that really strongly support it.” Her team tried to get sleeping volunteers to replay memories during slow wave sleep and REM sleep, and found different effects in each. Those results should be published in the near-future. In the meantime, the team is also developing ways of boosting or suppressing the two sleep stages to see how that affects people’s problem-solving skills. This is all part of a five-year project, and they’re just in their first year.

Lewis is also working with Mark van Rossum from the University of Nottingham to create an artificial intelligence that learns in the way she thinks the sleeping brain does, with “a stage for abstraction and a stage for linking things together,” she says.

“So you’re building an AI that sleeps?” I ask her.

“Yes,” she says.

I wonder if it will dream of electric sheep.