Your 4 p.m. coffee is still half there at midnight.
Caffeine blocks adenosine receptors – adenosine is the signal that builds up sleep pressure across the day. Its half-life in adults is typically around 5 hours, with a wide range of roughly 3 to 7. So of 200 mg in the afternoon, roughly 100 mg is still active at midnight, even if you don’t feel wired.
Useful: If you struggle to fall asleep, try having your last coffee 8 to 10 hours before bedtime.
Source: en.wikipedia.org