Every time I finish a meal at a restaurant, I’m faced with the question of all questions: Would you care for dessert and/or coffee? Obviously I’ve known what I’ll be having for dessert since I sat down, but if left alone I’d deliberate over whether to order a coffee until the restaurant has long been closed. I worry that the extra eight ounces of coffee will keep me up all night. I fear that my heart will race for hours, pumping the caffeine through my veins so swiftly I can feel it in my wrists. And since I’m embarrassed to ask my waiters, I asked the internet: How late in the day can you drink coffee?

A 2013 study performed by the Sleep Disorders & Research Center at Henry Ford Hospital and Wayne State College of Medicine looked at the effects of caffeine on sleep. The researchers found that whether taken 0, 3, or 6 hours before going to bed, a significant amount of caffeine would likely disrupt sleep. However, this study measured their findings using 400 milligram-doses of caffeine. Considering that 1 8-ounce cup of coffee typically contains about 95 milligrams of caffeine, while 1 shot of espresso has about 65 milligrams, it’s definitely not surprising that ingesting 400 milligrams of caffeine even several hours before bed would ruin your sleep, and that may be one of the more mild results. 

After ingesting more than 200 milligrams of caffeine (the rough equivalent of about 2 standard cups of coffee), “many people report anxious, jittery feelings of uneasiness," Laura Juliano, a caffeine researcher at American University, told NPR. Jitters aside, Juliano’s research suggests that even just a bit of caffeinated coffee in the morning can affect sleep. "There's research to show that people who have caffeine in the morning can take longer to fall asleep that evening," she says.

The National Sleep Foundatio explains that caffeine can have a stimulating effect even just 15 minutes after consumption, and can take about 6 hours for half of the caffeine ingested to leave your system. By this logic, an after-dinner espresso finished by 8 p.m. would likely leave around 30 milligrams of caffeine in your system until about 8 a.m. the following morning.

Ultimately, everyone’s system handles caffeine differently. A 4 p.m. coffee date will likely not deeply affect the sleep of someone with a midnight bedtime, but if you know you have trouble drifting off after coffee, don’t go for a cup at the end of a late dinner. If you’re really craving the flavor, opt for decaf—it doesn’t taste that different.