Abstract The generation of walking motions for humanoid robots is a challenging task. From the infinite number of possibilities to move the body of the robot with its redundant degrees of freedom (DOF) forward, the task is to determine those motions that are stable, feasible within the robots kinematic and dynamic limitations, and also resemble the way we expect an anthropomorphic system to walk. Several approaches have been developed and implemented on humanoids in the past years, however most of them require fixing several characteristics of the gait, such as foot placement or step time, in advance, and none has lead to truly human-like walking performance. The purpose of this paper is to show that mathematical trajectory optimization or optimal control can be very helpful to generate walking motions for humanoid robots. We propose a method that uses dynamic model information of the robot as well as efficient optimal control techniques to determine joint trajectories and actuator torques at the same time. Foot placement and step times are also left free for optimization. The method is applied to the humanoid robot HRP-2 with 36 DOF and 30 actuators. Different optimization criteria are evaluated, such as maximization of efficiency, walking speed or postural stability, and a minimization of joint torques or angular amplitudes. ZMP constraints (or alternative stability constraints) can be taken into account in the optimization. The results show that different objective functions and constraints have a considerable influence on the resulting gait.