The Canonical Partition Function

Imagine a mole of gas molecules jostling in a sealed flask held at constant temperature. Each molecule has its own energy ladder. But the system as a whole also has a total energy that fluctuates around some average. The canonical partition function QQ is the single mathematical object that encodes every thermodynamic property of that whole system. This includes pressure, entropy, and heat capacity, as a function of temperature, volume, and the number of particles. This matters because real chemistry happens with vast numbers of interacting or non-interacting molecules. It does not happen with one isolated particle. The molecular partition function qq, met earlier, describes one molecule's accessible states. QQ scales that idea up to NN molecules. It connects microscopic quantum states directly to macroscopic thermodynamics through Boltzmann's entropy formula. This article builds QQ from the Boltzmann distribution over system energy levels. You will see how QQ relates to qq for independent particles. You will work through two full numerical examples. You will also see where the naive Q=qNQ = q^N formula fails. You will learn why that failure matters.

Key takeaways
  • QQ is the sum over all quantum states of an entire NN-particle system, weighted by e−Ei/kBTe^{-E_i/k_BT}.
  • For independent, distinguishable molecules, Q=qNQ = q^N, where qq is the single-molecule partition function.
  • For identical, indistinguishable molecules (most gases), Q=qN/N!Q = q^N/N! to avoid overcounting permuted states.
  • QQ is the bridge between microscopic energy levels and macroscopic thermodynamic functions like UU, SS, and AA.
  • The canonical ensemble fixes NN, VV, TT; QQ is its generating function, analogous to qq for one molecule.
  • Key idea: QQ turns a Boltzmann-weighted sum over the entire system's quantum states into all of equilibrium thermodynamics.
The core insight

The canonical partition function Q(N,V,T)Q(N,V,T) is the Boltzmann-weighted sum over every accessible energy state of an entire NN-molecule system at fixed volume and temperature, and once you have it, every thermodynamic property follows by differentiation — nothing further need be assumed.

The physical picture

Consider a closed system: NN molecules in a container of volume VV, held at temperature TT by contact with a much larger heat bath. This is the canonical ensemble. The system's total energy is not fixed exactly — it fluctuates as heat trickles in and out of contact with the bath — but the distribution of that energy is sharply peaked, governed by the Boltzmann factor e−Ei/kBTe^{-E_i/k_BT} applied not to one molecule's states, but to the entire system's quantum states. Label the possible total-energy eigenstates of the whole assembly i=1,2,3,…i = 1, 2, 3, \ldots, each with energy EiE_i. Many different microscopic arrangements can share the same total energy — that degeneracy is automatically built into the sum. The canonical partition function is defined exactly as qq was, but with system states replacing molecular states: Just as qq tells you how molecular states populate as TT rises, QQ tells you how system configurations populate. When molecules do not interact (ideal gas, no intermolecular forces), the total energy is just a sum of individual molecular energies, and this additivity lets us factor QQ into a product of qq's. When they do interact, that factorization breaks down, and QQ must be computed with the interaction potential included in EiE_i — a much harder problem, central to the statistical mechanics of real fluids. The subtlety that trips up nearly every student is the indistinguishability of identical molecules. If you swap two identical helium atoms, you get the same physical state of the system, not a new one — yet naively multiplying q×q×⋯q\times q\times\cdots counts each permutation as distinct. Correcting for this by dividing by N!N! is one of the most important small corrections in physical chemistry, resolving the historical Gibbs paradox in entropy.

Figure
Boltzmann weighting of system-level states building up Q
Energy Ei System quantum states i = 1, 2, 3 ... E1 E2 E3 weight e^(-E1/kT), largest e^(-Ei/kT) to 0 as Ei grows Q = sum over i of e^(-Ei / kBT)
Figure
Factorization of Q for independent indistinguishable molecules
Molecule A: states, q Molecule B: states, q Molecule N: states, q x ... Naive product: q x q x ... x q = q^N Correct (identical particles): Q = q^N / N!

The core relations

Q=∑ie−Ei/kBTQ = \sum_i e^{-E_i/k_BT}

where: sum runs over all quantum states ii of the entire NN-particle system with energy EiE_i.

Q=qN(distinguishable, non-interacting molecules)Q = q^N \quad \text{(distinguishable, non-interacting molecules)}

where: qq is the single-molecule partition function; valid when molecules are localized (e.g., atoms fixed on lattice sites).

