The **ideal gas law** is , where is the pressure, is the volume, is the number of particles, , and is the temperature. It constitutes one of the simplest and most applied “equations of states” in all of physics, and is (or will become) incredibly familiar to any student of not only physics but also related fields such as chemistry and various engineering disciplines.

Recently, I’ve come to appreciate the ideal gas law as a very good illustrative example of what **statistical mechanics** is capable of. In the eighteenth and nineteenth (during the industrial revolution), the field of thermodynamics arose in pursuit of answers to how much energy can be extracted from systems. At the time, the notion of temperature was hotly debated, with one ostensibly reasonable theory being that the flow of a fluid, called “caloric,” facilitated heat transfer. It should be appreciated just how many important results could be derived by our predecessors without precise knowledge of the microscopic physics involved.

Statistical mechanics arises from a desire to understand how thermodynamics arises from microscopic physics, either classical or quantum. While classical thermodynamics is able to achieve a great deal, it is philosophically difficult to reconcile the microscopic and macroscopic worlds without some statistical framework that can translate the former to the latter. Moreover, it allows us to determine the thermodynamic behavior of new systems that are hard to reason about a priori—how, for example, should we expect the stars in a star cluster to behave? What about a complicated, novel quantum field theory?

* In this article, I will present a number of different derivations of the ideal gas law within the framework of statistical mechanics.* In the process, I hope to motivate the different ensembles of statistical mechanics (which ultimately just encode the behavior of possibly large systems for which only a small amount of bulk information is known). In the process, I hope that an overview of these derivations will be a useful introduction for current physics students (or other interested people) to a notoriously (but arguably needlessly) opaque field.

## A hand-wavy, “kinetic” derivation

Before we proceed with derivations from statistical mechanics, I think that there is utility in understanding at a heuristic and intuitive level what is being stated by the ideal gas law. An ideal gas is a simplified model which models a gas as a collection of very small, collisionless particles which exert forces on the sides of a container (e.g., a box) whenever they collide with them. The **pressure** is a reflection of this force, and is (by definition) force per unit area. This can go up if (1) the number of particles per unit volume is increased (so that more particles are around to hit the sides of the box), or if (2) the typical velocities (read: temperature) of the particles are increased (so that each collision of a particle with the sides of the box imparts more momentum on average).

We can start by saying that the pressure can also be thought of as the normal momentum flux, or the amount of momentum perpendicular to the sides of the box which moves through a surface per unit area (this is equivalent to the force per unit area, since force is momentum per time). We can write

For particles with mass , we can write

At a temperature , the typical kinetic energy of a particle is (up to numerical constants). This means that , and, substituting, we have

or

In fact, this approximate expression is actually exact, and kinetic theory can be used to show that the numerical factor that ultimately ends up in front is . Remarkably, the law does not depend on the mass of the particles (which cancels out of the equation)—simple measurements of these bulk quantities is not sufficient to find out what the masses of the particles in a gas are, and somehow, at least through these bulk equilibrium quantities, the gas does not appear to care what the particle mass is.

## How to think about statistical mechanics

Statistical mechanics (as mentioned above) is a formalism for transforming microscopic physical laws into thermodynamics. Classical thermodynamics, in turn, is based on the determination of so-called **thermodynamic potentials**, of which the most famous is **energy** . An infinitesimal change of energy is related to changes in other quantities , volume , and particle number as

where is the chemical potential, and is the amount of energy needed to add an additional particle to the system. This is commonly called the **first law of thermodynamics** (and is a restatement of the conservation of energy).

Another is the **entropy** , which curiously was already understood to be an extensive quantity on the basis of thermodynamic arguments alone. An infinitesimal change in the entropy can be seen from the above to be

The other “thermodynamic potentials” are obtained by performing a mathematical operation called a “Legendre transform,” whose interpretation is very neat and summarized well here. For example, we can define the **Helmholtz free energy** as . While this definition doesn’t seem very motivated at first, we can see upon finding why we have done this:

We see in the differential that the effect of subtracting from the energy was to “switch around” and within , with the necessary addition of a minus sign. Similarly, we can define other thermodynamic potentials which are useful in different contexts:

