Legged locomotion requires the determination of a number of parameters such as stride period, stride length, order of leg movements, leg trajectory, etc. How are these parameters determined? It has been reported that the locomotor patterns of many legged animals exhibit common characteristics, which suggests that there exists a basic strategy for legged locomotion. In this study we derive an equation to estimate the cost of transport for legged locomotion and examine a criterion of the minimization of the transport cost as a candidate of the strategy. The obtained optimal locomotor pattern that minimizes the cost suitably represents many characteristics of the pattern observed in legged animals. This suggests that the locomotor pattern of legged animals is well optimized with regard to the energetic cost. The result also suggests that the existence of specific gait patterns and the phase transition between them could be the result due to optimization; they are induced by the change in the distribution of ground reaction forces for each leg during locomotion.