Q=qNN!(indistinguishable, non-interacting molecules, e.g. an ideal gas)Q = \frac{q^N}{N!} \quad \text{(indistinguishable, non-interacting molecules, e.g. an ideal gas)}

where: N!N! corrects for overcounting identical permutations of freely moving, identical molecules.

U−U(0)=−(∂ln⁡Q∂β)V,β=1kBTU - U(0) = -\left(\frac{\partial \ln Q}{\partial \beta}\right)_V, \qquad \beta = \frac{1}{k_BT}

where: U(0)U(0) is the internal energy at T=0T=0; this links QQ to measurable thermodynamic energy.

S=U−U(0)T+kBln⁡QS = \frac{U - U(0)}{T} + k_B \ln Q

where: SS is entropy expressed directly from QQ and its derivative, the Boltzmann-Planck bridge to thermodynamics.

A−A(0)=−kBTln⁡QA - A(0) = -k_BT \ln Q

where: AA is the Helmholtz energy, the natural thermodynamic potential of the canonical (fixed N,V,TN,V,T) ensemble.

Derivation AFrom molecular states to Q = qᴺ/N!

Goal. Show how the system partition function for NN independent, indistinguishable, non-interacting molecules reduces to Q=qN/N!Q = q^N/N!.

Step 1: Write the total energy as a sum over molecules. For non-interacting molecules, the total energy of the system in a given configuration is the sum of individual molecular energies. Label molecule 1 in state with energy εi\varepsilon_{i}, molecule 2 in state with energy εj\varepsilon_j, and so on:

E=εi+εj+εk+⋯E = \varepsilon_i + \varepsilon_j + \varepsilon_k + \cdots

This additivity is the entire physical content of "non-interacting" — there is no cross term coupling one molecule's state to another's.

Step 2: Insert into the definition of Q and factor the exponential. Because the exponential of a sum is a product of exponentials,

Q=∑i,j,k,…e−β(εi+εj+εk+⋯ )=∑i,j,k,…e−βεi e−βεj e−βεk⋯Q = \sum_{i,j,k,\ldots} e^{-\beta(\varepsilon_i+\varepsilon_j+\varepsilon_k+\cdots)} = \sum_{i,j,k,\ldots} e^{-\beta\varepsilon_i}\,e^{-\beta\varepsilon_j}\,e^{-\beta\varepsilon_k}\cdots

The sum over the joint index set (i,j,k,…)(i,j,k,\ldots), with each index ranging independently over all states of its molecule, factors into separate sums:

Q=(∑ie−βεi)(∑je−βεj)(∑ke−βεk)⋯Q = \left(\sum_i e^{-\beta\varepsilon_i}\right)\left(\sum_j e^{-\beta\varepsilon_j}\right)\left(\sum_k e^{-\beta\varepsilon_k}\right)\cdots

Each bracket is exactly the single-molecule partition function qq, so if the molecules were distinguishable (imagine each nailed to a labeled lattice site, so "molecule 1 in state ii" is physically different from "molecule 2 in state ii"), we would get

Qdistinguishable=q1q2q3⋯qN=qNQ_{\text{distinguishable}} = q_1 q_2 q_3 \cdots q_N = q^N

for NN identical molecules sharing the same single-molecule partition function qq.

Step 3: Correct for indistinguishability. For freely translating molecules in a gas, swapping molecule 1 and molecule 2 between their states produces no new physical configuration — there is no label distinguishing "molecule 1 in state ii, molecule 2 in state jj" from "molecule 1 in state jj, molecule 2 in state ii." Yet the product qNq^N counts both terms separately, once for each ordered assignment. For NN molecules distributed over states with negligible multiple occupancy of any single state (true whenever q≫Nq \gg N, i.e., thermal wavelength much smaller than mean spacing — the classical, non-degenerate limit valid for most gases well above their condensation temperature), each distinct physical configuration is counted exactly N!N! times in qNq^N, once for every permutation of which molecule sits in which state.

Step 4: Divide out the overcounting.

Q=qNN!\boxed{Q = \frac{q^N}{N!}}

This is the correction that removes the Gibbs paradox: without it, the entropy of mixing two samples of the same gas would spuriously increase, violating the requirement that entropy be extensive and that mixing identical gases changes nothing measurable.

Worked examples