(**enthalpy**)

(**Gibbs free energy**)

(**grand potential**)

The differential quantities which naturally appear in the above expressions should be interpreted as the “natural” quantities of the potential. While that seems a bit hand-wavy, I mean that, for example, if you were doing an experiment where you had control over the temperature, pressure, and particle number (as chemists often do), it would probably be most useful for you to reason about your system through the Gibbs free energy, where , , and appear.

Moreover (and relatedly), the knowledge of any of these potentials as a function of their natural variables will encode all the macroscopic thermodynamical quantities. For example, if we had knowledge of the energy function , then we could use the multivariate chain rule to write

where subscripts indicate that a partial derivative is being taken with the subscripted variables fixed (for example, is the volume derivative of the energy where entropy and particle number are held fixed). At the same time, since we know that , we can identify the coefficients , , and with each other to find

Hence, by taking derivatives of our known energy function , we can easily find the temperature , pressure , and chemical potential as a function of , , and . This framework can be generalized to other systems. For example, for a one-dimensional problem (e.g., rubber band), we may instead write

whereby . For a more extreme example, one can consult Wikipedia and write for a black hole

where is its surface gravity, is its surface area, is its angular velocity (of rotation), is its angular momentum, is its electrostatic potential, and is its charge. By analogy, it can be seen exactly what sense in which Stephen Hawking meant that the entropy of a black hole scales with its area, and that its temperature scales with surface gravity.

As a fun aside, it turns out that performing a Legendre transform with respect to all particles in a system is “not allowed” in the sense that it will actually cause the quantity to vanish entirely:

This result is called the **Gibbs-Duhem relation**.

### Fantastic ensembles and where to find them

Heuristically, most, if not all, equilibrium statistical mechanics problems go as follows: we count the number of microscopic states (“microstates”) which are compatible with a given macroscopic state, and then straightforwardly translate that result into a thermodynamic potential which is most natural to that system. Upon obtaining that thermodynamic potential, we can then use rules from classical thermodynamics to find out any thermodynamical quantity about our system that we want.

A fundamental assumption of statistical mechanics is the **principle of indifference**, a (sometimes debated) postulate that two microscopic configurations of a system which have the same total energy will be equally probable. A shuffled deck of cards is unlikely to be in order, not because any given shuffled deck is more likely than an ordered deck, but rather because there are many more ways for the shuffled deck to be out of order. From this perspective, it is a little bit clearer why solving problems in this field almost always involves counting states, sometimes weighted by some quantity to account for coupling to a heat or particle bath.

Statistical mechanics reasons about **ensembles**, which can be thought of as probability distributions over a given system where certain macroscopic quantities are known (possibly including, for example, the temperature). Alternatively, they can be thought of as a large collection of macroscopically (but not necessarily microscopically) identical systems. The sense in which the systems are macroscopically identical depends on which type of ensemble is being used (i.e., which macroscopic quantities are shared in common between the systems which makes them “macroscopically identical”).

However, an important fact must be stated: * for systems with very many particles, the ensembles ought to agree.* On a macroscopic level, an isolated system ought to behave identically to the same system which is in contact with a heat bath of the same temperature. Even though, strictly speaking, the latter is coupled to another system and the former is not, the lack of heat flow means that the systems should be macroscopically indistinguishable. The same goes for a particle bath with the same chemical potential as the system.

I will briefly summarize below the three most common statistical ensembles which are introduced in usual courses on statistical mechanics (although this is not an exhaustive list of all ensembles which could exist). There are some very common tricks to doing problems in all of the ensembles, some of which I will also describe below. The ultimate hope is that the way to utilize those tricks will become clear in the concrete example of an ideal gas.

### Microcanonical Ensemble

In the **microcanonical ensemble**, we know a system’s total energy , its volume , and the number of particles within it. As these can be considered the “natural variables” of the ensemble, the “natural potential” of the microcanonical ensemble is the *entropy* .

