Virtual laboratory/Mathematics/Number theory/Ulam spiral — patterns among the primes

Ulam spiral — patterns among the primes

An extension of the topic of prime numbers. Writing the natural numbers in a spiral and marking the primes, we notice unexpected diagonal lines — a trace of the hidden structure of the primes. The lines correspond to quadratic polynomials that generate many primes (e.g. n²+n+41). It was discovered by the Polish mathematician Stanisław Ulam in 1963.

Ulam spiral — patterns among the primes
Mathematics · Number theory · Ulam spiral — patterns among the primes (1963)
Spiral size — grid side (numbers: side2\text{side}^2)30 × 30
We write the numbers 1, 2, 3, … in a spiral and mark the primes. They will arrange themselves…
grid side
30×30
numbers in spiral
900
primes
154
density
17.1%
🎯 Challenge: prime or composite?
streak: 0

I will give you one of the numbers that lie on the spiral — decide whether it is prime or composite.

What just happened?

The Ulam spiral is one of the most surprising pictures in number theory, discovered by the Polish mathematician Stanisław Ulam in 1963 — reportedly by accident, when, bored during a lecture, he began writing the natural numbers in a spiral and marking the primes. To his astonishment, the primes did not scatter chaotically but lined up along clear diagonal lines.

Why is this not a coincidence?

The pattern appears no matter which number we start the spiral with — so it is not down to chance. The diagonal lines correspond to quadratic polynomials of the form 4n2+bn+c4n^2+bn+c (consecutive numbers on one diagonal differ by amounts that grow linearly, giving a quadratic sequence). Some such polynomials generate an unexpectedly large number of primes — and it is their values that line up into the visible lines.

Euler's famous polynomial:

P(n)=n2+n+41P(n) = n^2 + n + 41

This polynomial yields primes for all n=0,1,2,…,39n = 0, 1, 2, \ldots, 39 — that is, 40 primes in a row: 41,43,47,53,61,71,83,…41, 43, 47, 53, 61, 71, 83, \ldots In the Ulam spiral its values lie on a single diagonal line, highlighted above in amber.

A mystery still open

To this day we do not fully understand why the primes form these patterns — it is one of many puzzling aspects of their distribution, linked to deep, unsolved problems (such as the Riemann hypothesis). The Ulam spiral beautifully shows that even in the seemingly chaotic world of the primes there hides an unexpected structure.

Why this matters for your exams:

Primes are the “building blocks” of all natural numbers (the fundamental theorem of arithmetic), and quadratic polynomials are a school staple. The Ulam spiral connects these two topics and teaches an important intuition: the absence of a visible pattern does not mean there is none — sometimes you have to look at the data differently for a hidden structure to reveal itself.

A Polish touch: Stanisław Ulam is one of the heroes of this collection (alongside Wacław Sierpiński and Stefan Banach) — a co-creator of the Monte Carlo method and a participant in the Manhattan Project.

Remember: in the Ulam spiral the primes line up along diagonal lines because they correspond to prime-rich quadratic polynomials (such as n2+n+41n^2+n+41). It is a visual trace of the hidden, still not fully understood, structure of the primes.

Illustrative model · NexTutor Virtual Laboratory

Enjoyed the experiment? Share it.

It's free — send it to friends from school.

Theory & formulas

Construction

We write the natural numbers in a spiral on a grid and mark the primes.

Visible patterns

The primes line up along clear diagonal lines (rather than chaotically) — a trace of a hidden structure.

Where the lines come from

The diagonals correspond to the values of quadratic polynomials that “produce” many primes, such as Euler's polynomial: n2+n+41n^2+n+41 (it yields primes for n=0,1,…,39n=0,1,\dots,39).

Notation: nn the next natural number, n2+n+41n^2+n+41 Euler's polynomial.

Frequently asked questions

›

How do the primes arrange themselves in the Ulam spiral?

Along visible diagonal lines (patterns), not chaotically — regardless of which number we start the spiral with.

›

What do the lines in the Ulam spiral correspond to?

To quadratic polynomials that generate many primes, such as Euler's polynomial n²+n+41.

›

Who discovered the Ulam spiral?

The Polish mathematician Stanisław Ulam, in 1963 — reportedly by accident, doodling during a lecture.

Teaching? Embed this experiment on your site.

Free widget — paste it on your school site, blog or notes. It links to the full version.

Teaching a class or tutoring? Guide students in NexTutor →