Almaz Ayana won the gold medal in the women’s 10,000 meters at the Summer Olympics on Friday with a blistering pace that obliterated the previous world best to set a new world record — 29:17.45. When Mo Farah took home the gold in the men’s 10,000 meters the next day in Rio de Janeiro, his finishing time of 27:05.17 was about 48 seconds off the world record of 26:17.53, set in 2005 by Ethiopian Kenenisa Bekele, and nearly 20 seconds slower than his own personal record.

The two races showcased two different styles of pacing. The women’s race saw fairly even pacing, with an aggressive upping of the pace by Ayana in the middle that set her on track for the world record. The men’s race, by contrast, began rather leisurely, with surges and slowdowns (including for Farah, who stumbled and fell to the track near the 4K mark), before the leaders and eventual winner increased the pace in the last 2,000 meters.

In theory, pacing should be straightforward, whether you’re running 400 meters or 26.2 miles. You pick your optimal pace for the distance and then stick to that tempo to run your fastest time and attain the best result possible. But in practice, pacing can become far more strategic and complicated. “Pacing is just a budgeting decision about how you’re going to allocate your resources so that you don’t spend them before the finish, but you don’t also leave some in store for after the finish,” said Ross Tucker, an exercise scientist at the School of Medicine of the University of the Free State in South Africa and co-founder of the blog The Science of Sport.

If the goal is the best possible time, Tucker’s work analyzing pacing in world-record-breaking races has shown that the optimal strategy for races longer than 800 meters is to run a fast, even pace with each lap the same speed until the final kick. (Ayana’s mostly even record-breaking pace came with a fast surge at about the halfway point. “There are few athletes who would be able to expend that energy mid-race and hold on so well,” Tucker said.) In events of 800 meters or less, the best times generally come from a gradual, progressive slowing where the first lap is faster than the second, and so on.

For instance, Wayde van Niekerk just won a gold medal and broke Michael Johnson’s 17-year-old world record in the 400 meters by slicing time off of the first 200 meters. His final 200 meters were slower than the same section of Johnson’s record run.

Even a race as short as the 400 meters involves pacing. The runners are not going “flat out” all the time, Tucker said. These decisions and adjustments seem to be a mix of conscious and subconscious pacing, based on physiological and anticipatory factors.

A runner may come to a race with a pacing plan in mind, but it’s easy to get caught up in the moves made by rivals. Olympic races have high stakes and spoils that go to just the top three finishers, and as a result, the pacing tends to be especially strategic. It’s the Olympics, after all. The difference in glory between first and fifth place is enormous, so a lot of people are looking for a “Hail Mary,” Tucker said. If you’re a runner in that 10,000-meter race with Farah, you know that with his killer kick, your best chance of beating him for the gold is to wear him down with some surges. Indeed, Ethiopians Tamirat Tola and Yigrem Demelash were at the front of the pack, setting the pace, when Farah took his tumble, but ultimately Farah’s end spurt was unbeatable.

It’s not so unusual for Olympic distance races to come down to the final stretch. In a study published in 2012, Jos J. de Koning, an exercise researcher at VU University Amsterdam in the Netherlands, and his colleagues analyzed the split times from track events ranging from 800 meters to 10,000 meters at the 2008 Olympic Games in Beijing. The numbers showed that in races of 1,500 meters and longer, the finals were won in the end spurt, with competitors’ peak speed coming during the final lap. Top contenders in the men’s and women’s 10K ran at a “continuously high speed.” The men’s 5K race saw the top racers stage a “breakaway” at the 3K mark, while the women’s 5K was characterized by a gradual increase in speed and a long end spurt. Being able to handle pacing changes appeared important for winning. The Olympic finalists in the study seemed to tolerate running the first kilometer of a race as much as 8 percent faster than their mean pace without becoming so fatigued that they couldn’t finish.

How do runners decide whether they can keep up a given pace? De Koning’s group has proposed what it calls a “hazard score” formula to calculate the likelihood that an athlete will slow down or speed up at any given time. The hazard score takes into account the momentary rating of perceived exertion, or RPE — a subjective rating of how difficult an exercise bout feels — and the fraction of the race that remains. Essentially, what the model says is that an athlete regulates exertion based on the sensations of fatigue or effort experienced in the moment as well as the time or distance left in the competition.

In one study, de Koning’s team had volunteers perform three cycling time trials in the lab. Participants were told they’d be performing a 10K, a 15K and, finally, another 10K. However, at the 7.5K point in the final trial, the instructions changed. “We told them, ‘Sorry, today it’s not 10K, it’s 15K,’” de Koning said in a presentation at the American College of Sports Medicine meeting in June. “Luckily they had masks on their faces so they couldn’t say anything to me.” Once told that they’d be going farther, the cyclists slowed their pace, and their RPEs — their perception of how hard the exercise bout felt — changed. For the first 7K, when they thought they were doing 10K, participants reported RPEs that were similar to what they’d reported at that point during their first 10K time trial, but when they were told that they’d be continuing for five additional kilometers, their RPEs switched to the pattern they’d reported in the previous 15K trial.

The implication is that how athletes feel at any given time isn’t just dependent on the objective effort they’re putting out, but also is a calculation of the demands yet to come. It’s akin to being on a tight financial budget where how broke or flush you feel doesn’t depend just on the money you have in the bank, but also on the bills you’re expecting before the next paycheck.

In a longer race like the 26.2-mile (42.2-kilometer) marathon, those impending bills may be external factors such as heat, humidity and a blazing sun. As in other long races, Tucker said, the ideal pacing strategy for a marathon is even splits, with each mile run at a similar pace. But at Rio, where the temperature at the start of the women’s race Sunday was already an uncomfortably warm 70 degrees Fahrenheit, many runners may have adopted more strategic pacing.

In the women’s marathon, the lead group ran the first 5K at a relatively steady 17:24 pace, but then they came through the second 5K at 16:59. From there, the pace of the lead group and eventual winner bumped around, with an acceleration at about the halfway mark leading to a split in the front group. As this chart shows, the runners at the front then continued to surge and slow. American Desiree Linden, by contrast, appeared to be running her own race. “She made some small pace changes, the kind you usually have because we are not robots. But for the most part, she was running even effort,” Tucker said.

Yet steady pacing is not what TV viewers saw. Instead, they watched her go off the back of the lead pack or up to the front. “The commentators kept saying it was a bad patch, or surprising tactics that she’d surge to the front, but she wasn’t — she was the barometer for even pace, and everyone else was surging, then slowing, then surging, then slowing, and she was going back and forward, back and forward accordingly,” Tucker said. These surges were too micro to really show in the 5K split times, Tucker said, but “there’s a lot going on at a micro level.” This coming Sunday, we’ll see how evenly or unevenly the men pace their Olympic marathon. There may not be a record set, but with medals at stake, we’re likely to see another exciting race.

We’re on the ground in Rio covering the 2016 Summer Olympics. Check out all our coverage here.