Perhaps the best answer is that dreams help us to regulate, analyze, explain and remember recent events in our lives, in a kind of "mental housekeeping" process. Most dreams are based in large part on everyday experiences from recent days, suggesting that at least part of their function is to help the brain sort through and make sense of recent real-life experiences. Reliving experiences internally through dreams helps to facilitate learning and to reconsolidate long-term memories (both the procedural memories of how to do things and the declarative memories of facts and events), and also provide an opportunity to delete unwanted or junk data from memory.
Rather than just processing memories in a mechanical way, though, dreams actually appear to refine and improve memories, making them more useful for the future, so that the subsequent performance of learned tasks is improved. This has been conclusively demonstrated experimentally, for example in in tests in which rats are set to learn tasks like navigating mazes.
The brain is particularly active during dream-heavy REM sleep, so it seems logical that REM dreams play an active role in keeping the brain and nervous system in good working order in some way. However, it is becoming increasingly apparent that non-REM dreams may be just as important in facilitating learning as REM dreams. Experiments on rats indicate that, during non-REM sleep, neuronal activity largely mirrors the neuronal activity of tasks performed during the previous day, although abbreviated, compressed or speeded up. On the other hand, in the much more detailed dreams of REM sleep (typically five times longer than non-REM dreams), brain wave activity appears almost identical to that during the original physical experiences, as though the tasks are being played out in full, but internally.
Because babies and young children spend so much time in REM sleep, it has been proposed that dreams are an essential element in the brain development of young children, a way of exercising and stimulating the young mind. REM sleep in the unborn fetus may represent as much as 80% of total sleep time, and a newborn baby spends at least 50% of their sleep time in REM sleep. This percentage continues to fall as the child ages, to around 35% for a one year old, before stabilizing at around 20-25% in older children and adults. However, although the high proportion of REM sleep in young children is well-documented, it is less easy to be sure that this REM sleep is actually accompanied by dreams in the very young. Also, this particular theory has little to say about the function of dreams in adults.
As well as their role in memory and learning, dreams also help us to resolve any emotional problems and inconsistencies arising from our daily activities, as well as aiding in mood regulation. Interestingly, some recent research has found that sleepers tend to report more negative emotions when woken during REM sleep than during non-REM sleep, suggesting that REM dreams and non-REM dreams may serve different (although complementary) functions in this regard. In particular, the amygdala, which specializes in dealing with unpleasant emotions (e.g. anger, aggression, fear, etc), is very active during REM sleep, and may be involved in the process of resolving emotional issues. This may be supported by the example of clinical depression: one symptom of depression is that sufferers tend to spend a disproportionately large amount of time in REM sleep, in which case these negative emotions may be over-represented, thus perpetuating the depression (deliberate deprivation of REM sleep is often helpful in alleviating depression symptoms).
It has also been suggested that the way the brain suppresses the rational, controlled activity of the prefontal cortex while allowing the more primitive, emotional side (associated with the amygdala, or emotion centre, of the brain) to run riot may be a way of keeping us safely sane by allowing us to “go crazy” in our nightly dreams, while simultaneously working out our emotional problems. Dreams may therefore function to contain and absorb negative emotional surges, allowing the dreamer to remain soundly asleep despite the inner turmoil, and to expunge these negative emotions from waking memory. According to this theory, sometimes referred to as the selective mood regulatory theory of dreaming, the first main dream of the night is therefore likely to be the most disturbing, with subsequent dreams becoming increasingly better-adjusted, in an ongoing, and largely automatic, process of emotional resolution. Recurring dreams occur where this process becomes stuck at an early stage, and the emotional issues remain unresolved.
A more evolutionary explanation that has been proposed by some people is that dreams may be a kind of mental simulation of potential real-life threatening events, allowing for a kind of safe “dry run”, and the testing and analysis of possible responses and mental schemas. It is also proposed by some that these schemas may also be passed on in the form of so-called “genetic memories”. Interestingly, children tend to have many "primal" dreams and nightmares, similar to the kinds of dreams mankind may have experienced millennia ago; as we age, these atavistic dreams tend to fade and our dreams tend to become more attuned to the subject matter of modern adult life. So, the theory holds that our dreams, and the long, detailed REM dreams in particular, may use our past experiences to anticipate possible future experiences, and allow us to test out possibilities and scenarios which might help us to deal with those experiences if they ever occur. Some of the scenarios constructed may be completely nonsensical, as indeed many dreams are, but some may prove genuinely useful in providing insights, so this may be at least a partial function of at least some dreams.
There is, though, a significant school of thought (stemming from the activation-synthesis model of dreaming first proposed back in the 1970s) that believes that dreams do not actually serve any natural purpose and have no significant influence on our waking actions at all, but are just a random by-product of REM sleep. The peculiar nature of dreams is therefore attributable to certain parts of the brain trying to piece together a story out of what is essentially random information presented to it by the release of acetylcholine from the brainstem during REM sleep. This theory might also go some way to explaining why dreams are usually so difficult to remember, especially if the brain were to consider them non-meaningful information or “noise” that we should just forget. This idea, that dreams may be instrumental in eliminating unwanted or unnecessary information and synaptic connections, is sometimes referred to as “active unlearning”. Of course, it can also be counter-argued that the way the forebrain chooses to interpret these random signals into a scenario or a story is in itself significant, and can tell us something about ourselves, in much the same way as our interpretation of a Rorschach ink-blot can.
The active unlearning idea was taken a step further in 1982 by Francis Crick and Graeme Mitchison. They hypothesized that synapses activated during dreams actually become weakened rather than strengthened, in a kind of negative mirror image of waking activity, and that the function of dreams was in fact a process of forgetting or “reverse learning”, a pruning down of unnecessary synapses in the neural networks of the brain. According to this theory, the content of our dreams has little or no significance; indeed, to the contrary, what we dream about is the waste products of our experiences, earmarked by the brain for disposal.
Another interesting idea is that of “oneiric Darwinism”, which proposes that new ideas may be created through the generation of random thought mutations during dreaming, most of which will likely be discarded as useless, but some of which may be retained as potentially valuable. Some scientists have argued that the brain is fundamentally creative, and that dreams allow this spontaneous creativity to be expressed in the absence of the many physical, moral and other constraints that we are normally subject to.
However, many of the claims of purportedly dream-driven discoveries and insights - commonly-quoted examples include Dmitri Mendeleev’s formatting of the periodic table, Mary Shelley’s invention of the Frankenstein story, Elias Howe’s sewing machine needle, etc - are of dubious authenticity, and it has been argued that these discoveries were really the product of active waking consciousness reflected in the content of dreams, following weeks of research, thought and consideration of the issues. If anything, it can be argued that these few isolated examples of dream creativity bring into sharp relief the fact that the vast majority of discoveries and insights are NOT dream-related.
Many people still believe, like many of the ancients did, that dreams have some prophetic element. However, most purported successes in predicting the future can be mainly explained in terms of various memory biases: the multi-faceted nature of dreams makes it relatively easy to find retrospective connections between dream content and subsequent real events. Having said that, it is still possible that, during REM sleep, the highly active brain may catch glimpses of physiological changes occurring within the body that the busy waking brain may be unaware of, or does not seriously consider, so that dreams may appear to predict diseases or internal events in an apparently prescient way.
A more radical idea that has been put forward recently suggests that dreams are an attempt to keep our hyperactive brains occupied, so that our bodies and other parts of our brains can restore and repair themselves. In this scenario, dreams are not merely a by-product of sleep, as has long been supposed, but rather what allows us to enjoy the essential healing process of sleep in the first place.