Metabolism & sleep
Last cup before bed: when to stop drinking caffeine
Caffeine has a long tail. Because it halves roughly every 5.7 hours, an afternoon coffee can still be working at midnight. This tool finds the latest clock time you can have a standard cup and still be under about 100 mg when you go to bed.
How to use it
- Set your bedtime.
- Add any caffeine you have already had today.
- Read the “latest cup before bed” time the calculator returns.
Why the cutoff is personal, not a fixed hour
The popular advice to stop caffeine by 2 pm is a blunt rule. The real cutoff depends on three things: how much caffeine you have already had today, your bedtime, and how fast you metabolize it. A single 95 mg cup on an otherwise caffeine-free afternoon clears the 100 mg sleep threshold in under an hour, so a 9 pm coffee could be fine for an 11 pm bedtime. But stack that cup on top of a 200 mg cold brew from the morning and the picture changes — the residual from earlier drinks counts too.
What 100 mg at bedtime means
Research on caffeine and sleep often centers on the dose still circulating when you lie down. Around 100 mg in the system at bedtime is enough to lengthen the time it takes to fall asleep and to trim deep, slow-wave sleep for many people, even those who insist coffee does not affect them. Because caffeine halves every 5.7 hours, working backwards from your bedtime and target threshold gives a concrete clock time — which is exactly what this tool computes.
Make it automatic
Recalculating the cutoff every time you have a drink is tedious. The CoffeeLog app keeps your decay curve live and shows the latest-cup time on your home screen, nudging you before an evening coffee would cross the line.
What is the arithmetic behind the cutoff — cutoff = bedtime − half-life × log2(dose ÷ threshold — and how do worked examples look?
The cutoff is computed by solving dose × 0.5^(hours ÷ 5.7) = threshold for hours, giving cutoff = bedtime − half-life × log2(dose ÷ threshold). First-order elimination is a process where the fractional rate of removal is proportional to the amount present, and half-life is the time for the circulating amount to fall by half; using a population-average half-life of 5.7 hours (342 minutes) this algebra gives a concrete clock time to stop drinking.
The formula written plainly is cutoff = bedtime − 5.7 × log2(dose ÷ 100), where dose and threshold are in milligrams and the threshold used by this tool is 100 mg of caffeine remaining at bedtime. Threshold is 100 mg for the calculator's target, chosen because 100 mg circulating at bedtime is commonly associated with measurable sleep effects in controlled studies; that 100 mg threshold is the basis for the arithmetic below rather than an assertion of safety.
The underlying decay rule is remaining = dose × 0.5^(hours ÷ 5.7); here remaining is in milligrams so every substitution below shows the arithmetic in mg. Remaining is the amount of caffeine in mg after a given number of hours; the calculator and the worked examples below use this exact form to show how hours before bedtime map to mg at bedtime.
Worked example 1: Cold brew (200 mg). Cold brew is 200 mg per 240 ml in the dataset, and using dose = 200 mg the algebra gives hours = 5.7 × log2(200 ÷ 100) = 5.7 × log2(2) = 5.7 × 1 = 5.7 hours, so cutoff = bedtime − 5.7 hours. Substituting into the decay shows remaining = 200 mg × 0.5^(5.7 ÷ 5.7) = 200 mg × 0.5^1 = 200 mg × 0.5 = 100 mg, which exactly reaches the 100 mg threshold at bedtime when the last cup is taken 5.7 hours before sleep time.
Worked example 2: Mocha (95 mg). Mocha is 95 mg per 240 ml in the dataset, and with dose = 95 mg the algebra gives hours = 5.7 × log2(95 ÷ 100) = 5.7 × log2(0.95) ≈ 5.7 × −0.074 = −0.42 hours, so cutoff = bedtime − (−0.42 hours) = bedtime + 0.42 hours (about 25 minutes after bedtime). Substituting into the decay shows remaining = 95 mg × 0.5^(−0.42 ÷ 5.7) ≈ 95 mg × 0.5^(−0.074) ≈ 95 mg × 1.053 ≈ 100 mg (algebraically consistent), which means a single 95 mg mocha would already be below the 100 mg threshold at bedtime and therefore does not need the same long lead time as a 200 mg cold brew. The arithmetic keeps every term in mg when a dose is present so the numbers remain traceable to the dataset.
Both examples show the mechanism: larger single doses push the cutoff earlier in clock time because they take more half-lives to decay to 100 mg, and small doses below 100 mg can produce negative hours in the formula, which is interpreted as the drink already being below the threshold at bedtime. This is why the calculator works by adding and summing residual mg from each drink in your day rather than by a single fixed hour rule.
What does the research actually say about caffeine and sleep?
The best-known controlled laboratory result often cited is that 400 mg of caffeine taken six hours before bedtime reduced total sleep time by more than an hour; that finding is from Drake et al. 2013 (Journal of Clinical Sleep Medicine) and is linked in the sources. Drake et al. 2013 is the study showing that 400 mg taken six hours before bed caused a measurable reduction in sleep, and the paper is the anchor for the common advice about evening caffeine timing.
Caffeine affects sleep by blocking adenosine receptors and altering central nervous system activity, and this mechanism is why a circulating dose measured in mg at bedtime can predict sleep effects; adenosine receptor antagonism is the pharmacologic mechanism that reduces pressure to sleep and fragments slow-wave sleep. The Drake et al. 2013 result gives an experimentally controlled marker — 400 mg six hours before bedtime was associated with over one hour less sleep — and the model on this site translates that marker into a residual-mg approach using first-order elimination and a 5.7-hour half-life to estimate equivalent timing for smaller or larger doses.
The laboratory finding in Drake et al. 2013 is not a universal prescription for every person because the study used specific doses and timed administration under controlled conditions, and individual sensitivity and habitual intake alter real-world responses; population-average numbers still provide a practical starting point but they are not a guarantee for any single night. Public health thresholds such as the FDA's 400 mg/day guidance for healthy adults are complementary context: the U.S. Food and Drug Administration states a 400 mg per day guidance for healthy adults (FDA, consumer update), and that daily limit is linked in the sources and should be cited when considering daily totals rather than timing alone.
Why is "stop at 2 pm" wrong as general advice and what should the rule depend on?
The advice to stop at 2 pm is wrong because a clock-based cutoff ignores three quantitative inputs that determine residual caffeine at bedtime: the milligrams you consumed, your bedtime clock time, and your elimination half-life. Bedtime is the reference point for the calculator, dose in mg comes directly from the dataset entries such as Cold brew, 200 mg and Mocha, 95 mg, and the half-life used is 5.7 hours which converts those mg into a decay curve.
A fixed-hour rule like 2 pm cannot account for high-caffeine morning drinks in the dataset such as Starbucks Pike Place Brewed (Grande), 310 mg or large energy drinks such as Bang, 300 mg, both of which can leave substantial residual caffeine many hours later; the calculator will push the last-cup time earlier than 2 pm for those large doses if your bedtime is early. Conversely, small afternoon drinks such as Latte, 68 mg or Iced tea (355 ml), 45 mg may not require as early a cutoff as 2 pm for a late bedtime because their dose is low enough that remaining mg at bedtime stays under 100 mg.
The practical rule should depend on three quantities that the calculator uses directly: the accumulated milligrams from every drink in the dataset (for example you can sum Drip coffee, 96 mg plus an afternoon Espresso (single), 63 mg), your intended bedtime clock time, and any personal knowledge of slower or faster metabolism; those three inputs map uniquely to a cutoff via the first-order decay model. If you want a simple heuristic instead of the calculated cutoff, pick a conservative cutoff that accounts for your largest likely morning dose (for example assume 300 mg) and work the hours backwards using 5.7 hours per half-life to arrive at a safe clock hour for your own bedtime, but using the calculator is a more precise alternative.
What should you do when you are already over the line for tonight?
If your current cumulative residual at bedtime exceeds 100 mg according to the calculator, the immediate steps are to avoid more caffeine, lower arousal with behavioral measures, and accept that sleep architecture may be affected tonight; the most impactful immediate action is to stop ingesting additional caffeine because additional mg add to the residual and move the effective cutoff earlier. Avoiding extra caffeine includes switching to Decaf coffee, 3 mg or caffeine-free beverages listed in the dataset, and the open dataset lets you check low- and zero-mg options quickly in the drink index.
Behavioral measures that reduce presleep arousal — dim lights, reduce screen time, progressive muscle relaxation — can reduce the subjective consequences of caffeine-induced alertness even though they do not reduce circulating mg; these are non-pharmacologic mitigations and they are useful because once caffeine is absorbed there is no way to accelerate elimination beyond metabolism. If you have urgent need to be alert tonight rather than sleep, an intentional short nap earlier in the day before the high residual can preserve performance later, but naps are a trade-off with evening sleep and should be planned with the residual curve in mind.
Pharmacologic countermeasures such as taking substances to force sleep are not recommended as routine and this page provides information not medical advice; if poor sleep is chronic or if large daytime doses regularly push you over the threshold consider reducing baseline intake and consult qualified guidance. The dataset and calculators can help you plan reductions: use the caffeine half-life calculator to model residual curves for specific drinks from the dataset and the safe daily limit tool to translate intake into body-weight–adjusted limits, and if you need to compare options use the caffeine comparison tool to see mg side-by-side for common choices.
What is the difference between falling asleep and sleeping well — does caffeine affect them differently?
Falling asleep (sleep latency) is how long it takes to transition from wake to sleep, and sleeping well refers to sleep architecture and continuity such as the amount of deep slow-wave sleep and total sleep time; falling asleep and sleeping well are related but distinct outcomes. Caffeine often affects sleep architecture and the latter parts of sleep more reliably than it prevents the initial transition for all people, meaning someone may still fall asleep yet lose slow-wave sleep or have more fragmented sleep later in the night.
Experimental work shows that doses leaving substantial mg at bedtime reduce slow-wave sleep and shorten total sleep even when subjective sleepiness at bedtime allows falling asleep; the Drake et al. 2013 laboratory work demonstrated reductions in total sleep time and changes in sleep stages from evening caffeine exposure and is the controlled evidence often cited for the 6-hour marker. Those changes in sleep quality can matter for next-day cognition and recovery even if sleep latency is only mildly altered, so the calculator emphasizes residual mg at bedtime as a predictor of both latency and architecture effects rather than focusing solely on how quickly you drop off.
Because the dataset provides exact mg for common drinks such as Flat white, 130 mg, Pour over, 145 mg, and Starbucks Cold Brew (Grande), 205 mg, you can use the half-life model to see whether a given drink is likely to leave enough mg at bedtime to change sleep architecture even if you expect to fall asleep normally. The distinction is actionable: if your priority is maintaining deep, uninterrupted sleep rather than merely falling asleep quickly, aim for lower residual mg at bedtime as computed by the cutoff calculator rather than relying on subjective ease of falling asleep alone.
If you want to explore specific drinks against your bedtime, the drink index and dataset are linked throughout this explanation and the calculators in the tools section will compute cutoffs from actual mg values; examples linked above include Cold brew, 200 mg, Mocha, 95 mg, Drip coffee, 96 mg, Espresso (single), 63 mg, and Decaf coffee, 3 mg, and the tools to model them are at caffeine half-life calculator, safe daily limit, and caffeine comparison. For broader context about the dataset and methods see the site open dataset and the about page which document sources and model assumptions; the Drake et al. 2013 paper and the FDA guidance are linked in the sources for anyone who wants the original reports (Drake et al. 2013, FDA 400 mg/day guidance).
Frequently asked questions
How many hours before bed should I stop caffeine?
A common guideline is 8–10 hours, but it depends on the dose and your metabolism. From a 95 mg cup it takes under an hour to clear the 100 mg sleep line if you have had nothing else; from a large energy drink it can be many hours.
Why does afternoon coffee affect sleep?
With a 5.7-hour half-life, about a quarter of a 2 pm coffee is still circulating near midnight. Even when you do not feel wired, that residual caffeine can reduce deep sleep.
Does caffeine before bed really reduce sleep quality?
Yes. Studies show caffeine taken even 6 hours before bed can cut total sleep time and reduce deep sleep, often without the person noticing. The effect is on sleep architecture, not just falling asleep.
CoffeeLog · iOS
Track this automatically with CoffeeLog
This site answers the question once. CoffeeLog answers it every day — logging what you drink, showing caffeine fade in real time, and telling you the last cup you can have before it reaches your sleep.
Read next
TrackCaffeine provides general reference information about caffeine. It is not medical advice. Caffeine values are public-source estimates, not exact measurements.