Find the caffeine cutoff for good sleep.
Caffeine clears exponentially with a half-life of about five hours in most adults, so the time needed to fall from your dose to an acceptable bedtime residual is a logarithm of the ratio between them. A 150 mg coffee therefore needs roughly twelve hours to drop below 30 mg — which is why an afternoon coffee affects sleep even when you fall asleep normally. Five half-lives is the conventional point of near-complete clearance.
Caffeine cutoff
Hours needed = half-life x ln(dose / acceptable residual) / ln 2; cutoff time = bedtime - hours needed
Caffeine sensitivity varies widely and interacts with medications and medical conditions such as arrhythmia, anxiety disorders and pregnancy. This is a general model, not medical advice.
Commonly eight to ten hours before bed, and longer for large doses or slow metabolisers. The exact cutoff depends on the dose and your own half-life.
Caffeine reduces deep sleep and increases fragmentation even when onset is unaffected, which shows up as unrefreshing sleep rather than insomnia.
Genetics, liver enzyme activity, pregnancy, oral contraceptives and smoking all shift it substantially — the range across healthy adults spans roughly three to nine hours.