Mathwords logoMathwords

Prime Spiral — Definition, Formula & Examples

A prime spiral (also called the Ulam spiral) is a visual pattern formed by writing the positive integers in a spiral on a grid and then highlighting which of those integers are prime. The result reveals unexpected diagonal lines and clusters among the primes.

The Ulam spiral is constructed by arranging the natural numbers 1,2,3,1, 2, 3, \ldots in a square spiral originating from a central point, then marking each position whose value is a prime number. The observed diagonal alignments correspond to quadratic polynomials f(n)=an2+bn+cf(n) = an^2 + bn + c that produce an unusually high density of prime values.

How It Works

Start by placing the number 1 at the center of a grid. Move right to place 2, then up for 3, left for 4 and 5, down for 6, 7, and 8, and so on, spiraling outward. Once the grid is filled, color every cell that contains a prime number and leave composites blank. When you zoom out on a large spiral (say, thousands of numbers), prominent diagonal lines emerge. These diagonals correspond to certain quadratic expressions that happen to generate many primes, such as Euler's famous n2+n+41n^2 + n + 41.

Example

Problem: Construct a small Ulam spiral for the integers 1 through 25 and identify which cells along the main diagonals are prime.
Step 1: Place 1 at the center. Spiral outward: right → up → left → down, increasing the run length appropriately. The first ring contains 2–9, the second ring 10–25.
Step 2: The numbers along one diagonal from the center read 1, 3, 13, 31, ... In our 5×5 grid the diagonal through 1 going upper-left contains 1, 3, 13. Of these, 3 and 13 are both prime.
Step 3: Highlight all primes in the grid: 2, 3, 5, 7, 11, 13, 17, 19, 23. Even at this small scale, notice that primes cluster along certain diagonals more than others.
Answer: In the 5×5 Ulam spiral, 9 of the 25 cells are prime, and several share diagonal alignments — a small preview of the striking patterns visible in larger spirals.

Why It Matters

The Ulam spiral, discovered by Stanislaw Ulam in 1963 during a boring meeting, connects prime distribution to quadratic polynomials — a link still not fully explained. It motivates open problems in analytic number theory, including conjectures about which polynomials produce infinitely many primes (the Bunyakovsky conjecture).

Common Mistakes

Mistake: Assuming the diagonal patterns mean primes follow a predictable formula.
Correction: The diagonals show that certain quadratics generate primes more often than average, but no simple formula produces only primes. Prime distribution remains fundamentally irregular.