For a long time, researchers weren’t quite sure why we — or any animal, for that matter — sleep. One theory was that sleeping at night kept us out of trouble — you’re less likely to stumble into a predator if you’re asleep, after all. But now researchers know that sleep has a number of critical functions, mostly for the brain.

And a new study shows that when it comes to memory formation, sleep definitely does a brain good. In fact, sleep may be one of your best safeguards against Alzheimer's Disease.

You might feel like you’re wasting time by sleeping, but that couldn’t be further from the truth.

The other theory suggested that sleep weakens some connections, but strengthens others, leading to a kind of reorganization of memory.

There have been two competing theories over the years about how sleep helps the brain, and the new study gives more support for both theories in tandem. One view suggested that sleep weakens synapses (the areas where brain cells come close to and communicate with each other), so weak memories are pruned away and forgotten, and only the “fittest” survive.

The new study looks at a process called long-term potentiation (LTP), which is thought to solidify memories as new neural connections become strengthened. The researchers exposed a group of rats to a new activity, and then let them sleep, watching the firing patterns in their brains for LTP.

What they found was interesting: Only those rats that had had the new experiences showed signs of LTP when they went into REM sleep. Rats who were not exposed to the new activities did not have LTP.

Researchers plugged the firing patterns of the neurons in the hippocampus (the area of the brain that controls long-term memory) into a computer model, and discovered more about what the brain is doing while sleeping. Not only were certain connections strengthened, but others were reorganized, and “ranked,” leading to big changes in the overall pattern of connectivity. In other words, the brain restructured its connections during sleep.

The brain is certainly doing some heavy lifting while we sleep — the results indicate that there may both be some pruning, or forgetting, of non-critical memories happening during sleep, and strengthening of others. Though the results technically apply only to rats, they are likely to apply to humans, too, since rats and humans share many similarities when it comes to memory formation.

Not only were certain connections strengthened, but others were reorganized, and “ranked,” leading to big changes in the overall pattern of connectivity.

Here is one more piece of evidence for the idea that sleep is good. And not only good, but important and even critical for brain function. You might feel like you’re wasting time by sleeping, but that couldn’t be further from the truth. So make sure to get a full night’s sleep.

If you’re tired during the day, that might be your brain telling you to grab a nap, if you can. The National Sleep Foundation recommends short naps for a quick cognitive boost (longer naps may actually be more draining). And be sure to let your kids benefit from the power of a nap whenever they can.

The study was carried out by researchers at the Brain Institute at the Federal University of Rio Grande do Norte and published in PLoS Computation Biology.