To many of us, caffeine is like a superhero—swooping in to save us from the drowsy morning or mid-day slump and carrying us through the rest of the day. What we tend to forget in all of our appreciation of the trusty caffeine buzz is that it is a stimulant drug—and a very powerful one at that. While this substance does an awesome job of pumping us up mid-afternoon, it has terrible effects on our sleep later on. But wait!—before you close this page, grab your grande and run, let us tell you why, and how you can drink coffee while still protecting your sleep.

Stubborn caffeine

Caffeine sticks around in your system for a while. Caffeine has a half-life of roughly five to six hours. What does that mean for you? Say you drink a grande coffee at 4 p.m. (clocking an impressive 300 mg of caffeine), then fast forward to 10 p.m. and you still have more caffeine in your system than if you had downed an energy drink. This is problematic when it comes to trying to fall asleep.

Even if you’re somehow able to fall asleep with caffeine still kicking around in your system, you risk the chance of losing out on restorative deep sleep and decreasing your total sleep time by up to an hour. And the last thing you need is to be getting less sleep!

Holding back sleep

A chemical compound called adenosine is responsible for creating “sleep pressure” in our brains. Adenosine works along with our circadian rhythms—it builds all day while we’re awake, and then releases at night while we sleep. When the pressure builds enough, that’s a signal to our body that we’re tired.

Caffeine tricks your body into thinking that it’s not tired by creating a barrier between your brain and the building adenosine. Sleep scientist Matthew Walker in his book Why We Sleep explains: “...caffeine blocks and effectively inactivates…[adenosine] receptors, acting as a masking agent”. He describes it as similar to “sticking your fingers in your ears to shut out a sound”.

All the while, sleep pressure builds up behind this dam of caffeine, and when the dam finally wears down hours later, the big wave of sleep pressure comes in all at once. This process is problematic for people drinking caffeine late in the day, because the dam stays strong long into the night, keeping you from the sleep pressure that aids your brain in initiating sleep.

Last call for coffee

As promised, the sleep-smart way to get your coffee: commit to a strict cutoff time of 2 p.m. for any caffeinated beverages, in order to give yourself plenty of time for the caffeine to wear off before bedtime. So this means you’re good to get your dose of caffeine in the morning if you need a quick perk-up—that’s what caffeine is for anyways, right? However, if you find yourself relying on caffeine to get you through every morning, you may want to examine the quality of the sleep you’re getting every night. After all, the best all-natural way to ensure happy, alert mornings will always be a great night’s sleep!