Kinetic Theory Gas Simulator
Watch atoms bounce while pressure, temperature and the Maxwell-Boltzmann curve are measured from their motion, making the gas law a result not an input.
Simulator
- P A / N k T Pressure from wall impacts, temperature from mean kinetic energy. Nothing here assumes the gas law, so 1 is a result.
- measuring
- Pressure A wall in two dimensions is a line, so pressure is force per unit length.
- measuring mN/m
- Temperature From the mean kinetic energy. In two dimensions that is kT per atom, not 3kT/2.
- 0 K
- Mean speed √(πkT/2m) in two dimensions. The rms speed is higher, at √(2kT/m).
- 0 m/s
- Mean free path 1/(2√2 n d), with d the diameter of a disc, since a moving disc sweeps a strip 2d wide. Compare it with the box.
- 0 nm
- Area filled How much of the box the atoms themselves occupy. This is why a crowded gas stops being ideal.
- 0%
- Measured speeds
- Maxwell-Boltzmann
Citing this tool
Last updated . Add the date you accessed it as well, which a citation of a page that can change asks for. If a specific result matters, cite the permalink from the tool’s share row instead of this page: it reproduces the exact parameters.
The equation
Kinetic theory of gases, Maxwell (1860) and Boltzmann (1872)
The gas law is not assumed here
Every gas law calculator takes PV = nRT as given and rearranges it. This page
contains no gas law at all. It contains atoms with positions and velocities, walls they bounce
off, and Newton’s laws. Pressure is measured by adding up the momentum the atoms deliver to
the walls. Temperature is measured from their mean kinetic energy. Nothing connects the two.
Then read the top figure. PA/NkT, where k is the
Boltzmann constant, sits at about 1, and it stays there when you
change the temperature, the box, or the gas. That is the whole content of kinetic theory: the
gas law is not a separate law of nature, it is what mechanics and statistics produce when you
have enough particles to average over.
Where pressure comes from
An atom hits a wall and rebounds. Its momentum along that direction goes from
+mv to −mv, so the wall receives 2mv. One impact is a
kick, not a pressure. What a wall actually feels is an enormous number of these arriving in
quick succession, and the average force is the total momentum delivered divided by the time
it took.
That is exactly what the simulation does, which is why the pressure readout says “measuring” for a moment when you change something: it needs a window of time to average over, because most individual timesteps contain no wall impact at all.
Why this gas is flat, and what that changes
The screen is two-dimensional, so the gas is too. That is an honest simplification rather than a hidden one, and it changes several formulas that are usually quoted in their three-dimensional form.
- Equipartition. Mean kinetic energy is
kTper atom here, one halfkTper degree of freedom with two of them. In three dimensions it is3kT/2. - The speed distribution.
f(v) ∝ v·e^(−mv²/2kT), with one power ofvfrom the circumference of a ring in velocity space. The familiarv²comes from the surface area of a sphere and does not belong in a flat gas. - Pressure. A wall in two dimensions is a line, so pressure is force per unit
length, quoted here in millinewtons per metre.
PA = NkTstill balances dimensionally. - Characteristic speeds. Most probable
√(kT/m), mean√(πkT/2m), rms√(2kT/m). All three differ from the 3D values.
Using the three-dimensional formulas on this simulation would put the temperature out by 50
percent and the peak of the distribution out by a factor of √2, and it would
look entirely plausible while doing it.
Watch a distribution assemble itself
Set the starting speeds to “All identical”. Every atom now has the same speed in a random direction, which is a state no real gas can hold, and the histogram is a single spike while the whole box is one colour.
Press play. Collisions begin redistributing energy between pairs, and within a few collisions per atom the spike has spread out and settled onto the Maxwell-Boltzmann curve. Two things are worth noticing while it happens. The temperature does not change, because elastic collisions conserve total energy, so the gas is thermalising rather than heating. And it never goes back: the distribution is where a randomly colliding population ends up, and there is nothing to push it off again.
Where the ideal gas law starts to fail
Now push the atom count up and watch PA/NkT climb. With argon, the default gas,
400 atoms in the smallest box cover about 20 percent of it and the ratio reaches about 1.6,
and it is not an error.
The ideal gas law assumes atoms are points. Real ones occupy space, so when they fill an
appreciable fraction of the container each atom has less room than the box area suggests, and
it reaches the walls more often. For hard discs the leading correction is
PA/NkT = 1 + 2φ, where φ is the fraction of the area the atoms cover,
which is the “area filled” readout. At φ of 8 percent that predicts 1.16, and the
simulation measures 1.21. The difference is what the formula leaves out: the next term in the
series, and the thin strip along each wall that no atom’s centre can reach.
This is the same physics as the b term in the van der Waals equation. Turn the
atom count back down and the ratio returns to 1, because the ideal gas law is the dilute
limit and nothing more.
Mean free path, and why it decides everything else
The bar under the box is the mean free path drawn to scale: the average distance an atom
covers between collisions, 1/(2√2 n d), with n atoms per unit area and
d the diameter of one. The 2d is the flat version of a collision
cross-section: a moving atom hits any other whose centre comes within one diameter of its
path, so it sweeps a strip two diameters wide.
Compare it with the box. When it is longer than the container, atoms cross without meeting each other and only the walls matter, which is the regime a vacuum chamber operates in and why a thermos flask works. When it is a small fraction of the box, atoms are interrupted constantly, which is why a dense gas diffuses slowly and why smells take so long to cross a still room despite molecular speeds of several hundred metres per second.
Why helium is the one that escapes
Switch between the four gases at a fixed temperature and watch the speeds. Temperature fixes the mean kinetic energy, not the speed, so speed goes as one over the square root of mass. Helium at 300 K averages about 990 metres per second where xenon manages about 170. Those are this flat gas’s speeds; a real three-dimensional gas moves faster, about 1,260 and 220 metres per second, in the same ratio.
That single fact explains a balloon going soft overnight, why Earth has kept its nitrogen and lost almost all of its primordial hydrogen and helium, and why separating uranium isotopes by gaseous diffusion is possible at all despite a mass difference under one percent.
What this model leaves out
The atoms are hard discs: they collide when they touch and ignore each other completely
otherwise. Real atoms repel steeply when close, much as these discs do, but they also attract
weakly at a distance, which is the a term in van der Waals and the reason gases can be liquefied at all. Nothing
here can condense, no matter how cold or crowded you make it.
Collisions are also perfectly elastic, and the walls are perfectly smooth and rigid: each one returns an atom at the speed it arrived with, so no heat passes between the gas and its container. There is no rotation, no vibration, and no internal structure, so this is a monatomic gas and its heat capacity would come out accordingly. And it is flat, which is the simplification with the most consequences, all of them listed above.
Common mistakes
- Using the three-dimensional distribution on a flat gas. The
v²prefactor belongs to a sphere. Here it isv. - Reading a ratio above 1 as a broken simulation. It is the excluded-volume correction, and the area-filled readout tells you how large to expect it.
- Confusing the three characteristic speeds. The peak of the histogram is the most probable speed, which is below the mean, which is below the rms. Only the rms one appears in the energy.
- Thinking thermalisation heats the gas. Starting from identical speeds, the distribution changes shape at constant temperature. Elastic collisions cannot add energy.
- Expecting a faster gas to be a hotter one at a glance. Compare helium and xenon at the same temperature: wildly different speeds, identical mean kinetic energy.
- Assuming pressure is instantaneous. It is an average over many impacts. Any single moment either has an impact or does not.
Model and assumptions
- Method
- Direct particle stepping under Newton’s laws
- Largest step
- 2e-13 s
- Repeatability
- Random. A shared link reproduces the settings, not the particular run.
What it assumes
- Hard discs in two dimensions with perfectly elastic collisions, so kinetic energy is conserved exactly at every impact.
- No gas law appears anywhere in the code: pressure is measured by summing the momentum the discs deliver to the walls.
- No interparticle forces at all beyond contact, and no gravity.
Where it stops holding. Real gases near condensation, where attraction between molecules matters and the ideal gas law itself starts to fail.
Numerical accuracy
No integration error in the motion: between impacts the discs travel in straight lines, and that update is exact. Two approximations sit elsewhere. Collisions are found by testing for overlap at the end of each substep and then rewound to the moment of contact, which makes a single impact exact; what is left is a pair that crosses entirely within one substep, or an atom that meets two partners in one, and the substeps are kept short enough against the size of an atom and the mean free path for both to be rare. Pressure is a running average of the momentum delivered to the walls, so it carries statistical scatter that shrinks the longer the meter averages, which is why the gas-law ratio wanders at first and settles as the meter runs.
Common questions
Where does the ideal gas law actually come from?
From atoms hitting walls, and nothing else. Each impact reverses one component of an atom’s momentum, so the wall receives 2mv. Add up those impulses over a period of time and divide by the time and the wall length and you have pressure, with no gas law used anywhere. Measure temperature separately from the mean kinetic energy, and the combination PA/NkT comes out at 1. That is what this simulator shows: the gas law is a consequence of mechanics plus statistics, not a separate law of nature.
Why is the distribution not the v-squared one from my textbook?
Because this gas is two-dimensional and your textbook’s is three-dimensional. The prefactor counts the directions available at a given speed: in three dimensions that is the surface of a sphere, giving v squared, and in two it is the circumference of a circle, giving one power of v. The rest of the arithmetic shifts with it, so mean kinetic energy here is kT rather than 3kT/2 and the rms speed is √(2kT/m) rather than √(3kT/m). Using the 3D formulas on a flat simulation would put the peak out by a factor of √2.
Why do all the atoms end up with different speeds when they started the same?
Collisions. Set the starting speeds to identical and every atom has the same speed in a random direction, which is a state no real gas can hold. Each collision redistributes energy between the pair involved, and after a few collisions per atom the population has spread into the Maxwell-Boltzmann distribution and stays there. Temperature does not change while this happens, because elastic collisions conserve total energy: the gas is not heating, it is thermalising.
Why does PA/NkT drift above 1 when I add more atoms?
Because the atoms take up room, and the ideal gas law assumes they do not. Once a noticeable fraction of the box is filled, each atom has less space available than the box area suggests, so it hits the walls more often than the ideal law predicts. For hard discs the correction is PA/NkT = 1 + 2φ to first order, with φ the fraction of the area the atoms cover, and you can watch that happen by raising the atom count while reading the area-filled figure. This is the same reason real gases need the van der Waals correction.
What is the mean free path and why does it matter?
The average distance an atom travels between collisions, drawn to scale beneath the box so you can compare it with the container. It is 1/(2√2 n d), where n is the number per unit area and d is the diameter of an atom: a moving atom sweeps out a strip 2d wide and meets every atom whose centre lies inside it. When it is much larger than the box, atoms cross freely and only the walls matter, which is how a vacuum chamber behaves. When it is much smaller, atoms are constantly interrupted, which is what makes a dense gas diffuse slowly and conduct heat the way it does.
Why do the light gases move faster than the heavy ones?
Because temperature fixes the mean kinetic energy, not the speed. At the same temperature every atom has the same average of one-half m v squared, so speed goes as one over the square root of mass. Switching from xenon to helium at fixed temperature multiplies the speeds by about 5.7, since the mass ratio is roughly 33. This is why helium escapes a balloon quickly, why hydrogen and helium leak out of a planet’s atmosphere over geological time, and why uranium enrichment by gas diffusion works at all.