In such problems, we will seek to count the total number of states with energy of exactly or, if in a classical problem where the space of such states is measure zero, with energy within the interval (i.e., very close to ). In other words, in the case of a discrete number of states, we would like to find

where

In the case of continuous states, for example of particles in three dimensions, we would like to integrate over phase space (noting that the “phase space volume” of a single state is for canonical coordinates):

where is the Dirac delta distribution and is the Hamiltonian (in many usual cases, the energy function). While this seems like a disgusting integral, the interpretation is that we want to pick out of our phase space only those states which have energy , which in all cases I can think of is a -dimensional surface in phase space. The “integral” in many problems is done geometrically, if it can be done at all. In many cases, it is more straightforward to find the number of states with energy (rather than ), or

\noindent where is the Heaviside step function. Then we can find by differentiating :

After finding (the microscopic, “counting” part of statistical mechanics), we simply translate to the thermodynamic potential (entropy) using the definition of entropy:

and from here can use classical thermodynamics to find out everything else.

### Canonical Ensemble

In the **canonical ensemble**, we again know the system’s volume and (as in the microcanonical ensemble), but instead of knowing the total energy of the system, we only know the average energy per particle (which, for fixed underlying physics, is equivalent to knowing ). The temperature is often written using the variable . This has the interpretation of a system being in contact with a **heat bath** of temperature .

Again, we are required to count the number of states, but this time with higher energy states being exponentially down-weighted (see, e.g., here for a satisfying derivation from Lagrange multipliers). In the discrete case, we have

This time, the sum (the **partition function**) appears to be very similar to the sum in the microcanonical ensemble, but with weights (**Boltzmann factors**) rather than . Similarly, in the continuous (three-dimensional) case, we have

Note that, if the system comprises many particles with identical behaviors whose energies sum together, i.e., (discrete), or , then the sum/integral decouple, and we often have

where is the partition function of only a single such particle.

Because the natural variables for this ensemble are now , , and , the natural potential for the ensemble is , which can be found via

Again, after obtaining , we are home free, and, by means of taking derivatives, can proceed to find out everything of (equilibrium) thermodynamic relevance in our system.

To reiterate, even though in this case the total energy of the system is not precisely fixed, it will only experience small fluctuations about its expectation value in the case of a realistically large system.

### Grand Canonical Ensemble

In the **grand canonical ensemble**, we know the average energy per particle as well as the system volume (as in the canonical ensemble), but now, in place of knowing the total particle number precisely, we instead know the average particle number (equivalent to knowing ). This ensemble has the interpretation of dealing with a system which is in contact with both a heat bath of temperature as well as a **particle bath** with chemical potential .

Counting the states this time requires computation of the so-called **grand canonical partition function** , which in the discrete case takes the form

where the Boltzmann factors have been replaced with the aesthetically similar **Gibbs factors** . In the continuous case, we not only integrate over phase space but sum over all possible particle numbers:

In both cases, we can factor out of the energy sum/integral, and recognize the remaining summand/integrand as the canonical partition function at for the system at a given particle number :

Hence, if the canonical problem has already been solved, it is often not too difficult at least in principle to extend it to the grand canonical case.

The natural variables , , and now imply that the natural potential is the grand potential , given by

in a similar manner to given the the canonical partition function in the canonical ensemble.

Once again, even though a particle bath is only involved here, in realistically large systems the total particle number will only experience small fluctuations about its large expectation value, determined by .

## Deriving the ideal gas law in the classical (continuous) case

Since all the ensembles should yield the same results in macroscopically large systems, all three ensembles described above can be used to derive the ideal gas law (although not necessarily with the same ease).

Furthermore, we can approach this problem both from classical (continuous) physics (which involves integrating over phase space) or take the high temperature limit of the quantum (discrete) case (which involves summing over states). Both of these approaches should, again, give the same answer as they should converge to the same physics at the regimes that we care about.

### Microcanonical Ensemble: Classical Case

We will seek to find the number of states with total energy . This process is made easier if we first instead find the number of states with total energy *less than* :

Since the positions play no part in the energy of a particle within an ideal gas, the integrals are easy and factor out as since the integrand doesn’t depend on them. We have then taken care of half of the integrals and are then reassuringly left with

