Caffeine doesn't give energy. It hides tiredness.
The longer you are awake, the more adenosine accumulates in your brain and binds to receptors that make you sleepy. Caffeine resembles the molecule, occupies the same receptors and blocks the signal. The adenosine, however, is still there. Its half-life is about 5 hours: half of a 4 pm coffee is still in your blood at 9 pm.
Useful: Daily caffeine drinkers grow extra adenosine receptors, which is why the effect fades over time.
Source: en.wikipedia.org