The analytical solution for steady viscous pressure-driven compressible isothermal gas flow through micro- and nanochannels with variable cross section for all Knudsen and all Mach number values is presented in this paper. The continuum one-dimensional governing equations are solved using the friction factor that is established in a special way to provide solutions for mass flow rate, pressure, and velocity distribution through the microchannels and nanochannels in the entire rarefaction regime. The friction factor, defined by the general boundary condition and generalized diffusion coefficient proposed by Beskok and Karniadakis (1999, “A Model for Flows in Channels, Pipes, and Ducts at Micro and Nano Scales,” J. Microscale Thermophys. Eng., 3, pp. 43–77), spreads the solution application to all rarefaction regimes from continuum to free molecular flow. The correlation between the product of friction factor and Reynolds number (Poiseuille number) and Knudsen number is established explicitly in the paper. Moreover, the obtained solution includes the inertia effect, which allows the application of the solution to both subsonic and supersonic gas flows, which was not shown earlier. The presented solution confirms the existence of the Knudsen minimum in the diverging, converging, and microchannels and nanochannels with constant cross section. The proposed solution is verified by comparison with experimental, analytical, and numerical results available in literature.