We may be tempted to evaluate the integral above by hand, but that would probably result in many empty boxes of chalk filled with tears.

Instead, we can find the number of states geometrically, by noting that the Hamiltonian (energy) for such a system is simply the sum of the kinetic energies:

The hypersurface can be written as

which looks awfully similar to the formula for a sphere (cf. ). In fact, this is an -dimensional sphere with radius , where typically particles (the -dimensional hypersphere concept was memed into oblivion in Berkeley’s statistical mechanics course the year before I took it; our semester was less fun and we instead spent our time being lame and doing problem sets and stuff).

Nevertheless, we trust that mathematicians have taken care of this problem, and indeed a quick look at Wikipedia reveals that a -dimensional hypersphere with radius has a hypervolume

where and is the gamma function, as nature intended. We can use this formula to evaluate the momentum integrals, which yields

Then we can find by differentiating

This can then be translated into an entropy which, using the rules for logarithms, cleans up immensely:

where is a hideous function of which, fortunately, we do not need to worry about so long as it turns out that all of our partial derivatives from now on are taken with fixed. Note that, since , this is practically

Then we can write

We can then find the pressure by identifying

which yields the ideal gas law:

### Canonical Ensemble: Classical Case

We saw that one difficulty with the microcanonical ensemble was that the integrals were too hard to do algebraically (at least, if the goal is to still want to be alive afterwards). The fundamental issue is that, when we fix the total energy of the system , we force the energy of any given particle to depend on all the others. For example, if particle turns out to be hogging most of the energy, then the rest of the particles must necessarily have much less energy, and the integrals are coupled accordingly.

In contrast, if we take the canonical approach of only fixing the *average* particle energy , we no longer have this issue, since particle hogging all the energy does not at all affect the values of energy allowed for the other particles (which still hovers around ). We will expect (and will come to see) that the integrals will decouple appropriately.

We can compute the partition function which is analogous to state counting once again:

Again, since the energy of the gas does not depend on the location of the particles but only their momenta, we can quickly evaluate the position integrals:

where we have substituted in the Hamiltonian for an ideal gas. Notably, the exponential can be broken up as follows:

We see that each factor in the integrand only depends on one component of one particle’s momentum, so we can pull each factor out of all the integrals that don’t depend on it, and we will obtain

We can recognize this as copies of the same (Gaussian) integral:

If we had been clever from the start, we could have recognized that, in fact, the total partition function from the start could be decoupled into identical smaller partition functions:

where , the partition function for just one of these identical particles, is simply given by

Anyway, we can now translate to the macroscopic picture by deriving the Helmholtz free energy:

We can then write

Aiming for the pressure once again, we can identify

which, once again, leads to the ideal gas law:

### Grand Canonical Ensemble: Classical Case

If we insisted in allowing the particle number to vary, we could, in fact, verify that we would achieve the same ideal gas law even if, say, the system were coupled to a large particle bath. We can work in the grand canonical ensemble, where now rather than knowing we instead know the average number of particles (parameterized by ).

We now start by performing the relevant “state counting,” which in this case involves deriving the grand canonical partition function:

We recognize that the integral has a factor which is constant with respect to the integration variables, and so we can factor it out:

Before doing literally anything else (even the trivial volume integrals), we can step back and recognize that the integral within the sum over is oddly familiar. In fact, the canonical partition function at a fixed number appears in the sum. Conveniently, we already know what this is, and can substitute accordingly:

Noting that everything in the summand is exponentiated to the th power,

we recognize that the grand canonical partition function is, in fact, a geometric series:

We can then relate this to the “natural potential,” in this case the grand potential , as

We note that

We can again identify via

This is ostensibly a very ugly formula, for which we are required to eliminate in favor of . Regrettably, this can be done with the further identification

We see that the mess

appears in our expression for , which yields

where, again, we find the ideal gas law.

## Deriving the ideal gas law in the quantum (discrete) case

