If dreams were movies, they wouldn’t make a dime. They’re often banal, frequently fleeting and they’re screened for an audience of just one. As for the storyline? You’re in a supermarket, only it’s also Yankee Stadium, shopping with your second-grade teacher until she turns into Ruth Bader Ginsburg. Then you both shoot a bear in the cereal aisle. Somebody call rewrite.

But dreams are vastly more complex than that, and if you’ve got a theory that explains them, have at it. The ancient Egyptians thought of dreams as simply a different form of seeing, with trained dreamers serving as seers to help plan battles and make state decisions. The ancient Greeks and Romans believed that dreams were equal parts predictions of future events and visitations by the dead.

Sigmund Freud considered dreaming an expression of repressed conflicts or desires, which were — no surprise, this being Freud — often sexual in nature. Carl Jung took a more rigorous approach, explaining dreams as a sort of “shaped energy,” inchoate emotions or thoughts released by the deep subconscious and entrained into narratives by higher regions of the brain. Modern psychologists and neurologists, armed with imaging equipment including PET scans and MRIs, have taken things to a deeper and more technical level, speculating that dreaming is the brain’s way of dumping excess data, consolidating important information, keeping us alert to danger and more.

Get our Health Newsletter. Sign up to receive the latest health and science news, plus answers to wellness questions and expert tips. Please enter a valid email address. Sign Up Now Check the box if you do not wish to receive promotional offers via email from TIME. You can unsubscribe at any time. By signing up you are agreeing to our Terms of Use and Privacy Policy . This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply. Thank you! For your security, we've sent a confirmation email to the address you entered. Click the link to confirm your subscription and begin receiving our newsletters. If you don't get the confirmation within 10 minutes, please check your spam folder.

But why do dreams take the particular shape they do? Why do you keep dreaming about having to cram for finals years after you graduated from college? Why do you dream about flying, or being chased by a wild animal, or showing up at that always-embarrassing party with your always-absent pants? And why are there dreams so stark or bizarre or seemingly perverse that you will carry them to your grave rather than revealing so much as a single detail about them to anyone in the world?

The least glamorous explanation for any dream is that it serves as a sort of data dump — a clearing of the day’s useless memories and a caching of the valuable ones. Researchers had long suspected that that process, if it exists, plays out between the hippocampus — which controls memory — and the neocortex, which governs higher order thought.

A 2007 study at the Max Planck Medical Institute in Heidelberg, Germany helped confirm that theory: working with anesthetized mice, the researchers found that as the neocortex fires during sleep, it signals various regions in the hippocampus to upload whatever information they’ve been holding in short-term storage. The hippocampus is then cleared to gather more the next day, while the neocortex decides what to transfer to long-term memory and what to discard. As that data streams by on the computer screen of the sleeping mind, some of it gets snatched up and randomly stitched into the crazy quilt of dreams, which often only vaguely resemble the literal content of the information.

MORE: How Dream Therapy Can Change Your Life

Justice Ginsburg and the bear, say, may come to mind as your brain examines and discards a scrap of news it picked up about the Supreme Court and the Department of the Interior. Most of this evanescent imagery — an estimated 90% — we don’t recall, which is consistent with the idea of dreaming as purging. “We dream to forget,” wrote Nobel laureate Francis Crick in 1984.

Crick, who is best known and most celebrated as the co-discoverer of DNA, improbably became something of a leading thinker — or at least leading provocateur — in dream theory, and what was colloquially known as his “garbage disposal theory” of dreaming attracted a lot of believers into the 1990s. But most contemporary dream theorists believe things are not quite so simple. For starters, a century of experience with talk therapy has shown that far from benefitting from forgetting all of our dreams, we often get a great deal out of reflecting on and analyzing them.

“It’s not a huge, dramatic effect but it certainly seems like paying attention to your dreams can have positive effects,” says Harvard University psychologist Deirdre Barrett, author of The Committee of Sleep. That’s not to say that dreams don’t involve a certain amount of data sorting and clearing. “This idea that information is being processed, I think does have validity. We’re sorting things into categories, comparing them to other events, considering information that we would suppress during the day.”

Another view of dreaming comes from cognitive neuroscientist Antti Revonsuo of Sweden’s University of Skövde, who has proposed what he calls the Threat Simulation Theory, arguing that the brain responds to potential future danger by running what amount to fire drills while we sleep just to keep us sharp. That may be the source of the persistent dream about failing to study for finals — with finals as a stand-in for a presentation you have to write for work in your adult life. Dreaming about losing some or all of your teeth — reported by a surprising number of respondents in studies — appears to be about anxiety over saying the wrong thing at the wrong moment. It may also be about bodily deterioration — something we all fear even in childhood.

The fact that the same dream themes occur across different populations and radically different cultures is not all that unexpected, since what human beings have in common is often far deeper and more primal than what we don’t. “We share a lot of genetic programming, so even modern humans continue to be concerned about large animals with big teeth,” says Barrett. “The idea of nudity as social exposure seems universal too, even in tribes that wear very little. In most cultures inappropriate clothing means shame.”

A far more productive function of dreaming is problem-solving, as the sleeping brain continues to work on jobs the waking mind handled during the day. In one 2010 study at Beth Israel Deaconess Medical Center in Boston, 99 people were administered a task that required them to navigate through a three-dimensional maze. During the course of their practice sessions, they were given a 90-minute break. Some were asked to engage in quiet activities like reading; others were were instructed to try to take a nap. Those who did nap and who happened to dream about the maze showed a ten-fold improvement on the task in the next session compared to the other subjects. Something similar happens when students are studying for a test and find they have a better mastery over the material after a night’s sleep, especially if they dreamed even indirectly about what they’d been learning.

“I often think of dreaming as simply thinking in a different biochemical state,” Barrett says.

Finally — give Freud his due — there are dreams that appear to be strictly wish-fulfillment. Dreams about flying may represent a desire for freedom. Dreams about finding new rooms in your home may express a desire for opportunity or novelty. And as for sex dreams? Often as not they’re about, um, sex. (The brain doesn’t always make things difficult.)

Our nights would likely be quieter and our sleep more serene if we didn’t dream at all, or at least didn’t dream so much. But our minds would not be as rich nor our brains as nimble nor our wishes so often fulfilled — if only in vivid fantasy. The screening room of the sleeping brain may sometimes wear you out, but like all good theaters, it will rarely leave you bored.

Write to Jeffrey Kluger at jeffrey.kluger@time.com.