In this Letter, we present a reliable algorithm of the homotopy perturbation method to the nonlinear Klein-Gordon equations. The algorithm provides analytical approximations for different types of the Klein-Gordon equations. The proposed framework overcomes the difficulty that arising in calculating complicated integrals using the homotopy perturbation method. Some numerical illustrations are given to show the efficiency of the algorithm. © 2007 Elsevier B.V. All rights reserved.