The call center closed at 2 a.m. and the coffee machine did not, so for two years my last cup was around midnight and my first alarm went unheard at 9. When I built the spreadsheet I gave the last coffee its own column and moved it earlier a week at a time until the mornings changed. This page is that column with the arithmetic shown.
Give it what you drank, how many, and when you want to be asleep. It counts back with the caffeine half-life to the time of your last cup, draws the curve, and marks the six hour rule next to it so you can see how the two compare.
How the math works
Half-life is the time your body takes to clear half of what you took. For caffeine the usual figure is five hours, so the 95 mg in a drip coffee is about 48 mg five hours later and about 24 mg five hours after that. It never quite reaches zero. It keeps halving.
That is why the calculator asks for a line rather than waiting for zero. The formula is one sentence: hours to clear equals the half-life times the log base 2 of the dose divided by the amount you are willing to have left. Log base 2 just counts how many halvings it takes.
Worked through with the defaults: 95 mg, a five hour half-life, and a 50 mg line. That is a little under one halving, 4 h 38 min, so an 11 p.m. bedtime puts the last coffee at 6:22 p.m. Two coffees is 190 mg, one more halving, 9 h 38 min, and the cut-off moves to 1:22 p.m. Every doubling of the dose costs one extra half-life. That is the part I wish someone had told me at the switchboard.
The 50 mg line is my rule of thumb, not a study number. It is about half a cup still in you when the light goes off, and it is where I stopped noticing the coffee. The slider runs from 10 to 100 mg because some people feel a single cup at lunch and some sleep fine after an espresso with dessert.
The milligrams per drink are averages. A drip coffee varies with the beans, the pour and the size of the cup, and a cafe pour can hold a good deal more than the list says. If you know the number on the label, pick the custom option and type it in.
What the curve shows
The curved line is the caffeine left in you, falling from the moment of the last cup to bedtime. The flat dashed line is the amount you said you could live with at lights out. Where the two meet is bedtime.
The dot at the top of the curve is the cut-off, the moment of the last cup, with a vertical line down to the axis. The small tick under the axis marks six hours before bed so you can see how the arithmetic compares with the rule of thumb. When the dose is already under your line, the dot sits at bedtime and the curve has nowhere to fall.
The six hour rule
The rule you have probably heard is no caffeine in the six hours before bed. It comes from one small study, and the study is worth knowing. Drake, Roehrs, Shambroom and Roth, in the Journal of Clinical Sleep Medicine in 2013, gave twelve people 400 mg of caffeine at bedtime, three hours before bed, or six hours before bed, on different nights, and measured their sleep. The dose six hours out still cut measured sleep by about an hour, and the participants mostly did not notice it had.
Two things follow from that. The dose was 400 mg, about four drip coffees, so six hours is a floor for a big dose, not a ceiling for a small one. Run 400 mg through the calculator with the defaults and it wants 15 hours, which is why the six hour mark is drawn on the chart next to the arithmetic instead of replacing it. The part about not noticing is the one I believe most. The next section is why.
Where the arithmetic is honest and where it is not
The half-life is the honest part and the shaky part at once. The Institute of Medicine's 2001 review gives about five hours as typical and 1.5 to 9.5 hours as the range between people. Pregnancy and oral contraceptives lengthen it a lot, smoking shortens it, and some medications change it in either direction. The slider runs from 3 to 7 hours, which covers most people and still misses some. If you are pregnant or on the pill, drag it up.
I found this out the slow way. On the switchboard I could drink a coffee at 10 p.m. and be asleep by midnight, and I took that as proof that I cleared caffeine fast. What it proved was that I was twenty-four and so short on sleep that nothing could have kept me up. The sleep was worse than it felt. Six weeks with the cut-off moved to 4 p.m. and the 5:40 wake-ups from Waffles started to feel like mornings instead of ambushes.
Sensitivity is the other thing the formula cannot see. Two people with the same half-life can react very differently to the same 50 mg, which is what the line slider is for. Move it until the number on the page matches what your nights tell you.
I am not a doctor. Caffeine alongside a medication, a heart condition, or a pregnancy is a question for one, and a calculator is the wrong place to settle it.
Tonight
Set the bedtime you actually want, not the one you usually get, and read the cut-off. If it is earlier than your last cup was today, move tomorrow's last cup by an hour and see what the morning does. The sleep calculator gives you the bedtime to count back from if you only know your alarm, and what time should I go to bed has the studies behind that number.