Ulam Spiral

6 min read#number-theory

Writing the integers in a square spiral and marking the primes reveals startling diagonal alignments where order seems to leak out of randomness.

Contents

Ulam Spiral

The Ulam spiral is one of the most famous accidental discoveries in mathematics. In 1963, bored during a lecture, Stanisław Ulam began writing the integers in a square spiral and idly circling the primes. He expected a random scatter. Instead the primes lined up along diagonals — long, conspicuous streaks that have no business appearing in something as irregular as the primes. The pattern is real, partial, and still not fully explained.

Coil the integers, mark the primes

Start with 1 at the center and spiral outward: 2 to its right, then up, left, down, around and around. Color a cell whenever its number is prime. The diagonals emerge on their own.

The Ulam spiral. Integers coil out from the center; primes are lit. Notice the diagonal streaks — primes clustering along lines like 4k²+something. The spiral grows outward as it fills; click to restart and rebuild it.

Why the diagonals?

The diagonals are not an illusion — they trace quadratic polynomials. Moving along a diagonal of the spiral steps you through values of an expression like 4k^2 + bk + c. Some of these quadratics are unusually rich in primes; the most celebrated is Euler's polynomial

k^2 + k + 41,

which is prime for every k from 0 to 39 — forty primes in a row. Each prime-dense quadratic paints one bright diagonal across the spiral.

Euler's polynomial k² + k + 41 (all prime)
Every value shown is prime. This single quadratic produces 40 consecutive primes (k = 0…39), and along the Ulam spiral it lights up as one of the most striking diagonals.

Same primes, different canvas

The effect is not unique to the square spiral. Plot the primes on a polar spiral, or with a hexagonal coiling, and different alignments appear or dissolve — proof that the diagonals are partly an artifact of how we arrange the integers, and partly a genuine fact about prime-dense quadratics. The honest summary: the primes are neither random nor regular, and the Ulam spiral is the clearest picture we have of that in-between.

What mathematical objects do the diagonal streaks in the Ulam spiral correspond to?

See also