See how long caffeine stays in your system. This free caffeine half-life calculator estimates how much remains now and at bedtime from your dose, when you had it, and your metabolism.
Enter how much caffeine you had and how long ago. Pick the metabolism that fits you. A common reference for a coffee is about 95 mg; an energy drink ~80 mg; a tea ~40 mg.
Caffeine decays exponentially: remaining = dose × ½^(hours ÷ half-life). With an average half-life of about 5.7 hours, roughly half of a dose remains after ~6 hours and a quarter after ~12 — which is why afternoon coffee can still affect sleep.