Gas Molecule SimulatorBeta
Watch thousands of colliding molecules settle into the Maxwell–Boltzmann distribution
This tool is a beta version still being stabilized. Please let us know if a result looks off.
Changing the temperature instantly rescales every molecule's velocity by the same factor (no gradual heating).
- Measured T
- –
- Most probable speed
- –
- Mean speed
- –
- RMS speed
- –
- PA / NkT
- –
- Collisions/s
- –
Each dot is one gas molecule. Molecules collide perfectly elastically with each other and with the walls, so total energy is conserved. They all start at the same speed, yet after enough collisions the histogram settles onto the Maxwell–Boltzmann curve. Raising the temperature scales every velocity by the same factor and the distribution spreads out. Dashed lines mark the most probable, mean and RMS speeds. Press on the canvas to follow the nearest molecule's path, a random walk like Brownian motion. PA/NkT near 1 means the ideal gas law holds; bigger, denser molecules push it above 1.
Working…
0.0
It hasn't frozen — the result will appear when the calculation finishes.
About Gas Molecule Simulator
Every dot here is a hard disk of the same mass. Disks bounce perfectly elastically off each other and off the walls, and nothing else acts on them. On restart every molecule gets the same speed, √(2kT), in a random direction, so the first histogram is a single spike. Collisions then smear that spike into the Maxwell–Boltzmann curve drawn on the right. Energy is conserved the whole time: nothing is added, the same energy is just reshuffled among the molecules.
The simulation is two-dimensional, which changes the numerical factors you may remember from a textbook. All numbers below are for 2D. Temperature is shown in kelvin for convenience, but internally 300 K is mapped to kT = 10,000 px²/s², so the units are arbitrary screen units.
The 2D Maxwell–Boltzmann distribution and its three speeds
If the x and y velocity components are each normally distributed with variance kT/m, the speed follows f(v) = (mv/kT)·exp(−mv²/2kT). In 3D the prefactor is v²; in 2D it is just v. Three characteristic speeds come out of this curve: the most probable speed √(kT/m), the mean speed √(πkT/2m) and the root-mean-square speed √(2kT/m). The three dashed lines on the histogram are these, left to right.
At 300 K (kT = 10,000) they are 100, 125.3 and 141.4 px/s. The ratio 1 : 1.253 : 1.414 does not depend on temperature, because heating does not change the shape of the curve, only stretches the speed axis by √T. Note that the starting speed √(2kT) equals the RMS speed exactly. The initial spike and the final curve carry the same average kinetic energy; only the spread differs.
Equipartition: what the thermometer actually reads
Classical statistical mechanics gives each quadratic degree of freedom an average energy of ½kT. A disk moving in x and y has two, so its mean kinetic energy is kT (a monatomic gas in 3D would have 3/2 kT). The readout labelled measured T runs this backwards: it averages ½v² over all molecules and calls the result kT.
The disks never spin. Real diatomic molecules such as N₂ and O₂ have two rotational degrees of freedom as well and store more energy at the same temperature, which is why their heat capacity is higher than a monatomic gas. This model leaves rotation out entirely.
Experiment 1: from a spike to a curve
With the defaults (2,500 molecules, radius 2.5 px), press restart and watch the histogram. The spike near 141 px/s collapses within seconds, spreading both left and right, because in any collision one partner usually speeds up while the other slows down. Drop the count to 500 and relaxation is visibly slower, since collisions are rarer, and the histogram is noisier. Statistical scatter in a bin shrinks only like 1/√N.
Slow the playback and press on the canvas to follow one molecule. Its path is a chain of short straight segments with random kinks, the same structure as the Brownian motion of a dust grain in air.
Experiment 2: why PA/NkT drifts above 1
For an ideal gas, pressure times area equals NkT. The tool measures pressure from the momentum delivered to the walls and shows the ratio. Real disks have size, though: no disk can sit where another already is. The free area is smaller than the box, so molecules hit the walls more often and the ratio rises above 1.
A convenient measure is the packing fraction η = Nπr²/A. On an 800×580 px canvas with default settings, η ≈ 2,500 × 19.6 / 464,000 ≈ 0.11. The Henderson approximation for hard disks, Z = (1 + η²/8)/(1 − η)², then predicts about 1.25. Cut the radius to 1.5 px and η ≈ 0.04, Z ≈ 1.08, close to ideal. Your canvas size depends on your screen, so plug in your own width and height and see how close the readout comes. If a combination would push η above 0.7 (say radius 8 px × 8,000 molecules), the tool places only as many as fit and shows a note: any denser and the disks overlap, so position corrections rather than collisions generate the pressure and PA/NkT stops meaning anything. Near 0.7 the Henderson formula overshoots (about 17), while the simulation reads around 9.
Scaling up to real air
In 3D the three speeds are √(2kT/m), √(8kT/πm) and √(3kT/m). For nitrogen at 300 K (one molecule is 4.65×10⁻²⁶ kg, kT = 4.14×10⁻²¹ J) they come to roughly 422, 476 and 517 m/s, faster than the speed of sound in air. A smell still takes a while to cross a room because at atmospheric pressure a molecule collides every few tens of nanometres and loses its direction. The kinked path in tracking mode is that process in miniature.
Worked examples
Quadrupling the temperature
- Input
300 K → 1,200 K- Output
All three speeds double: 200 / 250.7 / 282.8 px/s
Speeds scale as √T. When you move the slider the tool multiplies every velocity by the same factor (2 here), so the distribution keeps its shape and simply stretches.
How many molecules beat the mean speed?
- Input
2D distribution, v greater than the mean √(πkT/2m)- Output
exp(−π/4) ≈ 45.6%
In 2D the probability of exceeding speed v integrates neatly to exp(−mv²/2kT). Fewer than half the molecules beat the mean because the long tail on the fast side pulls the mean up.
Nitrogen at room temperature
- Input
N₂, m = 4.65×10⁻²⁶ kg, T = 300 K, 3D formulas- Output
most probable ≈ 422 m/s, mean ≈ 476 m/s, RMS ≈ 517 m/s
2kT/m = 1.78×10⁵ m²/s², whose square root is 422 m/s. The other two follow from the fixed ratios √(4/π) and √(3/2).
How to use it
- Press restart so every molecule starts at the same speed.
- Watch the histogram bars settle onto the theory curve.
- Change temperature, count and radius, and compare the dashed speed markers and the PA/NkT readout.
- Press on the canvas to trace a single molecule.
Frequently asked questions
Why does the gas speed up instantly when I raise the temperature?
The tool does not simulate heating. It rescales every velocity by the same factor so the average energy matches the new temperature. A real gas would warm gradually through collisions with a hot wall.
Why don't the numbers match my textbook?
Textbooks usually treat 3D gases, where f(v) ∝ v²·exp(−mv²/2kT). This is a flat world of disks with f(v) ∝ v·exp(…), so the coefficients of the characteristic speeds differ.
Large, numerous molecules look jammed. Is that a bug?
It is a packing limit. Hard disks start to crystallise around a packing fraction of 0.7 and cannot exceed about 0.907. Close to that, PA/NkT shoots up and the gas behaves more like a solid.
If energy is conserved, why does the distribution change at all?
The total stays fixed, but there are overwhelmingly more ways to share it in a Maxwell–Boltzmann pattern than in the all-equal starting pattern. Random collisions drift toward the most common arrangement.
Notes
Z = (1 + η²/8)/(1 − η)² is Henderson's empirical equation of state for hard disks; it is most accurate at low packing fractions.
There is no attraction between molecules and no rotation, so condensation and van der Waals effects do not appear.
Sources
- J. C. Maxwell, Illustrations of the dynamical theory of gases, Phil. Mag. 19–20 (1860)
- HyperPhysics — Maxwell speed distribution
- NIST CODATA — Boltzmann constant
Last reviewed: