We present a mean photon number dependent variational method, which works well in the 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 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 more complex models, for which it is difficult to formulate an analytic formula. by considering the RWA-type interaction in the reformulated Hamiltonian in the displaced oscillator basis. This scheme was named 'generalized RWA' (GRWA). Although the GRWA works well in a quite broad parameter regime, especially in the strong coupling regime, it does not work well in the weak coupling regime, especially for the positive detuning case. In addition, the mean photon number predicted by the GRWA is independent of the frequency of the two-level system, which is actually not true. As an improvement, a generalized variational method (GVM) [31,32] has been introduced, where the displacement of the displaced oscillator basis is determined by minimizing the ground state energy. Indeed, the GVM evidently improves the GRWA in the weak coupling regime with positive detuning, and yields a frequency dependent ground state mean photon number. However, for strong coupling and intermediate coupling regimes, the GVM is no longer applicable. Moreover the GVM is limited to the ground state.Obviously, the merit of the GRWA and the AA comes from the introduction of the displaced oscillator basis, which captures the essential physics in the large coupling regime. However, its disadvantage lies in fixing the displacement, which leads to a frequency independent mean photon number of the obtained ground state. On the contrary, the GVM frees the displacement, but it does not introduce the displaced oscillator basis and has been excessively simplified in the analytic treatment. In the present work, we combine the merits of the GRWA and the GVM to obtain a novel analytic method. We start from the GRWA formula but further introduce a mean photon number dependent variational method to determine the displacement. As a result, our approximation method is applicable in both weak and strong coupling regimes. In the weak coupling regime, it recovers the result of the GVM and in the strong coupling regime it recovers the GRWA. In the intermediate coupling, it provides a natural crossover from the GVM to the GRWA. This variational method is not only valid for the ground state, b...