Example 1 — Q and A for a simple model gas. Suppose a single-molecule partition function has been evaluated (from translational and electronic contributions) to be q=2.50×1026q = 2.50\times10^{26} for N2N_2 gas at T=298 KT = 298\ \text{K} in a 1.00×10−3 m31.00\times10^{-3}\ \text{m}^3 container (a typical order of magnitude for qtransq_{\text{trans}} of a small molecule in a liter-sized box). Take N=6.022×1023N = 6.022\times10^{23} (one mole). Step 1 — apply the indistinguishability correction.

Q=qNN!Q = \frac{q^N}{N!}

Taking logarithms (since QQ itself is astronomically large and unmanageable as a raw number):

ln⁡Q=Nln⁡q−ln⁡N!\ln Q = N\ln q - \ln N!

Using Stirling's approximation, ln⁡N!≈Nln⁡N−N\ln N! \approx N\ln N - N:

ln⁡Q=Nln⁡q−Nln⁡N+N=N(ln⁡q−ln⁡N+1)\ln Q = N\ln q - N\ln N + N = N\left(\ln q - \ln N + 1\right)

Step 2 — plug in numbers.

ln⁡q=ln⁡(2.50×1026)=60.87\ln q = \ln(2.50\times10^{26}) = 60.87
ln⁡N=ln⁡(6.022×1023)=54.94\ln N = \ln(6.022\times10^{23}) = 54.94
ln⁡Q=6.022×1023×(60.87−54.94+1)=6.022×1023×6.93=4.17×1024\ln Q = 6.022\times10^{23}\times(60.87 - 54.94 + 1) = 6.022\times10^{23}\times 6.93 = 4.17\times10^{24}

Step 3 — Helmholtz energy.

A−A(0)=−kBTln⁡QA - A(0) = -k_BT\ln Q
=−(1.381×10−23 J K−1)(298 K)(4.17×1024)= -(1.381\times10^{-23}\ \text{J K}^{-1})(298\ \text{K})(4.17\times10^{24})
=−1.71×104 J=−17.1 kJ= -1.71\times10^4\ \text{J} = -17.1\ \text{kJ}

Sanity check. A−A(0)A - A(0) per mole in the tens of kJ range is entirely reasonable — comparable in magnitude to typical translational contributions to Helmholtz energy for a mole of gas at room temperature, and it is correctly negative (system states overwhelmingly outnumber the ground state, so Q≫1Q\gg1 and ln⁡Q>0\ln Q>0, forcing A<A(0)A<A(0)).

