Caffeine acts on a chemical in your brain called adenosine, neurologist and sleep medicine specialist Ajay Sampat, MD, assistant clinical professor at UC Davis Health, tells SELF.

“Adenosine is like a sleep-inducing molecule that your brain makes while you’re awake. The longer you’re awake, the more adenosine you have in your system,” Dr. Sampat explains. And caffeine is essentially an adenosine antagonist, binding to molecules of adenosine and lessening its sleep-inducing effects, Dr. Sampat says.

Caffeine’s primary stimulant effects occur in the first hour or so, when it reaches peak levels in your blood, according to the U.S. National Library of Medicine.“Most people feel that jolt of energy around the first 15 to 45 minutes,” Dr. Sampat says.

But it takes a long, long time for caffeine to completely leave your system, with its zippy side effects gradually wearing off as time passes and your body metabolizes it, Dr. Sampat says. Typically, the half-life of caffeine is around four to six hours, according to the Food and Drug Administration (FDA), meaning that four to six hours after consumption, about half of that caffeine is still in your system. At this point, you may still be feeling some stimulant effects of the caffeine, Dr. Sampat says. Then, another four to six hours later, half of that amount is gone. If you drink a cup of coffee containing 100 mg of caffeine at 10 a.m. (about one 8-ounce cup of coffee) as much as 25 mg may still be in your system when you lay down at 10 p.m., whereas if you drink 200 mg at 4 p.m. (twoish 8-ounce cups), about 100 mg can still be in your system at 10 p.m.