We present a mean-photon-number dependent variational method, which works well in whole coupling regime if the photon energy is dominant over the spin-flipping, to evaluate the properties of the Rabi model for both the ground state and the excited states. For the ground state, it is shown that the previous approximate methods, the generalized rotating-wave approximation (only working well in the strong coupling limit) and the generalized variational method (only working well in the weak coupling limit), can be recovered in the corresponding coupling limits. The key point of our method is to tailor the merits of these two existing methods by introducing a mean-photon-number dependent variational parameter. For the excited states,our method yields considerable improvements over the generalized rotating-wave approximation. The variational method proposed could be readily applied to the more complex models, for which an analytic formula is difficult to be formulated.