Caffeine has a very long tail
Caffeine’s half-life is about five to six hours, so an afternoon coffee is still there at midnight — and it shortens sleep even when it doesn’t feel like it.
The coffee at two o'clock is still measurably present at midnight.
While you are awake, adenosine accumulates in the brain. It is the molecular record of how long you have been up, and the pressure to sleep is largely what that accumulation feels like from the inside.
Caffeine does not clear any of it. It occupies the same receptors so the adenosine cannot, which is why the tiredness is still underneath the whole time and arrives all at once when the caffeine leaves.
Caffeine does not give you energy. It defers the bill.
The number worth carrying around is the half-life: roughly five to six hours in most adults, longer in some. Two hundred milligrams at two in the afternoon leaves about a hundred at eight and about fifty at two in the morning. Half a strong coffee is not nothing.
The awkward part is that the effect shows up in measurements before it shows up in opinions. Caffeine taken six hours before bed has been found to reduce objectively recorded sleep while the drinkers' own judgement of their sleep stayed the same. Not noticing is not evidence of not being affected.
The longer answer
Where caffeine sits among the other evening habits is in a bedtime routine for adults, which keeps it away from bedtime along with alcohol, and in sleep hygiene, which looks at what each of the familiar rules is worth on its own. Tired but can’t sleep counts caffeine among the usual reasons that being tired and falling asleep come apart.