← all topics

The Ulam spiral

Write the whole numbers on a square spiral, light up the primes, and they snap onto surprising diagonal lines.

A doodle in a boring meeting

In 1963 the mathematician Stanisław Ulam was stuck in a meeting and let his pen wander. He wrote 1 in the middle of a page and spiralled the counting numbers outward in a square: 2, 3, 4, 5, and on around the loops.

Then he shaded the primes — the numbers that can only be divided by 1 and themselves. He expected a random scatter. Instead the dots lined up along clear diagonal streaks, as if the primes were following invisible rails. He had stumbled onto a pattern nobody had drawn before.

Why the diagonals appear

Each diagonal on the spiral is really a simple formula in disguise. As you step along a diagonal line, the numbers grow in a steady, curving way that a quadratic formula describes — something of the shape (a number times n times n) plus (a number times n) plus a constant.

Some of these formulas are unusually good at spitting out primes. The most celebrated is Euler's polynomial, n² + n + 41. Feed in n = 0, 1, 2, all the way to 39, and every single answer is prime — forty primes in a row. On the spiral, that lucky formula shows up as one of the boldest, longest diagonal streaks.

Where the magic stops

No prime formula runs forever. Euler's streak finally breaks at n = 40, where n² + n + 41 equals 1681, which is 41 times 41 — not prime. And our example number, 41, breaks it again: plug in n = 41 and you get 1763, which is 41 times 43.

It is a neat coincidence that the constant 41 in the formula is also where the run of primes first fails. That is the spirit of the whole picture: tidy rules that work astonishingly well, then quietly stop.

A puzzle that is still open

The diagonals are real, not a trick of the eye — you can keep zooming out and they keep appearing. But mathematicians still cannot fully explain how rich those prime-laden lines get, or predict which formulas will be the best prime factories.

It is a rare and lovely thing: a pattern simple enough to draw on a napkin, beautiful enough to frame, and deep enough that more than sixty years later, no one has the whole answer.