You make another cup at four in the afternoon. You sleep badly in the evening but do not know why. The next morning you start tired and reach for coffee early. That cycle is recognizable for many people, and caffeine plays a central role in it.
Coffee and sleep are more closely connected than most people realize. Here is the science behind it.
How caffeine affects sleep via adenosine
Caffeine works by blocking adenosine receptors in the brain. Adenosine is the substance that builds up sleep pressure throughout the day: the longer you are awake, the more adenosine accumulates and the sleepier you become. Caffeine takes the place of adenosine on the receptors but does not cause adenosine to break down. It only blocks the signal.
Once the caffeine breaks down, all the accumulated adenosine is released at once. That is why after a long day with a lot of coffee you sometimes fall asleep heavily but still do not wake up rested. Caffeine sleep disruption affects the deep sleep phases too, even when you fall asleep normally. Research shows that caffeine significantly reduces slow-wave sleep, the deepest and most restorative sleep phase.

When to stop drinking coffee: what the science says
The half-life of caffeine is between 5 and 6 hours for most people. That means half the caffeine from a cup of coffee at 3pm is still in your body when you go to bed at 9pm. Research published in Sleep Medicine Reviews calculated that a regular cup of coffee must be consumed at least 8.8 hours before bedtime to avoid reducing total sleep time.
For most people with a bedtime of 11pm that means: stop drinking coffee around 2pm. Those who are more sensitive to caffeine, or have a slower metabolism due to genetic variation in the CYP1A2 gene, should stop even earlier. Coffee insomnia is often not insomnia at all but caffeine that is still active while you have been in bed for hours.
Is decaf a real alternative
Decaf is not completely caffeine free. An average cup of decaf still contains 5 to 15 milligrams of caffeine, compared to 80 to 120 milligrams in regular coffee. For most people that is little enough not to disrupt sleep, but sensitive people can still notice effects from late consumption.
Decaf is a more realistic evening alternative than many people think, as long as you want to keep the habit of a warm drink. The taste of good decaf specialty coffee has improved significantly, partly due to better decaffeination processes. Specialty coffee caffeine content also varies by bean and roast level: lighter roasting preserves more of the flavour and complexity of the bean, while darker roasting masks the taste but also influences the caffeine content.
Why the quality of your coffee also affects sleep
Those who get less caffeine per cup but still want flavour drink fewer cups. That is the simplest way to reduce total caffeine intake without giving up the ritual. Healthline confirms that timing and dose together determine how caffeine affects sleep, and that both are adjustable.