How Caffeine Affects Sleep (And When to Stop Drinking It)
Caffeine works by blocking adenosine, the molecule that accumulates in your brain while you are awake and creates what we experience as sleep pressure. Caffeine does not remove adenosine — it occupies the receptors adenosine would bind to, so the pressure builds up unseen. When the caffeine clears, the adenosine is still there, which is why a late afternoon coffee can leave you tired at 11 p.m. and wide awake at 3 a.m.
That mechanism explains the two things people get wrong about caffeine and sleep. The first is thinking it only matters if it keeps you from falling asleep. The second is assuming a fixed cut-off time works for everyone.
It affects sleep quality, not just sleep onset
The most useful study on this is a 2013 double-blind trial by Drake and colleagues, published in the Journal of Clinical Sleep Medicine. Participants took 400 mg of caffeine — about two cups of coffee — at three different times before bed: immediately, three hours before, and six hours before. Sleep was measured objectively with polysomnography, not self-report.
The result: caffeine taken six hours before bedtime reduced total sleep time by more than an hour. It also reduced time spent in slow-wave (deep) sleep. Participants largely did not notice. Their subjective sense of how well they had slept barely changed, even though the EEG said otherwise.
That gap between what you feel and what is measured is the important finding. You can drink coffee at 4 p.m., fall asleep at 11 p.m. without difficulty, and still be losing an hour of sleep and a chunk of deep sleep every night — without knowing.
Half-life is the number that matters
Caffeine’s half-life in healthy adults averages about five hours, with a normal range of roughly three to seven. That means half the caffeine from a 2 p.m. cup is still in your system at 7 p.m., a quarter at midnight, and an eighth at 5 a.m.
Several things push that half-life upward:
| Factor | Effect on half-life |
|---|---|
| Oral contraceptives | Roughly doubles it |
| Pregnancy (third trimester) | Can reach 15 hours |
| Liver conditions affecting CYP1A2 | Prolonged |
| Some drug interactions (e.g. fluvoxamine, ciprofloxacin) | Markedly prolonged |
| Smoking | Shortens it — roughly halves it |
| Genetic variation in CYP1A2 | Fast or slow metaboliser, up to 4x difference |
This is why “no coffee after 2 p.m.” is good advice on average and wrong for a meaningful minority. A slow metaboliser on an oral contraceptive may still have meaningful caffeine at midnight from a noon cup.
Finding your own cut-off
There is no test most people will take, so use behaviour instead.
1. Pick a cut-off and hold it for two weeks. Start at 2 p.m. if you are unsure. 2. Keep total intake moderate. Up to 400 mg a day is the level generally considered safe for healthy adults (roughly four cups of brewed coffee). The timing question is separate from the dose question, and both matter. 3. Judge by mornings, not bedtimes. The signal is how you feel in the first hour after waking, and whether you wake during the night. If you are reaching for coffee to become functional, your sleep is being shortened somewhere. 4. Move it earlier by two hours if you wake at 3 a.m. regularly. Early-morning waking with a racing mind is a common signature of caffeine that has not cleared. 5. Do not quit abruptly if you drink a lot. Cutting from four cups to zero produces a withdrawal headache for two to nine days that will make you conclude caffeine was helping. Taper by a cup every three days.
The hidden sources
Coffee is not the main problem for most people who cannot work out why they sleep badly. These are:
- Pre-workout supplements — often 200–300 mg per scoop, frequently taken at 6 p.m. before the gym
- Energy drinks — 80–300 mg, and often consumed in the afternoon
- Strong tea — a large mug of builder’s tea is 60–90 mg; matcha is comparable to coffee by weight
- Cola — 30–40 mg per can, easy to drink three of
- Dark chocolate — 20–30 mg per 30 g, more in high-cocoa bars
- Decaf — not zero; typically 2–15 mg per cup
- Some painkillers and cold remedies — 30–65 mg per tablet, often taken at bedtime without a second thought
If you are serious about testing your sensitivity, cut all of these for two weeks, not just coffee. Otherwise you will conclude caffeine is not the issue when the pre-workout was.
What caffeine does not do
It does not replace sleep. Performance under caffeine while sleep-deprived is still impaired, particularly on tasks requiring sustained attention and on anything involving memory consolidation.
It does not cause insomnia in everyone. Some people genuinely sleep well on late coffee — usually fast metabolisers. Their experience is real; it just does not generalise.
It does not make you a “bad sleeper”. Caffeine sensitivity is largely genetic and it interacts with anxiety, alcohol and shift work. If you are sensitive, that is information about your physiology, not a character flaw.
A note on alcohol, since they travel together
Caffeine and alcohol both fragment sleep, in different ways. Alcohol shortens the time to fall asleep and then produces a rebound in the second half of the night — which is why the 3 a.m. waking that people blame on stress often follows two glasses of wine. If you are dealing with early-morning waking, changing both is more informative than changing either alone.
FAQ
How long before bed should I stop drinking coffee? At least six hours on the evidence, and eight to ten if you are sensitive, over 50, pregnant, or taking an oral contraceptive. The six-hour figure comes from measured sleep loss, not from a guideline.
Does caffeine reduce deep sleep? Yes. The 2013 trial found reduced slow-wave sleep even when caffeine was taken six hours before bed, and even in participants who did not report worse sleep.
Can I build a tolerance to the sleep effects? Partially. Tolerance develops to the alerting effect more than to the sleep-architecture effect. Regular consumers still show disrupted deep sleep, they just stop noticing the wakefulness.
Is decaf safe before bed? Largely, at 2–15 mg per cup. It will not meaningfully affect sleep for most people, though a very sensitive person may notice.
Does caffeine help with sleep apnea? No. It may mask daytime sleepiness, which is dangerous because untreated apnea is a cardiovascular risk. If you are sleepy despite adequate time in bed, see a clinician rather than drinking more coffee. See our medical disclaimer.