The best-known study on this question gave people 400 mg of caffeine zero, three or six hours before bed and measured their sleep in a laboratory. Even six hours before bedtime, caffeine cut total sleep time by more than an hour and reduced sleep quality. The effects were measurable in people who said they felt fine.

mg
mg

What this calculator is doing

Because caffeine is cleared in a predictable way, you can work the arithmetic backwards: decide how much you are willing to have in your body at bedtime, and the calculator tells you the latest hour you can drink. Six hours is a good starting rule; sensitive sleepers often do better with eight or more.

How to use it

  1. Enter the time you intend to be asleep, not the time you get into bed.
  2. Use the size of your usual afternoon coffee, not a guess — 16 oz of filter coffee is often 180–200 mg.
  3. If you sleep lightly, set the target lower (25–50 mg) rather than moving the cut-off earlier by guesswork.

Formulas and assumptions

Latest intake time
cut-off = bedtime − t½ × log₂(dose ÷ target)

A 200 mg dose with a 50 mg target at a five-hour half-life needs 10 hours, so with an 11 pm bedtime the last cup is at 1 pm.

Residual at bedtime
left = dose × 0.5^(hours before bed ÷ t½)

Use this to check a drink you have already had, or to compare a 3 pm coffee against an 8 am one.

The six-hour rule
no caffeine within 6 hours of bed (8–10 if sensitive)

From laboratory sleep studies: 400 mg six hours before bed reduced total sleep time by over an hour and increased wakefulness during the night.

Caffeine in your body before bed

Dose of 200 mg, five-hour half-life. Lower doses scale proportionally.
Time before bedStill in your bodyEffect on sleep
0 h200 mgFalling asleep is harder and deep sleep is reduced.
2 h152 mgClear effect on sleep quality.
4 h115 mgMeasurable reduction in deep sleep.
6 h87 mgStill cuts total sleep time by around an hour at this dose.
8 h66 mgMild but real for sensitive sleepers.
10 h50 mgBelow the threshold for most people.
12 h38 mgNegligible for most, still felt by the very sensitive.

Effects on sleep onset and depth appear at lower doses than the ones that make you feel alert.

Frequently asked questions

Is six hours enough?

It is a reasonable default, not a guarantee. In the laboratory study, six hours before bed still measurably reduced sleep. People who describe themselves as sensitive to caffeine often need eight to ten hours.

Does caffeine reduce sleep quality or just make it harder to fall asleep?

Both. It lengthens the time to fall asleep, reduces total sleep time and cut deep slow-wave sleep in the studies, and the effects on sleep quality show up on polysomnography even when the sleeper reports a normal night.

Does tea count?

Yes, at its own dose. A cup of black tea at 9 pm is about 47 mg — usually not enough to matter, but three cups or a strong matcha in the evening add up to a coffee's worth.

What if I drink coffee after dinner and sleep fine?

You may be a fast metaboliser, or you may be sleeping less deeply without noticing. People are poor judges of their own sleep debt: in controlled studies, participants consistently under-reported impairment. A tracker with sleep staging, or a week of earlier cut-offs, will tell you more than a feeling.

Sources and further reading

  • Drake C, Roehrs T, Shambroom J, Roth T. Caffeine effects on sleep taken 0, 3, or 6 hours before going to bed. J Clin Sleep Med. 2013;9(11):1195-1201. source
  • European Food Safety Authority. Scientific opinion on the safety of caffeine. EFSA Journal. 2015;13(5):4102. source
  • U.S. Food and Drug Administration. Spilling the beans: how much caffeine is too much? source
Last updated: November 2026 Reviewed by the RhythmCalc editorial team How we build our calculators

RhythmCalc gives general information for healthy adults, not medical advice. Sleep, caffeine and nutrition needs vary between people and change with health conditions, medication and pregnancy. Talk to a qualified clinician about your own situation.