Staying awake and alert or sleeping restfully when we choose to depends largely on the function of a few small areas of the brain.
When the alerting areas of the brain are most active, they inhibit activity in other areas of the brain responsible for promoting sleep. This inhibition of sleep results in stable wakefulness.
Similarly, when the sleep-promoting areas of the brain are most active, they inhibit activity in areas of the brain responsible for promoting wakefulness. This inhibition of wakefulness results in stable sleep.
We normally change from one stable state to the other due to internal factors, such as an increased drive to sleep that builds up during wakefulness and changing influences from our internal biological clock.
A number of other factors can influence the stability of this system and may cause us to fall asleep or wake up at inopportune times…