How does caffeine keep your brain feeling awake and alert?
Caffeine works by blocking adenosine receptors in the brain. Adenosine is a chemical that builds up throughout the day as a byproduct of neural activity, and as it accumulates it binds to receptors that slow brain activity and make you feel drowsy. Caffeine's molecular structure is similar enough to adenosine that it fits into those same receptors without activating them, essentially acting as a plug that keeps adenosine from doing its job.
With adenosine blocked, the brain's stimulating neurotransmitters like dopamine and norepinephrine can operate more freely, increasing neuronal firing and promoting alertness. This is why caffeine doesn't actually give you energy directly but rather suppresses the signal telling your brain it's tired.