The ideal gas law can also be derived from first principles using the kinetic theory of gases, in which several simplifying assumptions are made, chief among which are that the molecules, or atoms, of the gas are point masses, possessing mass but no significant volume, and undergo only elastic collisions with each other and the sides of the container in which both linear momentum and kinetic energy are conserved.
First we show that the fundamental assumptions of the kinetic theory of gases imply that
Consider a container in the  Cartesian coordinate system. For simplicity, we assume that a third of the molecules moves parallel to the -axis, a third moves parallel to the -axis and a third moves parallel to the -axis. Next we temporarily assume that all molecules with the same velocity . We choose an area  on a wall of the container, perpendicular to the -axis. When time  elapses, all molecules in the volume  moving in the positive direction of the -axis will hit the area. There are  molecules in a part of volume  of the container, but only one sixth (i.e. a half of a third) of them moves in the positive direction of the -axis. Therefore, the number of molecules  that will hit the area  when the time  elapses is .
When a molecule bounces off the wall of the container, it changes its momentum  to . Hence the magnitude of change of the momentum of one molecule is . The magnitude of the change of momentum of all molecules that bounce off the area  when time  elapses is then . From  and  we get
We supposed that all molecules move with the same velocity , but in fact they move with different velocities, so we replace  in the equation by the arithmetic mean of all squares of all velocities of the molecules, i.e. by  Therefore
which gives the desired formula.
Using the Maxwell–Boltzmann distribution, the fraction of molecules that have a speed in the range  to  is , where
and  denotes the Boltzmann constant. The root-mean-square speed can be calculated by
Using the integration formula
it follows that
from which we get the ideal gas law: