Why coffee at four wrecks your sleep

The half-life of caffeine, the switch it blocks, and what is still in your blood at bedtime.

Caffeine does not give you energy. It hides the signal that says you are tired. Half of what you drink is still in your blood about five hours later, and a quarter after ten. So the espresso at four in the afternoon is still working at midnight. Type what you drank below and the page draws it.

The rule: half every five hours

The liver clears caffeine at a steady fraction per hour, so the amount in your blood halves on a fixed clock. For a healthy adult the half-life averages about 5 hours, and the real range is 3 to 7. That gives the only formula on this page:

left = dose × 0.5 ^ (hours ÷ half-life)

An espresso at 16:00, 63 mg, at 23:00 has been through 7 hours, so 63 × 0.5 to the 1.4, which is 24 mg. At 07:00 the next morning, 8 mg. A large filter coffee at 16:00, 95 mg, leaves 36 mg at bedtime. A 500 ml energy drink leaves 61 mg. Two of those and you go to bed with more caffeine than an espresso.

What it blocks

While you are awake your cells burn fuel and a by-product called adenosine builds up in the brain. It docks onto receptors on nerve cells and slows them down. The longer you are awake, the more adenosine, the heavier your head. Sleep clears it. That is sleep pressure, and it is the main reason you feel tired at night.

Caffeine has nearly the same shape as adenosine. It sits in the same receptors and does nothing, so the adenosine cannot dock. The tiredness is still there, piling up behind a closed door. When the caffeine clears, the door opens and all of it arrives at once: the afternoon crash. The idea is from Solomon Snyder's lab in 1981, and Bertil Fredholm spent the next twenty years proving it was the whole story at the doses people drink.

What it does to sleep, measured

Drake's lab in Detroit gave people 400 mg of caffeine, two large coffees, at bedtime, 3 hours before, and 6 hours before, and recorded their sleep with sensors. All three cut sleep. The dose taken 6 hours before bed took more than an hour off the night, and the sleepers did not notice: their diaries said they had slept fine (Drake, Roehrs, Shambroom and Roth, 2013).

A 2023 review of 24 such studies found that caffeine takes about 45 minutes off a night on average and cuts the deep sleep. From the curves, the authors put the last ordinary coffee, about 107 mg, at 8.8 hours before bed, and a 217 mg pre-workout dose at 13.2 hours (Gardiner and colleagues, Sleep Medicine Reviews, 2023). For a 23:00 bedtime that is a last coffee at about 14:00.

Why your friend sleeps fine after an espresso

The half-life is not the same in everyone. One liver enzyme, CYP1A2, does almost all the work, and the gene for it comes in a fast and a slow version. Smoking speeds the enzyme up, so a smoker clears caffeine in about half the time. The pill slows it, roughly doubling the half-life. In pregnancy it stretches to 15 hours or more by the last months. A newborn takes days. So the slider above matters: 3 hours and 7 hours are both normal people.

And some people have a version of the adenosine receptor that caffeine binds less well, so they feel less of it. What nobody has yet is a cheap test that tells you your own number. Until then the honest test is the one above: drink, note the time, and see how you sleep.

What is in the cup

Measured values vary by bean, roast and barista. These are typical figures from the USDA tables and the European Food Safety Authority, and the ones the calculator uses.

Decaf is not zero: an espresso keeps 2 to 5 mg. Dark chocolate counts. Tea has less caffeine than coffee but a lot of tea is a coffee.

How much is safe

The European Food Safety Authority's 2015 opinion: up to 400 mg a day for a healthy adult, no more than 200 mg in one go, and no more than 200 mg a day in pregnancy. For children the figure is 3 mg per kilo of body weight, so a 30 kg child is at the limit after one can of cola and a chocolate bar.

Caffeine withdrawal is real and brief: a headache and a heavy head for two or three days after you stop, worst on day two. That is the adenosine receptors, which multiplied to get round the blockade, now with nothing to block them.

This page is arithmetic, not medical advice. If you are pregnant, have a heart rhythm problem, take medicines (some antibiotics and antidepressants slow caffeine a lot), or have a child drinking energy drinks, ask a pharmacist or doctor, not a web page.

In Como

The after-lunch espresso at 14:00 is almost gone by bedtime: 18 mg at 23:00. The problem is the 17:00 one with a friend at the lake, 63 mg, still 27 mg at 23:00 and enough to shave the deep sleep, and the after-dinner one at 21:00, 48 mg at 23:00. The Italian habit of a small espresso rather than a big filter cup is the right one; it is the hour, not the cup.