Finally, science has come up with a useful study!

A team of researchers in Scotland looked into how late in the day you can drink coffee WITHOUT it effecting your sleep. That answer?

Six hours before bed.

“Caffeine is consumed daily by roughly 80% of the world’s population, often for its benefits in promoting wakefulness and concentration,” says Reneta Riha, the lead author of the study, in a media release. “Its effects can last for several hours, depending on how quickly or slowly it is metabolized by the body.”

Riha also cautions that not everyone’s metabolism is the same, so if you find yourself unable to sleep even if you stop in the six hour window, you may want to consider decaf in the afternoon and evenings. They also found that you can do four to five cups a day, as long as you knock off early enough.

And, bonus, it has been found that three to four cups per day can lower the risk for liver disease!

Coffee: it really is a miracle drink!