The half-life is the useful concept
Caffeine leaves the body on an exponential curve with a half-life averaging around five hours in healthy adults. A 200 mg dose at three in the afternoon is 100 mg at eight, 50 mg at one in the morning and 25 mg at six. That slow tail is why an afternoon coffee can still be doing something at midnight, and it is the arithmetic behind the residual line in the result.
Five hours is a population average covering a genuine spread of roughly three to seven. The enzyme responsible, CYP1A2, varies substantially by genotype, so two people drinking identical amounts can be left with very different quantities at bedtime. Oral contraceptives and pregnancy both roughly double the half-life. Smoking roughly halves it, which is one reason people who quit often find their usual coffee suddenly feels like too much. Some medications inhibit the same enzyme and extend the tail considerably.
What the reference figures are and are not
The 400 mg per day figure that appears on this page is the one most commonly cited by public health authorities for healthy adults, based on reviews finding no consistent evidence of harm at or below it in that population. It is not a target and not a threshold at which something happens. The 200 mg figure quoted for pregnancy comes from a different literature with different endpoints, and guidance on it is not uniform across countries. The per-kilogram figure used for children and adolescents is more cautious again.
What none of them do is describe an individual. Someone with an arrhythmia, an anxiety disorder or reflux may find far smaller amounts problematic. Someone taking a medication that inhibits caffeine metabolism is effectively getting a larger dose than the label suggests. These figures are population reference points that a page like this can compare a total against; they are not permissions, and they are not a substitute for a conversation with a clinician when there is a medical reason for the question.
Where the caffeine actually is
The single largest source of error in a day's total is cup size. A home mug of brewed coffee is often 8 to 12 ounces; a coffee shop large is 20 and sometimes contains three times what people mentally file as "a coffee". Cold brew is typically more concentrated than drip at the same volume. Energy drinks vary from 80 mg in a small can to well over 300 in a large one, and concentrated shots are higher again.
Beyond drinks, caffeine turns up in pre-workout supplements, in some weight-loss and pain-relief products, in chocolate in small amounts, and in energy gels and chews. Decaffeinated coffee retains 5 to 15 mg per cup, which is negligible for one cup and not for six. Packaged products list their content, so where a number is printed it is worth using instead of any table.
Tolerance, and what it does not cover
Regular intake produces tolerance to the subjective alertness effect fairly quickly, which is why habitual drinkers report that coffee no longer does much. Tolerance to the effects on sleep architecture is much less complete. It is entirely ordinary to feel unaffected, fall asleep normally, and still show reduced deep sleep on a measurement — the absence of a subjective effect is weak evidence about what is happening.
Which leaves the residual figure at bedtime as the number most worth looking at on this page. If it seems high and sleep is a concern, the variable that moves it most is not the daily total but the timing of the last drink, and shifting that earlier costs nothing to try.
Questions people ask
How much caffeine is in a cup of coffee?
For a 12 ounce mug of drip coffee, somewhere around 140 mg is a reasonable central estimate, but the honest range is roughly 90 to 200 for the same nominal cup. It depends on the bean species, the roast, the grind, the brew method and the ratio of coffee to water. Cold brew usually lands higher per ounce than drip. Coffee shop sizes complicate it further: a 20 ounce cup can carry 250 to 400 mg, which is two or three home mugs in one container. Where a number is printed on packaging, use it — it will be closer than any generic table.
Is decaf caffeine-free?
No. Decaffeination removes most but not all of it, leaving roughly 5 to 15 mg per cup depending on the process and the serving size. For one or two cups that is small enough to ignore in almost any context. For someone drinking six or eight cups a day it adds up to something comparable to a regular cup of tea. It is also worth knowing if the reason for switching to decaf is a medical one where small amounts matter, in which case the actual figure for the specific product is the one to find.
Does the residual estimate at bedtime mean I will sleep badly?
It does not predict anything about your sleep. What it shows is roughly how much would still be circulating on average metabolism, and the page overstates it slightly by treating the whole day as consumed at the time of the last drink. Sleep studies have found measurable reductions in total sleep and in deeper stages from doses taken six hours before bed, including in people who reported no trouble falling asleep, so a large residual is a plausible thing to experiment with. But sensitivity varies several-fold between people and the only way to find where you sit is to change the timing and observe.
Why does the calculator not tell me to cut down?
Because it has no basis for that. The reference figures it compares against are population-level statements about healthy adults published by public health bodies, and they differ between countries. What is appropriate for a specific person depends on pregnancy, cardiac and psychiatric conditions, liver function, other medications and their own experience of the stuff, none of which this page can see. It adds up the milligrams and shows how they decay. Any decision that follows belongs with you and, where there is a medical reason for the question, with a clinician.