The analysis of the gait mode is an important step for constructing a walking robot. In this study an optimal turning gait of a four-legged walking robot is proposed, which maximizes walking speed keeping walking stability larger than a certain required value. To obtain an optimal gait algorithm, for body trajectory of the robot, maximum walking speed, feasible gait modes and stability margin are analyzed for a quadruped walking robot designed in this study. The proposed gait is sufficiently flexible, as to permit crab walking, turning walking and a pure rotational walking about a robot's geometric center. The validity of the proposed gait algorithm is confirmed by many simulations.