Enter what you drank today — see the caffeine curve, what's left at bedtime and the latest safe cup.
Caffeine is metabolized exponentially. Its half-life is the time after which half of a dose remains active. For most adults it's between 4–6 hours — shorter for smokers, much longer during pregnancy or while on the contraceptive pill. Concretely: drinking 100 mg at 3 pm leaves ~50 mg in your body at 8 pm, ~25 mg at 1 am.
Rule of thumb: no caffeine 6–8 hours before bed. A more precise approach uses the half-life: if your threshold is ~100 mg and you drink 200 mg, you need one half-life to get below — i.e., 5 hours before bed at a 5h half-life. For 400 mg you need two half-lives = 10 hours.