How sleep works

Last update: 2019-01-03

What is sleep and how it works?

To hack our sleep, we have to understand how it works. The purpose of this article is to present some basic overview of main topics related to sleep (deep enough to understand what needs to be taken care of, but not deep enough to be a medical workbook). This is just a summary. I highly recommend reading books listed in the sleep biohacking section.

Sleep process

Our sleep timing is controlled by two processes, the sleep-wake homeostasis (Process S), and circadian clock (Process C).

  • Process S – Sleep-Wake Homeostasis

It causes pressure to fall asleep. It is the accumulation of a sleep-inducing substance, called adenosine, in the brain. It’s a biochemical timer, generating the need to sleep after a certain amount of time being awake (peaks usually 12-16h after waking up). The longer you’ve been awake, the stronger your desire for sleep becomes, as the adenosine purges only during sleep.

  • Process C – The Circadian Rhythm

It defines the daily rhythm of sleep. It is a signal from an internal ~24h clock located in your brain in the suprachiasmatic nucleus. Its location is not accidental. It’s just above optical nerves coming from eyeballs, allowing for sampling the light. It communicates a signal of night and day with melatonin, secreted by the pineal gland.

Both processes are independent of each other but usually aligned:


Image source: Krzysztof Załęski

Process-C cycles independently, that’s why we can have second alertness even if we are sleep deprived. But remember, if you miss one night you have a great chance of falling asleep subconsciously (car accidents!). You also need a few longer nights to build up a sleep debt. You can usually catch up only about 1h each consecutive night (same with jetlag).


Image source: Krzysztof Załęski

Circadian rhythm

Circadian rhythm governs how our body behaves during the whole cycle. It coordinates the light-dark cycle of day and night and regulates your body’s not only sleeping patterns, but also feeding patterns, core body temperature, brain wave activity, and hormone production.

Humans have an internal clock that lasts about 24 hours 15 minutes (famous experiment with a human in a cave), but the indoor lights, seasons, traveling, and shift work, influence it, so it’s continuously phase-shifted – the time we go to bed and wake up changes over a year, but we should try to normalize it and maintain a constant habit. Adults (18–64 years) should sleep 7 to 9 hours. Average 8 hours of actual sleep per day means 8.5–9 hours in bed. The best time to go to bed is 22:45 – 23:00 to catch the first wave. We are pre-programmed with specific rhythm every day (image below). The body cannot accomplish all tasks at once, so each function has a specific time during the cycle.

circadian clock

Image source: Wikipedia

Sleep phases

The whole sleep cycle is divided into several phases. One full phase lasts about 90 minutes. The first half of the night is dominated by the NREM, second by REM sleep (hypnogram below). Each phase offers different brain benefits at different times of the night.


Image source: Krzysztof Załęski

If you sleep less, the cycle does not shrink. If you stay awake longer, you cut your deep NREM. If you wake up early (sleeping less than 6h) you lose most of your REM sleep. To have good, restorative sleep, it is paramount to maximize the amount of deep sleep (N3) by going through at least three cycles. Most of recovery takes place only in the deepest stages during the first 4 hours. Sleeping more won’t increase our recovery performance. If you decrease your normal sleep time by 30min, you get a sleep debt. If you sleep the usual amount of time the next day, the debt from last night is repaired, but you are still 30 min behind. You can use naps to catch up.

  • REM
    • The brain is awake, with neurons firing with the same intensity as in wakefulness (even similar energy is used).
    • Dreaming is at its peak. In spite of high brain activity, the body is paralyzed (thalamus, a sensory gate of the brain, blocks all signals from outer senses). Otherwise you’d sleepwalk.
    • Average 4-5 stages during the night.
  • NREM
    • N1 – The first stage – 10min. Easy to wake up. Occasionally opening eyes.
    • N2 – The second stage – 20-30min. Slowly fade away. Muscles start to relax. This is true sleep phase.
    • N3 – The third stage – 30-40min. Deep sleep. Hard to wake up someone. Body regeneration starts. Neurons are globally inhibited by GABA.


