A numerical method is developed to solve the nonlinear one-dimensional Klein–Gordon equation by using the cubic B-spline collocation method on the uniform mesh points. We solve the problem for both Dirichlet and Neumann boundary conditions. The convergence and stability of the method are proved. The method is applied on some test examples, and the numerical results have been compared with the exact solutions. The L2, L∞ and Root-Mean-Square errors (RMS) in the solutions show the efficiency of the method computationally.