Partition Function Calculator

Find the canonical partition function Z, occupation probabilities, and average energy for a discrete-energy-level system using Boltzmann statistics.

📊 Partition Function Calculator
Temperature (T)300 K
K
10 K2000 K

Energy levels (up to 4). Set a level's degeneracy to 0 to disable it.

Partition function (Z)
Average energy ⟨E⟩
kBT
Step-by-step working
Occupation probabilities

📊 What is the Partition Function Calculator?

This partition function calculator finds the canonical partition function Z, the occupation probability of each level, and the average energy of a discrete-energy-level system using Boltzmann statistics. Enter a temperature and up to 4 energy levels (each with an energy and a degeneracy), and it computes Z = sum of gi*exp(-Ei/kBT) along with everything derived from it.

The partition function is a foundational quantity in statistical mechanics. It is not just a number, it is the normalization constant of the Boltzmann distribution, and essentially every macroscopic thermodynamic quantity (average energy, entropy, Helmholtz free energy, heat capacity) can be derived from Z and its derivatives with respect to temperature. Physical chemistry, condensed matter physics, and spectroscopy all use partition-function reasoning to connect microscopic energy levels to macroscopic, measurable behavior.

Set any unused level's degeneracy to 0 to exclude it, this lets you model a simple 2-level spin or electronic system, or build up to a full 4-level system, using the same input rows. Energies are entered relative to the ground state, so the lowest level is normally set to E=0 eV.

This calculator is useful for physical chemistry and statistical mechanics students verifying homework calculations, and for physicists doing quick order-of-magnitude checks on level populations before a more detailed numerical treatment.

📐 Formula

Z  =  ∑i gi·exp(−Ei / kBT)
gi = degeneracy of level i, Ei = energy of level i (eV)
kB = 8.617333262×10−5 eV/K (Boltzmann constant in eV/K), T = absolute temperature (K)
Occupation probability: pi = gi·exp(−Ei/kBT) / Z
Average energy: ⟨E⟩ = ∑i pi·Ei
Example: E1=0 eV, E2=0.1 eV (both g=1), T=300 K: Z ≈ 1.020897, p2 ≈ 2.0469%.

📖 How to Use This Calculator

Steps

1
Set the temperature - Enter or slide to the temperature T in Kelvin.
2
Enter the energy levels - For each level, enter its energy Ei in eV and degeneracy gi. Set g=0 to disable an unused level.
3
Read the partition function results - See Z, the occupation probability of each active level, and the average energy.

💡 Example Calculations

Example 1 - Two-level system at room temperature

1
E1=0 eV, g1=1 (ground state); E2=0.1 eV, g2=1 (excited state); T=300 K
2
kBT = 8.617333262×10−5 × 300 = 0.025852 eV
3
Z = 1×exp(0) + 1×exp(−0.1/0.025852) = 1 + 0.020897 = 1.020897
4
p1 = 97.9531%, p2 = 2.0469%, ⟨E⟩ = 0.0020469 eV (2.0469 meV)
Z = 1.020897, p2 = 2.0469%
Try this example →

Example 2 - Same levels, much higher temperature

1
Same levels as Example 1 (E1=0, E2=0.1 eV, both g=1), but T=2000 K
2
kBT = 8.617333262×10−5 × 2000 = 0.172347 eV, now much larger than the 0.1 eV gap
3
Z = 1 + exp(−0.1/0.172347) = 1 + 0.559772 = 1.559772
4
p1 = 64.1119%, p2 = 35.8881%, much closer together than at 300 K, approaching the 1:1 degeneracy ratio
Z = 1.559772, p2 = 35.8881%
Try this example →

❓ Frequently Asked Questions

