Many quadrupedal mammals transition from a four-beat walk to a two-beat run (e.g. trot), but some transition to a four-beat run (e.g. amble). Recent analysis shows that a two-beat run minimizes work only for animals with a small pitch moment of inertia (MOI), though empirical MOI were not reported. It was also unclear whether MOI affects gait energetics at slow speeds. Here, I show that a particular normalization of the pitch moment of inertia (the Murphy number) has opposite effects on walking and running energetics. During walking, simultaneous forelimb and hindlimb contacts dampen pitching energy, favouring a four-beat gait that can distribute expensive transfer of support. However, the required pitching of a four-beat walk becomes more expensive as Murphy number increases. Using trajectory optimization of a simple model, I show that both the walking and slow running strategies used by dogs, horses, giraffes and elephants can be explained by work optimization under their specific Murphy numbers. Rotational dynamics have been largely ignored in quadrupedal locomotion, but appear to be a central factor in gait selection.