Deep sleep brain waves are generated in the middle of your frontal lobes, and they travel from front to back of your brain. NREM wave is slow, and long, meaning it can travel a longer distance through your brain, allowing it to send and receive repositories of stored experience. Those waves move short-term memories from hippocampus to long-term repository in the cortex, strengthen them, and make room for new memories. REM waves allow interconnecting new material with existing experience, building a more accurate model of how your world works, including innovations and problem-solving.

  • Low gamma (30–70 Hz), and high gamma (70–150 Hz) – cognitive processing
  • Beta, 13-30 Hz – full alertness
    • REM is here between Alpha and Beta
  • Alpha, 8–13 – Relaxed, day-dreaming
    • A meditative state with eyes closed is here between Alpha and Theta
  • Theta waves, 4–8 Hz – first phase of deep sleep
  • Delta waves, 0.5–4 Hz – NREM, deep sleep


Some studies show that chronotype (night owls or morning larks) is determined by genetics, but it’s true just for a small number of permanent mutations. Also, the gene code, in this particular case, can be often overridden with healthy habits. This is what I recently believed in, and proved to be right; it can be adjusted. I always thought I was an owl, and I used to go to bed at 1-2 am for over 15 years, and even if I slept 7-8h, I was tired. My mom always said that “the best sleep is before midnight”, and she was right (she had no idea what biohacking was 🙂 ). Now, I go to bed at 9 pm and wake up at 5 am, and I am not only fully rested, but my cognition and performance during the day are much higher than before. So, if you want to change your sleeping habits, start with adjusting proper timing (you cannot cheat the Circadian Rhythm, it’s the nature’s law). Your late sleeping can be caused by simply just maintaining the bad habit over many years.

Brain detoxification

Our metabolism produces free radicals (oxygen and nitrogen) and sometimes faulty proteins (yes, our body makes mistakes). Free radicals are unstable, and they must acquire free electrons from other molecules. They can get it from DNA, cell membrane, enzymes or proteins. Oxidative stress leads to inflammation. There is a process responsible for cleaning up, called autophagy. Cells recycling their garbage put it into the lysosome disposal system. It contains acids that digest the garbage. Then, the body cleans up chemically during the night by removing toxins using lymphatic systems, but the brain is not directly connected to this system. The cerebrospinal fluid cannot reach neurons during the day, as it is very tight there. It does the cleaning during the deep sleep. There is a glymphatic system in the brain composed of glial cells. The bathing the brain is possible at night because glial cells shrink during NREM sleep by 60%. Toxins are then removed from the body by the liver.

Sleep and learning

The brain organizes memory (declarative facts and procedural skills) during deep sleep and possibly verifies it during REM (tests stressful scenarios – that’s probably why you have dreams). If you do not get enough sleep the first night after learning, your memories are likely to evaporate, even if you catch up your sleep after that. Also, one night of shift work can decrease your cognitive abilities for an entire week. Sleep for memory is an all-or-nothing event.

Muscle memory is, in fact, brain memory. Training muscles help you better execute tasks, but the memory program resides in the brain.

Optimal brain function is between 10 am and 3 pm.

Sleep deprivation

What happens if you do sleep properly:

  • Routinely sleeping less than 6 hours a night demolishes your immune system.
  • Insulin sensitivity drops by 45% when you sleep 6h. You gain weight.
  • Lack of sleep releases cortisol that is the catabolic stress hormone. It accelerates aging and makes our skin more wrinkled and dry.
  • Sacrificing sleep time for working or studying makes you less productive. Even a few days of not getting enough sleep leads to the same performance drop as not having slept for 24 hours.
  • Older people need less sleep is a myth. Atrophy in the brain related to aging first touches areas responsible for deep sleep. The older we get, the more frequently we wake up during the night.
  • Without enough good quality sleep the two emotional areas – amygdala (strong emotions like rage, anger) and prefrontal cortex (rational, logical thought) – are out of sync. You have emotional swings, and you are more aggressive.
  • If you don’t sleep well, a toxic protein called beta-amyloid aggregates in the brain. It is poisonous to neurons. It causes an Alzheimer’s disease in the long run. Temporary accumulation leads to brain fog.
  • Insomnia is an inability to generate good quality sleep despite giving yourself the opportunity to have adequate sleep. Main reasons are psychological, like anxiety and stress.

