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 body 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 are its effects 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 on athletic performance. The International Society of Sports Nutrition says caffeine is “very effective” at improving athletic endurance. The Gatorade Sports Science Institute found that ingesting 3-13 milligrams of caffeine, prior to exercise, “often increases performance during prolonged endurance cycling and running,” and in one study in the Journal of Applied Physiology, several athletes who consumed caffeine pills ran an additional 2-3 km than those who drank coffee or consumed no caffeine at all.

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.”

Know your dose. “It’s been shown that three to six milligrams of caffeine per kilogram of bodyweight 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. 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 bodyweight. 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.

Take it at the right time. “The research shows it takes about 45 minutes for the caffeine to hit its peak in your blood stream. 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 said. 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 effects everyone differently. Figure out your preferred method of consumption, a comfortable/legal dose, and you’ll have a leg up on the competition — hopefully not a jittery one.