The coffee you drank this morning was spiked with a powerful plant-produced insecticide — but you’re okay with that. It’s why you drank it in the first place. It’s called caffeine, and if you’re like 64 percent of Americans, hardly a day goes by when you don’t consume it. According to the American Journal of Physiology, caffeine’s energizing effect occurs when the chemical latches on to our neurotransmitters and blocks a sleepiness-inducing chemical called adenosine, which builds up naturally in our bodies throughout the day. People consume caffeine for various reasons — to shake off morning grogginess, to focus better on work, to party all night — but what is its impact on exercise?

“There is a large body of evidence showing that caffeine is the most effective legal performance drug out there,” said Kristen Arnold, a licensed dietician with a master’s degree in human nutrition. “For endurance sports, specifically. So, time trials, team sports such as soccer, basketball, and also sports that involve sleep deprivation, like ultra endurance.”

Arnold is right: in recent years, many studies have shown caffeine to have several benefits for athletic performance. The International Society of Sports Nutrition says caffeine is “very effective” at improving athletic endurance. And in one study in the Journal of Applied Physiology, several athletes who consumed caffeine pills ran 2-3 km more than those who drank coffee or consumed no caffeine at all. When it comes to brain stimulation, “nothing is better than caffeine,” Dr. Indre Viskontas\, Ph.D. in Cognitive Neuroscience, says.

So, caffeine is a performance-enhancing drug. But it’s not the kind of performance-enhancing drug that Mark McGwire would inject into his ass cheek in an empty St. Louis Cardinals locker room. For one thing, caffeine is totally legal. Even the World Anti-Doping Agency, knowing full well its effects, recognizes caffeine as an acceptable performance-enhancing drug (up until 2004, it was banned). And the International Olympic Committee says it’s perfectly OK for Olympic athletes to use caffeine, as long as the amount in their urine stays below a certain amount. The world of sports science seems to agree that caffeine can be beneficial to athletes and everyday gym-goers alike. But reaping those benefits is a bit more complicated than simply tossing back a few shots of espresso before a race or gym session. Here are a few things you should know.

The molecule in question.

The molecule in question.

Think beyond coffee. “For people that don’t drink caffeine regularly, there are definitely side effects. Elevated heart rate, anxiety, gastrointestinal issues — especially when it’s consumed in coffee, which is really acidic, so it can cause a lot of stomach issues. But it’s mostly just a feeling, nothing serious. They won’t feel good going into their workout,” Arnold said. She added that caffeine pills, when consumed responsibly, are what most studies have shown to be the most effective, and that coffee often doesn’t make sense for high-intensity physical activity: “It’s not often that people drink coffee on rides or runs or in the middle of a game. That’s when the drink mixes and sports gels and things come in handy.” Gu Energy has gels with caffeine, Nuun Sport has tablets and then there’s the runner favorite, Run Gum.

Know your dose. “It’s been shown that three to six milligrams of caffeine per kilogram of body weight is what’s helpful. Anything above nine milligrams per kilogram is not helpful,” Arnold said. As a point of reference, one cup of coffee typically contains 95 milligrams of caffeine. For a 150-pound athlete, this works out to about two milligrams per pound — slightly below a beneficial dose. “A lot of people don’t get nearly as much caffeine as they need per kilogram of their body weight,” says Joe Holder, Nike Master Trainer and founder of Ocho System.

Other forms of caffeine usually pack a bigger punch: most caffeine pills contain 200 milligrams, several extra-strong energy drinks contain close to 300 milligrams and, if you really want to feel like a meth-addled super warrior, certain candies, like the aptly named Crackheads chocolate-covered coffee beans, contain up to 600 milligrams in a single box. High doses are fine, as long as you’re staying below the recommended limit of 9 milligrams per kilogram of body weight. And for maximum effect, remember to space out your caffeine intake throughout the day: “If somebody is considering using caffeine to improve performance or exercise, it’s best to drink less caffeine during daily living, and then consume more of it during the events that we’re focusing on,” Arnold said. Some athletes even go so far as to eschew coffee the week or so before a race so that when they take it on race day, they’re super amped. While that hack hasn’t quite been proven yet, if you find it works for you, that’s all that matters.

Take it at the right time. “The research shows it takes about 45 minutes for the caffeine to hit its peak in your bloodstream. So, if you’re about to start a race, and you need a really big burst of energy — like with the first minute of track running or cyclocross or criterium racing — you’ll want to consume forty-five minutes before you start your event or your workout,” Arnold says. Of course, if a big burst of energy isn’t what you’re looking for, the timing will differ. Arnold continues: “Let’s say your event is an hour long. You might want to consume it at the start, so you’ll have the best benefits of the caffeine at the end of the event. Or you can do both: you can have caffeine forty-five minutes before, and then right before.” For high-endurance events, Arnold suggests taking caffeine in 45-minute intervals to maintain a good buzz throughout. But remember that caffeine affects everyone differently. Experiment to figure out your optimal method of consumption and a comfortable/legal dose, and you’ll have a leg up on the competition — hopefully not a jittery one.

Note: Purchasing products through our links may earn us a portion of the sale, which supports our editorial team’s mission. Learn more here.