What is the partition function?+
The partition function Z is a normalization sum over all accessible microstates of a system, weighted by their Boltzmann factors exp(-Ei/kBT). It might look like a bookkeeping quantity, but essentially every thermodynamic property of the system (average energy, entropy, free energy, heat capacity) can be derived from Z and its derivatives with respect to temperature.
What is the formula for the canonical partition function?+
Z = sum over i of gi * exp(-Ei / (kB*T)), where gi is the degeneracy (number of distinct states) at energy level Ei, kB is the Boltzmann constant, and T is the absolute temperature. Once Z is known, the occupation probability of level i is pi = gi*exp(-Ei/kBT) / Z.
Why are lower-energy states always more populated at finite temperature?+
Because the Boltzmann factor exp(-Ei/kBT) decreases as Ei increases, for any finite positive temperature. A lower Ei always produces a larger Boltzmann factor than a higher Ei, so states are exponentially weighted toward the ground state, this is the Boltzmann distribution, and it is why the ground state (or lowest-energy accessible level) always has the highest occupation probability.
What happens to the populations as T approaches 0?+
As T to 0, kBT to 0, so exp(-Ei/kBT) vanishes for every level except the ground state (Ei=0), whose factor stays exactly 1. In this limit only the ground state is populated (p1 to 1, all others to 0), the system freezes entirely into its lowest-energy configuration.
What happens to the populations as T approaches infinity?+
As T to infinity, kBT becomes much larger than every energy gap, so exp(-Ei/kBT) to 1 for every level regardless of Ei. The occupation probabilities then approach the ratio of degeneracies alone, pi to gi / (sum of all gj), completely independent of the energy differences between levels.
What is kBT at room temperature?+
At T=300 K, kBT = 8.617333262e-5 eV/K x 300 K is approximately 0.02585 eV, or about 25.85 meV. This is a widely used reference figure in condensed matter and semiconductor physics: any energy gap much larger than roughly 25.85 meV is only weakly populated at room temperature, while gaps much smaller than that are close to equally populated.
How do I model a system with only 2 energy levels?+
Enter your ground state as Level 1 (E1=0, g1 as needed) and your excited state as Level 2, then set the degeneracy of Level 3 and Level 4 to 0. A degeneracy of 0 removes a level from the sum entirely, so it contributes nothing to Z, the occupation probabilities, or the average energy.
What does the average energy result represent?+
The average energy avgE = sum over i of pi*Ei is the thermally averaged energy of the system at temperature T, weighting each level's energy by how likely the system is to occupy it. It rises from 0 (all population in the E=0 ground state) toward the degeneracy-weighted average of all level energies as T increases.
Why does the excited-state population increase with temperature?+
As T rises, kBT grows, which shrinks the exponent Ei/kBT for any nonzero Ei, making exp(-Ei/kBT) closer to 1 relative to the ground state's factor of exactly 1. The excited state's Boltzmann factor therefore catches up toward the ground state's, so its share of the total population (its occupation probability) increases with temperature, this is exactly the curve plotted on this page.
Is the partition function the same as the number of microstates?+
Not quite. The (canonical) partition function is a Boltzmann-weighted sum over microstates, not a plain count. At infinite temperature it does reduce to a simple count (the total degeneracy, sum of gi), but at any finite temperature lower-energy microstates are weighted more heavily than higher-energy ones.
Can this calculator handle more than 4 energy levels?+
This tool supports up to 4 discrete levels via the 4 input rows, which is enough for most introductory two-level and few-level statistical mechanics problems (spin systems, simple electronic transitions). For systems with many more levels or a continuous energy spectrum, the sum generalizes to an integral over the density of states, outside the scope of this direct-entry calculator.

What is the partition function?

The partition function Z is a normalization sum over all accessible microstates of a system, weighted by their Boltzmann factors exp(-Ei/kBT). It might look like a bookkeeping quantity, but essentially every thermodynamic property of the system (average energy, entropy, free energy, heat capacity) can be derived from Z and its derivatives with respect to temperature.

What is the formula for the canonical partition function?

Z = sum over i of gi * exp(-Ei / (kB*T)), where gi is the degeneracy (number of distinct states) at energy level Ei, kB is the Boltzmann constant, and T is the absolute temperature. Once Z is known, the occupation probability of level i is pi = gi*exp(-Ei/kBT) / Z.

Why are lower-energy states always more populated at finite temperature?

Because the Boltzmann factor exp(-Ei/kBT) decreases as Ei increases, for any finite positive temperature. A lower Ei always produces a larger Boltzmann factor than a higher Ei, so states are exponentially weighted toward the ground state, this is the Boltzmann distribution, and it is why the ground state (or lowest-energy accessible level) always has the highest occupation probability.

What happens to the populations as T approaches 0?

As T to 0, kBT to 0, so exp(-Ei/kBT) vanishes for every level except the ground state (Ei=0), whose factor stays exactly 1. In this limit only the ground state is populated (p1 to 1, all others to 0), the system freezes entirely into its lowest-energy configuration.

What happens to the populations as T approaches infinity?

As T to infinity, kBT becomes much larger than every energy gap, so exp(-Ei/kBT) to 1 for every level regardless of Ei. The occupation probabilities then approach the ratio of degeneracies alone, pi to gi / (sum of all gj), completely independent of the energy differences between levels.

What is kBT at room temperature?

At T=300 K, kBT = 8.617333262e-5 eV/K x 300 K is approximately 0.02585 eV, or about 25.85 meV. This is a widely used reference figure in condensed matter and semiconductor physics: any energy gap much larger than roughly 25.85 meV is only weakly populated at room temperature, while gaps much smaller than that are close to equally populated.

How do I model a system with only 2 energy levels?

Enter your ground state as Level 1 (E1=0, g1 as needed) and your excited state as Level 2, then set the degeneracy of Level 3 and Level 4 to 0. A degeneracy of 0 removes a level from the sum entirely, so it contributes nothing to Z, the occupation probabilities, or the average energy.

What does the average energy result represent?

The average energy avgE = sum over i of pi*Ei is the thermally averaged energy of the system at temperature T, weighting each level's energy by how likely the system is to occupy it. It rises from 0 (all population in the E=0 ground state) toward the degeneracy-weighted average of all level energies as T increases.

Why does the excited-state population increase with temperature?

As T rises, kBT grows, which shrinks the exponent Ei/kBT for any nonzero Ei, making exp(-Ei/kBT) closer to 1 relative to the ground state's factor of exactly 1. The excited state's Boltzmann factor therefore catches up toward the ground state's, so its share of the total population (its occupation probability) increases with temperature, this is exactly the curve plotted on this page.

Is the partition function the same as the number of microstates?

Not quite. The (canonical) partition function is a Boltzmann-weighted sum over microstates, not a plain count. At infinite temperature it does reduce to a simple count (the total degeneracy, sum of gi), but at any finite temperature lower-energy microstates are weighted more heavily than higher-energy ones.

Can this calculator handle more than 4 energy levels?

This tool supports up to 4 discrete levels via the 4 input rows, which is enough for most introductory two-level and few-level statistical mechanics problems (spin systems, simple electronic transitions). For systems with many more levels or a continuous energy spectrum, the sum generalizes to an integral over the density of states, outside the scope of this direct-entry calculator.