Random walks add up to a smooth gradient
Diffusion looks purposeful — dye spreads evenly through water, a scent fills a room, salt equalises across a membrane — but nothing in the process is aiming for anything. Each molecule takes a random walk: it is battered by thermal collisions and moves in an unpredictable direction at every instant. What looks like directed flow "from high concentration to low" is really a statistical artefact of huge numbers. Where there are more particles, more of them randomly wander outward than wander in from the sparser side, simply because there are more of them to begin with. Net motion emerges from pure chance plus an uneven starting count.
This microscopic picture is captured macroscopically by Fick’s laws, published by Adolf Fick in 1855 by analogy with Fourier's law of heat conduction. Fick's first law says the diffusive flux J is proportional to the concentration gradient:
J = -D * (dC/dx) J flux -- amount crossing a unit area per unit time D diffusion coefficient (m^2/s) -- how fast the species spreads C concentration dC/dx concentration gradient (steepness of the slope)
The minus sign says flux runs downhill: net motion is from high C to low C. Fick's second law follows from combining the first law with conservation of mass (particles are neither created nor destroyed), giving the diffusion equation:
dC/dt = D * (d^2 C / dx^2)
This is the same equation that governs heat conduction, and it has the same signature solution: an initial spike of concentration spreads into a Gaussian bell curve whose width grows as sqrt(t), not as t. That square-root scaling is the single most important fact about diffusion: to double the spreading distance you need four times as long, not twice as long. It is why diffusion alone is far too slow to move oxygen across a whole animal body (which is why blood circulation exists) but is plenty fast across the few-micron width of a cell membrane.
Osmosis: diffusion of a solvent, not a solute
Osmosis is a special case: water molecules diffuse across a semi-permeable membrane that lets the solvent through but blocks the solute (say, a large sugar molecule). Water cannot equalise concentration by moving solute, so instead it moves itself — net flow goes from the side with more free water (lower solute concentration) to the side with less, diluting the concentrated side until the chemical potential of water is equal on both sides, or until a counteracting osmotic pressure builds up. The Van't Hoff relation treats osmotic pressure like an ideal-gas pressure of the dissolved particles: π = iMRT, where i is the number of particles the solute dissociates into, M its molar concentration, R the gas constant and T the absolute temperature. This is exactly how a plant cell stays turgid, how a red blood cell bursts in pure water, and how a slug shrivels on salted ground.
Simulating it: many random walkers, or one field
There are two equally valid ways to simulate diffusion, and this site's demo uses the particle version because it makes the randomness visible. Every particle gets a small random displacement each frame, drawn independently in x and y — literally Brownian motion: x += randn() * sqrt(2*D*dt). Track thousands of these and the histogram of positions converges to the Gaussian solution of Fick's second law automatically; no gradient, no flux calculation, just noise plus particle count. The alternative is a finite-difference field solver that discretises C(x,y) on a grid and iterates the discrete Laplacian directly — faster for large systems and for enforcing membrane boundaries exactly, but it hides the underlying randomness that makes diffusion diffusion.
Membrane mode adds a rule: a particle attempting to cross the membrane line is reflected unless it happens to pass a semi-permeability check, which is exactly the microscopic mechanism behind osmotic pressure — block solute particles outright, let solvent particles through freely, and watch the free volume rebalance.
Frequently asked questions
Why does diffusion slow down over time instead of continuing at a constant rate?
Flux is proportional to the local gradient (Fick's first law), and diffusion itself erodes that gradient as it proceeds. As concentrations even out, the driving gradient shrinks, so the process naturally decelerates and the spreading distance grows only as the square root of time.
Is diffusion the same thing as osmosis?
Osmosis is diffusion of a solvent (usually water) across a membrane that is selectively permeable -- it lets the solvent through but blocks a dissolved solute. The solute cannot equalise itself, so the solvent moves instead, which is why osmosis is directional even though ordinary diffusion has no preferred direction.
Why do the particles in the simulation keep jittering even at equilibrium?
Reaching a uniform concentration stops the *net* flow, not the motion. Each particle keeps taking its random walk forever; it is only the population-level statistics -- equal numbers wandering each way -- that stay constant once equilibrium is reached.
Try it live
Everything above runs in your browser — open Particle Diffusion and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.
▶ Open Particle Diffusion simulation