Sleep issues

  • Peeing at night
    • Insulin resistance issues. Diabetes are thirsty all the time; they drink a lot, and urine a lot.
    • Too much water drunk less than 1-2h before bed.
  • Waking at night
    • Cortisol, adrenaline issue, usually caused by stress.
  • Waking up tired
    • Not enough nutrients (low potassium) and proteins
    • Too much coffee, overtraining, short sleep
  • Restless legs
    • Vitamin B1 deficiency, too much sugar.
  • Problem falling asleep
    • Getting worried, too much food, too little exercise, too much light in the evening.
  • Fragmented sleep
    • This is when you wake up more than once for at least several minutes. Caused by dehydration, room temperature too hot, acid reflux, pets, snoring, external noises.
  • Snoring
    • Snoring may be caused by obese fat, blocking your breathing canal. Usually related to mouth breathing. Mouth breathing also reduces the amount of oxygen reaching your brain.

(I still need to investigate solutions for them)

Circadian hormones and chemicals

There are several hormones, and other molecules strictly related to sleep.

  • Melatonin
    • Melatonin is antioxidant, anti-inflammatory and anti-cancer. It signals body to prepare for sleep.
    • As we age, our pineal gland produces less melatonin at night. Boosting with pills may be reasonable.
  • Melanopsin
    • Melanopsin is a blue light-sensing protein in your eye. It can sense the light even if you have your eyes shut. It requires lot’s of light to activate, so sitting in dimmed office whole day impacts your circadian rhythm. After many weeks you get depression.
    • Melanopsin cells in your retina are directly connected to suprachiasmatic nucleus – master clock in the brain, connected to all other parts regulating hunger, sleep, fluid balance, stress response, etc.
  • Serotonin
  • Cortisol
    • Cortisol, the stress hormone, is produced actively for the first 30 minutes after waking up (no need for coffee for 2-3h after waking up, you should be already awake). It also contributes to sudden wakefulness in the middle of the night (usually related to stress).
  • Prolactin
    • Prolactin starts releasing (first few hours) during N3.
  • Dopamine
    • Related to motivation and alertness. It’s a pleasure hormone, but in reality, it is about seeking not pleasure itself. Stimulated by a red light. Morning sunlight is the best (good ratio of blue and red light).
    • High levels of dopamine and serotonin promote alertness; low levels lead to sleepiness
  • Testosterone
    • Testosterone is released in the last phase of the sleep
  • Growth hormone
    • Growth hormone starts releasing (first few hours) during N3.
  • Insulin
    • The pancreas releases insulin every time we eat and continues for 2-3h. Insulin promotes the biochemical pathway that makes fat from sugar. If we keep eating in the late evening when the pancreas is asleep, the insulin released is insufficient to remove sugar, and blood glucose becomes very high.

(all this requires more elaboration)


I am not, by any means, neither a doctor nor a pharmacist or a scientist. I am just a simple engineer. I am collecting and investigating many different lifestyle, mind, and body improvement techniques, found on the Internet, in books, articles, and I will test them on myself. Do not take any information posted here as a reliable source of information. Assume, that every sentence in my article starts with “someone on the Internet said…”. I take no responsibility nor liability for any damage or injury anyone can suffer from applying any of the mentioned techniques, digesting food, drugs, or performing exercises, whatever may be the cause. This article is for informational purposes ONLY. Whatever you do, you do at your own risk.