The Nagel-Schreckenberg Traffic Model, Explained

After reading this you will understand why traffic jams form on an open road with no crash and no bottleneck, how four simple rules produce that behaviour, and how to read the flow curve to find the density that moves the most cars.

What the model is and why jams appear from nothing

The Nagel-Schreckenberg model is a cellular automaton for single-lane traffic. Introduced by Kai Nagel and Michael Schreckenberg in 1992, it divides a road into equal cells. Each cell is either empty or holds one car, and each car carries an integer speed from 0 to a maximum v_{max}. Time advances in discrete ticks. On every tick, every car applies the same four rules at once.

The striking result is that jams appear without any external cause. Put enough cars on a ring road, let one driver tap the brakes once, and that single slowdown can grow into a dense band of stopped cars that drifts backward against the flow of traffic. Nobody crashed. There is no on-ramp, no red light, no lane closure. The jam is a property of the collective, not of any one driver. On a real highway you meet this as the phantom jam: you crawl for two minutes, then the road clears and you never see a reason.

The simulator puts cars on a closed loop, so the number of cars is fixed. That lets you study one density at a time and watch the same population circulate.

When to use it, and when not to

Use this model to build intuition about three things: that congestion is an emergent phase, that flow does not rise forever with density, and that small noise can trigger large structure. It is the cleanest available demonstration that a traffic jam is a wave, not a place.

Do not use it to predict tomorrow's commute. The model has one lane, identical drivers, no junctions, and a single dawdle probability. Real traffic has overtaking, trucks, merges, and drivers who react differently. The model reproduces the shape of the fundamental diagram, not the exact numbers for a given road.

Cellular automata like this one sit alongside differential-equation models. The traffic model is discrete in space, time and speed. Compare that with the continuous rate equations behind the Predator-Prey Simulator, which track populations as smooth quantities rather than counting individuals in cells.

The four rules and the intuition behind each

Let car i have speed v_i and let d_i be the number of empty cells between it and the car ahead. One tick updates every car in this order, using the same old positions for all gap measurements.

  1. Accelerate. If v_i \lt v_{max}, increase v_i by 1. Drivers want to go faster.
  2. Brake. If v_i \gt d_i, set v_i = d_i. You cannot drive into the gap you do not have.
  3. Dawdle. With probability p, if v_i \gt 0, decrease v_i by 1. This is the only randomness: a distraction, an overreaction, a slight tap of the brake.
  4. Move. Advance the car v_i cells.

The braking rule can be written compactly. After acceleration the new speed is capped by the gap:

v_i' = \min(v_i + 1,\; d_i,\; v_{max})