Example 2 — Comparing distinguishable vs. indistinguishable treatments: entropy of a lattice of defects. A crystal contains N=1.00×1020N = 1.00\times10^{20} point defects (vacancies), each of which can sit in any of z=4z = 4 equivalent orientations with equal energy (so each defect's single-particle partition function is q=4q = 4, a purely orientational/configurational qq with no energy weighting since all orientations are degenerate). Because each defect occupies a fixed, distinguishable lattice site, this is the distinguishable case. Step 1 — write Q for distinguishable defects.

Q=qN=41.00×1020Q = q^N = 4^{1.00\times10^{20}}

Step 2 — compute ln Q.

ln⁡Q=Nln⁡q=1.00×1020×ln⁡4=1.00×1020×1.386=1.386×1020\ln Q = N\ln q = 1.00\times10^{20}\times \ln 4 = 1.00\times10^{20}\times1.386 = 1.386\times10^{20}

Step 3 — entropy from Q (energy term vanishes since all orientations are degenerate, so U − U(0) = 0).

S=U−U(0)T+kBln⁡Q=0+kBln⁡QS = \frac{U-U(0)}{T} + k_B\ln Q = 0 + k_B\ln Q
S=(1.381×10−23 J K−1)(1.386×1020)=1.914×10−3 J K−1S = (1.381\times10^{-23}\ \text{J K}^{-1})(1.386\times10^{20}) = 1.914\times10^{-3}\ \text{J K}^{-1}

Step 4 — contrast with the wrong (indistinguishable) treatment. If we mistakenly divided by N!N! as though defects could swap identities between lattice sites,

ln⁡Qwrong=Nln⁡q−ln⁡N!\ln Q_{\text{wrong}} = N\ln q - \ln N!

Using Stirling, ln⁡N!≈Nln⁡N−N=1.00×1020(46.05−1)=4.505×1021\ln N! \approx N\ln N - N = 1.00\times10^{20}(46.05 - 1) = 4.505\times10^{21}, which dwarfs Nln⁡q=1.386×1020N\ln q = 1.386\times10^{20}, giving a large negative ln⁡Qwrong\ln Q_{\text{wrong}} and a nonsensical negative entropy contribution. Sanity check. Defects on fixed, labeled lattice sites are physically distinguishable by position — swapping two defects' orientations between two different sites does create a distinguishable configuration, so the N!N! correction must not be applied here. This example is precisely why the distinguishable/indistinguishable distinction, foreshadowed next, is not a bookkeeping nuance but changes the sign and size of SS dramatically.

Limiting cases & common traps

SituationCorrect treatmentCommon error
Ideal gas, freely translating identical moleculesQ=qN/N!Q = q^N/N!Forgetting N!N!, causing Gibbs paradox in mixing entropy
Atoms/defects fixed on distinguishable lattice sitesQ=qNQ = q^NWrongly dividing by N!N!, understating entropy
Interacting molecules (real gas, liquid, solid vibrations beyond independent oscillators)QQ does not factor as qNq^N; must include full Ei(all coordinates)E_i(\text{all coordinates})Assuming Q=qN/N!Q=q^N/N! always holds
High density or low TT, qq comparable to NN (quantum degeneracy regime)Classical N!N! correction fails; need Fermi-Dirac/Bose-Einstein statisticsApplying Stirling/N!N! correction outside its regime of validity

The chemist behind it

The canonical ensemble formalism is inseparable from Josiah Willard Gibbs, who in his 1902 treatise Elementary Principles in Statistical Mechanics systematically introduced the microcanonical, canonical, and grand canonical ensembles as the organizing framework of statistical mechanics. Gibbs also first recognized — and partially resolved — the paradox that bears his name: the apparent entropy increase on "mixing" two samples of an identical gas, a problem only fully resolved once quantum indistinguishability justified the N!N! correction rigorously. Boltzmann had earlier connected entropy to the number of microstates for isolated systems; Gibbs generalized this to systems in thermal contact with a reservoir, exactly the canonical setting in which QQ lives.

Origins · 1 minJosiah Willard Gibbs and how this was discovered
JW
Josiah Willard Gibbs
1839-1903 · American physicist and chemist who formalized the canonical ensemble and named the Gibbs paradox in statistical mechanics

Ask the tutor: How does the distinguishable-versus-indistinguishable choice change the entropy of mixing two gases, and where exactly does the Gibbs paradox arise?

Why does Q require knowing every quantum state of the whole system, not just one molecule?

Because thermodynamic properties like entropy and Helmholtz energy are properties of the system, not of an individual molecule. The canonical ensemble describes a system in contact with a heat bath, exchanging energy but not particles, so its energy fluctuates and is distributed according to Boltzmann weights over the system's own quantum states. When molecules do not interact, those system states are built from combinations of molecular states, letting QQ be expressed in terms of qq — but conceptually QQ is always defined at the system level first.

Does Q = q^N/N! work for liquids and solids too?

Not directly. That formula assumes the molecules are non-interacting, so total energy is a simple sum of independent molecular energies. In liquids and dense solids, intermolecular forces couple every molecule's energy to its neighbors' positions, so the total energy cannot be split into independent per-molecule terms. Computing QQ for such systems requires more advanced methods, like configurational integrals or simulation techniques, which fall outside the ideal-gas partition function framework.

How is Q related to the Helmholtz energy A, and why A specifically?

The canonical ensemble holds NN, VV, and TT fixed, and the natural thermodynamic potential for those fixed variables is the Helmholtz energy, A=U−TSA = U - TS. The relation A−A(0)=−kBTln⁡QA - A(0) = -k_BT\ln Q falls directly out of combining the Boltzmann-distribution expressions for UU and SS in terms of QQ. Because AA is a natural function of N,V,TN,V,T, and QQ is naturally defined at fixed N,V,TN,V,T, this pairing gives the most direct route from statistical mechanics to macroscopic thermodynamics.

What happens to Q = q^N/N! when q is not much larger than N?

The derivation assumes negligible multiple occupancy of single-molecule states — the classical, non-degenerate limit where q≫Nq \gg N. This holds for ordinary gases at room temperature and typical densities. At very low temperatures or very high densities, quantum statistics (Fermi-Dirac for fermions, Bose-Einstein for bosons) become necessary, since multiple molecules occupying the same low-lying state changes the counting in ways the simple N!N! correction does not capture.

Before this

Where this leads