This is a great video showing how caffeine in coffee works in the brain to reduce sleepiness…
I found this video to be quite good and accurate. It was made by ASAPScience and if you like their video, you might want to take a look at their book ASAPScience.
The more time we are awake, the more adenosine builds up in the brain. This is what makes us sleepy. When we sleep, the adenosine level decrease so that we no longer are as sleepy. However, caffeine affects this sleep regulation, because caffeine competes with the adenosine receptors and blocks the adenosine from docking. So we don’t feel sleepy.
The half-life of caffeine is about 6 hours. That means that it takes six hours for half of the caffeine to disappear from the system. So if you want to sleep, don’t drink caffeine close to bed (preferably not after noon).
Alternatively drink decaf. Fortunately, BrainHQ article writes that the antioxidant levels is decaf is similar to that of regular coffee. But unfortunately, it is the caffeine properties that seem to stave of dementia (in animal studies) [reference]
So caffeine can be both good and bad. Good for staving off dementia, bad for sleep.