Here v_i + 1 is the wish to speed up, d_i is the safety limit set by the car ahead, and v_{max} is the hard cap. Then with probability p the model subtracts one more, giving the final speed \max(v_i' - 1,\; 0) on dawdle ticks. Without the dawdle (p = 0) the model is deterministic and, above a certain density, settles into smooth patterns. The noise is what makes jams appear and disperse the way real ones do.

Density, flow and the fundamental diagram

Two summary numbers describe the whole road. Density \rho is the fraction of cells that hold a car: with N cars on L cells, \rho = N/L. Flow q (also called throughput) is the average number of cars that cross any fixed point per tick. It equals density times mean speed:

q = \rho \cdot \bar{v}

In this equation \bar{v} is the average speed of all cars measured in cells per tick. The plot of q against \rho is the fundamental diagram, and its shape is the whole story. At low density cars rarely meet, so \bar{v} \approx v_{max} and flow climbs almost linearly. Past a critical density \rho_c the road is crowded enough that jams persist, mean speed falls faster than density rises, and flow drops. Add more cars beyond the peak and you move fewer of them past any point.

Flow rises to a peak near density 0.16, then falls. The vertical marker sits at the critical density where throughput is largest. Numbers are typical for the defaults below and will vary a little run to run.

A worked example with the demo settings

The demo button loads the field defaults. Work through one tick by hand to see the rules bite, then reason about the whole road.

One tick on a short stretch

Take v_{max} = 5 and p = 0.3. Line up three cars on a stretch of road. Positions are cell indices, and the gap is the count of empty cells to the next car ahead.

Three cars before and after one tick (no dawdle drawn this tick)
CarPositionOld speedGap aheadNew speedNew position
A03222
B32636
C1059515

Car A wished to go from 3 to 4 (rule 1), but the gap is only 2, so rule 2 clamps it to 2. It moves 2 cells to position 2. Car B accelerates from 2 to 3, has plenty of room, and advances to 6. Car C is already at v_{max} = 5, cannot speed up, has room, and advances to 15. Now suppose the dawdle die comes up for car B (probability 0.3): its speed drops from 3 to 2, and it lands at 5 instead of 6. That one tap is exactly how a jam seeds.

Now scale up. Set the density to the default and watch the whole ring. Below the critical density most cars sit at speed 5 and the space-time diagram shows nearly straight bright lines. Push density up and dark backward-slanting stripes appear. Each stripe is a jam. Its slope is the jam's velocity: in this model a well-developed jam drifts backward at close to one cell per tick, roughly the reciprocal of the dawdle interplay, regardless of how fast the free-flowing cars move.

A line chart of flow versus density. At v_{max} = 5 and dawdle 0.3, flow rises to about 0.65 near density 0.16, then falls steadily toward 0 as density approaches 1. Lowering the dawdle raises and sharpens the peak; raising it flattens the curve.

Reading and interpreting the results

Three things on the screen carry the meaning. First, car colour by speed: a road of one bright colour is free flow, patches of dark are jams. Second, the space-time diagram, where the horizontal axis is position and each new row is a later tick. A jam shows as a dark band tilting up and to the left, because the stopped region sits at earlier positions as time passes. That leftward tilt is the backward wave. Third, the live flow number. Watch it settle after the first hundred or so ticks; early values reflect the starting layout, not the steady state.

To find the peak of the fundamental diagram, hold v_{max} and p fixed and raise density in small steps, recording the settled flow at each. With v_{max} = 5 and p = 0.3 you should find flow peaking near \rho = 0.16 at about 0.65 cars per tick, then declining. That peak density is the most efficient loading of the road.

Common mistakes when running it

Do not read the flow before the road settles. The first rows of the space-time diagram depend on how cars were placed at the start. Let the simulation run a few hundred ticks before you trust the average, and take several runs at each density because the dawdle makes every run slightly different.

A second mistake is expecting a sharp critical density. The transition from free flow to jams is gradual and noisy, not a clean edge. Near \rho_c you will see jams flicker in and out; that is real behaviour, not a bug.

A third is confusing high density with high flow. It feels like packing more cars should move more traffic. The diagram says otherwise: past the peak, every extra car lowers throughput. On real roads this is why ramp metering, which limits how fast cars join, can raise the total number that get through.

Finally, remember the model is one lane on a loop. There is no overtaking. A single slow car sets the pace for everyone behind it until a gap opens, which exaggerates how fast jams form compared with a multi-lane road.

Related simulations on this site

If emergent collective behaviour from simple local rules interests you, two other simulators here explore the same idea in different settings. The SIR Epidemic Simulator shows how an outbreak grows and burns out from three population rates, with its own critical threshold for whether a disease spreads at all. The Predator-Prey Simulator traces boom-and-bust cycles from coupled rate equations. All three share a lesson: rich, wave-like or cyclic patterns come from a handful of rules, not from any single driver, predator or patient acting alone.

Frequently asked questions

Why do traffic jams move backward?

A jam is a region of stopped cars. Cars leave the front as room opens and join at the back as new arrivals brake. The region of stopped cars therefore shifts toward earlier positions over time even though every individual car moves forward. In the model this backward drift is close to one cell per tick.

What causes the phantom jam with no accident?

Above the critical density the road is crowded enough that one random brake tap (the dawdle rule) cannot be absorbed. The car behind brakes, then the next, and the slowdown propagates back into a standing wave. Set p = 0 and above the critical density the road settles into steady patterns instead.

What density gives the most flow?

With v_{max} = 5 and p = 0.3, flow peaks near density 0.16 at roughly 0.65 cars per tick. Lower the dawdle and the peak rises and moves right; raise it and the peak falls and moves left.

Does raising the speed limit increase flow?

Only at low density. Once jams form, mean speed is set by the gaps between cars, not by v_{max}. Raising the limit lifts the free-flow branch of the diagram but barely changes the congested branch or the peak flow value.

Is the dawdle probability realistic?

It is a stand-in for all human imperfection: distraction, delayed reaction, cautious braking. A value around 0.2 to 0.3 reproduces realistic jam dynamics. It is a single tunable number, not a measurement of any real driver.