Bipedal robots by their nature show both hybrid and underactuated system features which are not stable and controllable at every point of joint space. They are only controllable on certain fixed equilibrium points and some trajectories that are periodically stable between these points. Therefore, it is crucial to determine the trajectory in the control of walking robots. However, trajectory optimization causes a heavy computational load. Conventional methods to reduce the computational load weaken the optimization accuracy. As a solution, a variable time interval trajectory optimization method is proposed. In this study, optimization accuracy can be increased without additional computational time. Moreover, a five-link planar biped walking robot is designed, produced, and the dynamic walking is controlled with the proposed method. Finally, cost of transport (CoT) values are calculated and compared with other methods in the literature to reveal the contribution of the study. According to comparisons, the proposed method increases the optimization accuracy and decreases the CoT value.