Quantum mechanics devolves to classical mechanics in the macroscopic limit—Ehrenfest’s theorem is that the expectation values of quantum mechanics will follow the usual classical equations of motion. Thus, we should not be particularly surprised that we can also derive the ideal gas law from a quantum mechanical perspective, with states now being discrete rather than part of a continuous phase space.

However, curiously, from a quantum mechanical perspective, the usual **Boltzmann distribution** is actually only a high temperature limit of the **Fermi-Dirac** or **Bose-Einstein distributions**, and does not arise on its own from any natural-looking partition function. In the Fermi-Dirac distribution (which describes fermions), two particles cannot share the same state. In the Bose-Einstein distribution (which describes bosons), they assuredly can (and, compared to the classical picture, are more zealous to do so particularly at low temperatures).

In the following derivations, I will be considering bosons, since counting states while also excluding those where multiple particles share a given state is somewhat more complicated. *I will only perform the derivation up to the point where the mathematics becomes identical to the classical case, which must occur at some point for the physics that occurs to be identical.*

This section will use some basic facts from quantum mechanics, in particular that the energy of a particle in an infinite square well with dimensions , , and is

where the wavenumbers , , and can only take discrete values

where .

### Microcanonical Ensemble: Quantum Case

We would like to count all of the states where this energy is equal to the numerical value :

As in the continuous case, we may instead consider all the states with energy :

where is, again, the Heaviside step function. Ironically, the next step involves approximating the sum as an integral, in the limit where the states are very close together—this step makes it much more plausible that the classical and quantum procedures will ultimately end up giving the same answer.

The total energy of the system can be written as

which can again be rearranged into the equation for a -dimensional sphere:

In the single particle -space, we can work out that the “volume” of a single state is given by incrementing , , and , and find that it is (the volume of the box is )—a state in the total -space involving all particles thus has volume . We can use the hypersphere hypervolume formula to perform the sum:

where the factor of arises because we only consider positive values of (for example, in the case of two dimensions, we only integrate over the sphere in a single quadrant). In fact, simplifying a bit, we have

which is exactly the same as the classical result. The rest of the analysis is identical to the classical microcanonical derivation, which can be found above.

One important note is that, in this case, the phase space volume of a state being arises naturally from counting quantum states, whereas this result was put in by hand in the classical case. Fortuitously, in the classical derivation, we would have been able to derive the ideal gas law taking *any* normalization for the phase space, and the only quantity that would be affected would be the chemical potential (since it involves an integral with respect to ).

### Canonical Ensemble: Quantum Case

In the canonical ensemble, we would like to compute the partition function , this time making explicit use of the decoupling of particles that comes with knowing rather than :

where

We see that the sum in breaks up into the product of three smaller, nearly identical sums:

The summands are Gaussians in whose width is , and the sums are adequately approximated as Gaussian integrals so long as , which is true if the temperature is macroscopically large. Then we must perform an integral over half of a Gaussian:

which evaluates to

This can be rewritten as

and the steps that follow are identical to the classical case.

### Grand Canonical Ensemble: Quantum Case

In the grand canonical ensemble, we use the trick that we can decompose the grand canonical partition function into the sum of canonical partition functions at fixed :

However, because we have already found that the quantum mechanical canonical partition function is identical to the classical version, the quantum version of must be identical to its classical version as well, and hence by this point have already achieved the exact same result as in the classical case.

## Summary

Equilibrium statistical mechanics comprises a set of tools for converting microscopic physics into macroscopic physics, in the absence of *most* of the information which describes the state of the system. When I first learned statistical mechanics, these tools seemed to be very ad hoc and disjoint from each other, but they fit together into an elegant, (debatably) coherent framework. When I now think about statistical mechanics, I have the following table in mind:

Ensemble | Counting states (microscopic) | Potential (macroscopic) |

Microcanonical | Entropy () | |

Canonical | Helmholtz free energy () | |

Grand Canonical | Grand potential () |

When keeping in mind that the ultimate purpose here is to try to convert microscopic physics into macroscopic physics, we can learn insightful facts about the behavior of large systems, such as the ideal gas law, which can be found using any number of the tools presented in a typical undergraduate statistical mechanics course.

All roads lead to Rome.