|Brain met (Photo credit: Wikipedia)|
The brain is a ton of little circuits each performing some task. All those circuits need power to function. Neural impulses are, after all, electrical signals. That electricity has to come from somewhere.
Science has found that some parts of the brain can fall asleep while others remain awake. This suggests that different parts have their own individual "batteries", rather than all being wired to a single central power source. (This is likely to ensure that power for critical systems isn't drained by non-critical ones.)
When we sleep, we "shut off" most of the brain's circuits and let them recharge. But that power has to get to them somehow. Well, rather than waste valuable space and brain matter on dedicated "wiring" just for this purpose, why not re-use the signal "wires" that aren't doing anything while those circuits aren't being used?
|English: My Brain's Tomo (Photo credit: Wikipedia)|
The parts that handle sensory input see all these impulses and interpret them as vision and sound and feelings. The memory systems respond to them by looking up or storing information in memory. But they're all basically just trying to make sense of random noise.
The result is that you get a lot of random nonsense flowing through your mind, from all these circuits triggering at random and acting on nonsensical input. You experience things that aren't real. You see someone and "know" them, because the noise flowing through the circuit responsible for recognizing people happens to look like the signal it generates when it successfully recognizes someone. You get dreams based on things you experienced that day, and you remember some of the dreams, because your short-term memory gets a lot of random "signals" that it sees as requests for various memories. You see something completely bizarre and don't find anything wrong with it because the part that decides whether something makes any damn sense isn't actually functioning but is passing along noise that happens to look like signals meaning "seems legit" or "WTF?".
All the while, your eyes, ears, nose etc are still functioning too, because you might still sense something urgent, that you need to wake up and deal with, such as a predator or a fire. This means your brain can't just decide to ignore all that nonsensical sensory input, because some of it is real, and might still be important.
That does mean a dream might wake you up sometimes too, if you happen to dream about a predator, but this didn't happen frequently enough for evolution to do anything about it.