To promote wakefulness in our brains, several neurotransmitters are involved including adenosine, norepinephrine, histamine, dopamine, serotonin, and acetylcholine. Adenosine is a protein that accumulates during wakefulness. When it reaches a certain threshold, it causes sleepiness. Caffeine blocks adenosine, which is how it promotes wakefulness. Histamine, on the other hand, is one of the most important neurotransmitters promoting wakefulness. This is why antihistamine drugs like allergy drugs, cause drowsiness.
Dopamine and serotonin are also involved in sleep, but through different complex mechanisms I won't go into.
These neurotransmitters project from the brain stem and forebrain to different areas in the cortex. They fire at their highest rate in wakefulness and decrease during non-REM sleep, then cease altogether in REM sleep.
One area of the brain that promotes arousal and orchestrates all of these neurotransmitters, is the hypothalamus. More specifically the orexin or hypocretin neurons. These neurons directly stimulate the arousal centers as well as the cerebral cortex. There are also multiple areas responsible for sleep. The most important of which is in the hypthothalumus, called the ventrolateral preoptic nucleus, or VLPO. The VLPO inhibits activity in the arousal centers, thus promoting sleep.
The ability to stay in a stable state, either awake or asleep, is due to a process called mutual inhibition. It works kind of like a seesaw. The areas of the brain that are responsible for being awake inhibit the sleep centers and vice versa. In normal conditions you can have one or the other but not both.
And so the brain shifts from awake to non-REM sleep to REM sleep. Recall that REM is considered the paradoxical stage of sleep and brain activity is high. If you observed person sleeping in an MRI machine you would see that during REM sleep the anterior cingulate, the amygdala, hypothalamus and basal forebrain are activated. These are the structures involved in emotional regulation and processing, whereas the frontal cortex, which is involved in reasoning, has a reduced level of activity. That's why dreams are often bizarre and don't make sense.
When you shift into REM sleep, the balance in neurotransmitters shifts from predominantly serotonin and norepinephrine to mostly acetylcholine. During REM sleep acetylcholine levels are very high, and noreinephrine and serotonin levels are very low. That is why you are paralyzed during REM sleep. But how do we switch from sleep to the awake state? There are two powerful mechanisms that balance and interact with each other to cause this, the homeostatic sleep drive and the circadian rhythm.
As your day progresses, the homeostatic sleep drive is regulated by hormones in the body. Cortisol goes down and melatonin goes up to trigger sleepiness.
The circadian rhythm is driven by an internal body clock called the suprachiasmatic nucleus which controls the body's sleep patterns. Your eyes transfer information about light and darkness to the suprachiasmatic nucleus, which synchronizes your rhythms with your external environment. There are also local circadian clocks found in different brain regions and throughout the body. And these generate rhythms through your gene expression, metabolism, and other physiological activities.
So as the day wears on, the homeostatic sleep drive increases in activity while your circadian clock slackens off and allows for sleep to occur around bedtime. As you sleep, melatonin production continues, and the homeostatic sleep drive begins to wind down. Finally, just before you wake, melatonin production stops and kicks off your circadian arousal drive starting the process all over again.