Most people think caffeine keeps you awake. It doesn't — caffeine had no meaningful effect on time spent lying awake in bed (p-value ~0.9).
What it actually does is destroy your REM sleep while leaving light sleep almost untouched. The damage is invisible — you fall asleep fine, but the most restorative part of your sleep takes the hit.
Full analysis: Caffeine Kills Your Deepest Sleep First