Adenosine is a molecule that builds up in the brain as you stay awake, and it binds to receptors on nerve cells to slow activity and make you feel drowsy. Caffeine has a shape similar to adenosine, so it fits into those same receptors without activating them, effectively blocking adenosine from doing its job.
Because caffeine occupies the receptors instead of adenosine, nerve cells keep firing more freely and you feel more alert. Over time the brain may grow extra receptors in response, which is one reason regular coffee drinkers can feel tired when they skip their usual dose.