A simple model predicts the energy cost of bipedal locomotion for given speed, stride length, duty factor and shape factor. (The duty factor is the fraction of stride duration, for which a foot is on the ground, and the shape factor describes the pattern of force exerted on the ground). The parameters are varied to find the gait that minimizes metabolic energy cost, for each speed. A previous model by Alexander calculated the work that muscles have to do, but the metabolic cost (calculated in this paper) is more likely to be the principal criterion for gait selection. This model gives good predictions of human stride lengths, and of the speed at which we break into a run. It predicts lower duty factors and higher shape factors than are normally used, but the relationships between these gait parameters and speed parallel the empirical relationships.