Ulam Spiral Explorer

Primes on a spiral, and stripes nobody ordered.

  • Millions of numbers
  • Sacks spiral and more
  • Prime-rich lines
A sheet of square graph paper with a pencilled square spiral and some squares shaded dark in diagonal streaks, a pencil and an eraser beside it

The guide

The Ulam Spiral Shows Real Stripes in the Primes, and Nobody Has Proved a Single One of Them

A doodle from a dull lecture in 1963 puts the primes on diagonal lines. The lines are quadratic polynomials, the evidence is strong, and the proof is still missing.

  • 1963 Stanislaw Ulam doodles the spiral during a lecture
  • 40 primes in a row on one diagonal when the spiral starts at 41
  • 581 primes among the first 1,000 values of Euler's polynomial
  • 6.6 times chance, the conjectured richness of that line
  • 5,761,455 primes below one hundred million
Read the full guide Fold the guide 7 min · 13 sources

Write the whole numbers in a square spiral, shade the primes, and stripes appear. They run along the diagonals, a few along the rows and columns, and they do not fade as the paper gets bigger. The uncomfortable part is what mathematics can say about them. Every explanation on offer is a conjecture. Not one of those stripes has been proved to go on for ever.

That is the argument of this page: the Ulam spiral is neither an illusion nor a discovery about spirals. It is an honest picture of a real and unproved habit of quadratic polynomials, and the only way to read it responsibly is to count, and to keep a random picture beside it.

A doodle at a dull meeting

Stanislaw Ulam was born in Lemberg, now Lviv, on 13 April 1909 and died in Santa Fe on 13 May 1984. MacTutor’s biography remembers him for the Monte Carlo method and for solving the problem of how to start fusion in the hydrogen bomb. It also records a smaller moment: sitting through a boring lecture, he doodled on a squared notepad, arranged the positive integers in a square spiral, and noticed that the primes seemed to gather on diagonal lines.

Wikipedia’s account, which follows Martin Gardner, dates the doodle to 1963 and the talk to a scientific meeting, where the paper being read was “long and very boring”. The hand drawing covered a few hundred points. Back at Los Alamos, Ulam and his colleagues Myron Stein and Mark Wells put the question to the MANIAC II computer, took the spiral to about 100,000 points, and photographed pictures of up to 65,000 points from a display attached to the machine.

They did something more useful than take pictures. They counted the primes along some of the rich lines and some of the poor ones, among numbers up to 10,000,000. The counting is the part worth copying.

Gardner made the picture famous. He had written the Mathematical Games column in Scientific American since January 1957 and would keep it going for twenty-five years. The March 1964 column described the spiral, and the spiral was on the cover. The usual way of drawing it comes from that cover: 1 in the middle, 2 to its right, 3 above the 2, then round counterclockwise, as the diagram in the OEIS entry for the eastern spoke shows.

Ulam was not first. In 1932 Laurence Klauber, a herpetologist, had shown a triangle of numbers with 1 at the top, 2 to 4 on the second line, 5 to 9 on the third, and so on. He saw the same concentrations in its vertical and diagonal lines, and he connected them to the same polynomials. Gardner acknowledged him in a later addendum.

Why a line is a quadratic

The spiral has a simple secret. Walk outward along any diagonal, row or column and the numbers you meet are the values of a quadratic polynomial, 4n² + bn + c, for whole numbers b and c. When b is even the line is a diagonal. When b is odd it is a row or a column. The spoke that runs east from the 1 reads 1, 2, 11, 28, 53, and its formula is 4n² - 3n + 1.

Half of the pattern is nothing but parity. On a diagonal the numbers are all odd or all even, so the primes after 2 can only live on alternate diagonals. That gives the picture its checkerboard grain, and it is the least interesting thing in it. Any set of odd numbers would do the same.

The interesting part is that the odd diagonals differ. Some are empty for a plain reason. The line 4n² + 8n + 3 equals (2n + 1)(2n + 3), so after its first value it never holds a prime at all. Others are thinned by small divisors. Take 4n² + 6n + 1 and 4n² + 6n + 5 and divide their values by 3. The first never leaves remainder zero. The second does so two times in every three. One line has lost two thirds of its candidates before the question of primality is even asked.

Carry that reasoning through every prime divisor, not only 3, and each line gets its own handicap. A line that dodges many small primes is rich. A line that keeps hitting them is poor. That is the whole mechanism, and it is persuasive. It is also not a proof of anything.

Euler’s line, and a worked count

The best known rich line is older than the spiral by two centuries. Leonhard Euler published the polynomial in 1772. In the form n² + n + 41 it gives a prime for every n from 0 to 39: 41, 43, 47, 53 and on up to 1601. At n = 40 it gives 1681, which is 41 times 41. The number 41 is the largest of six “lucky” numbers with this property, the others being 2, 3, 5, 11 and 17, and the OEIS notes that four times each of them, less one, is a Heegner number. For 41 that number is 163.

On the ordinary spiral this line is split in two. Start the spiral at 41 instead of 1 and it becomes the main diagonal: 40 primes in a row, from 1523 in the south-west through 41 at the center to 1601 in the north-east. Wikipedia calls it the longest example of its kind. In the tool above, choose the example that starts at 41 and the ringed cells show it.

Forty in a row is a stunt. The count over a longer stretch is the evidence. Set the tool’s line to Euler’s polynomial and test the first 1,000 values. It finds 581 primes. Is that a lot? The prime number theorem says that the number of primes up to x is about x divided by its natural logarithm, so a number near x is prime with a chance of about one in ln x. Add that chance over the same thousand values, which run up to 999,041, and random numbers of those sizes would be expected to give 88.0 primes. The ratio is 6.60.

Push the test to a million values and the tool reports 261,081 primes and a ratio of 6.64. The poor line from the last section, 4n² + 6n + 5, scores 0.98 over ten thousand values, and its rich neighbor 4n² + 6n + 1 scores 3.48. Those figures are measurements made by the tool, exact as counts, and anyone can repeat them.

What is proved, and what is not

In 1923 G. H. Hardy and J. E. Littlewood wrote down a guess that fits those measurements. Their Conjecture F says that the number of primes of the form an² + bn + c below a bound grows like a constant A times the count that chance would give. The constant is a product over all primes, built from how many roots the polynomial has modulo each one, which is the handicap argument made exact.

For the diagonal 4n² - 2n + 41, which is every second value of Euler’s polynomial, Wikipedia gives A as about 6.6. The tool’s ratio of 6.6 agrees with it. The record holder, found by Jacobson and Williams, is a polynomial with A near 11.3.

Now the limits. Conjecture F is a conjecture. Hardy and Littlewood also asserted that such a polynomial takes prime values infinitely often unless there is an obvious reason why it cannot, a special case of an older conjecture of Bunyakovsky. That remains open. No quadratic polynomial has ever been proved to produce infinitely many primes, let alone a high density of them. The stripes are observed to the edge of every picture anyone has drawn, and that is all.

So a finite count, however large, proves nothing about the far end of a line. The tool reports a ratio for the stretch it tested and says no more. It tests one number at a time by an exact method and sieves whole ranges exactly, in the manner of Eratosthenes of Cyrene, who lived from 276 BC to 194 BC: strike out the multiples of each prime, starting from its square, and what is left is prime. Below one hundred million that leaves 5,761,455 primes. Exact data does not turn an observation into a theorem.

Telling a stripe from an accident

Eyes find lines in noise. Scatter dots at random and you will see streaks, because short runs are common and the mind promotes them. A picture of the primes therefore needs a control, and the Wikipedia article supplies one: the same spiral with random odd numbers shaded at the density of the primes.

The control in the tool does the same and is a little stricter. It counts the real set in every stretch of 4,096 consecutive numbers and marks exactly that many numbers at random places in the stretch, optionally odd ones only. The density matches everywhere and the total matches exactly. Switch between the two and the difference is plain. The checkerboard grain survives, because it is only parity. The long diagonals do not.

The spiral itself is not sacred. Robert Sacks drew the numbers along an Archimedean spiral in 1994, spaced so that one perfect square falls in each full turn, and on it Euler’s polynomial becomes a single curve instead of two diagonals. Klauber’s triangle turns the same polynomials into vertical lines. Hexagonal spirals show prime-rich lines of their own. The stripes move and bend with the layout and never disappear, which is good evidence that they belong to the numbers.

What the picture cannot do is rank lines by eye, or settle anything about infinity. A stripe that looks dark may only be long. The honest procedure is the one Stein, Ulam and Wells used once they had a machine to do it: pick a line, count its primes, and compare the count with chance.

Sources

Every source consulted for this guide. Links checked October 7, 2026.

  1. Ulam spiral - Wikipedia Wikipedia
  2. Stan Ulam (1909 - 1984) - Biography MacTutor History of Mathematics, University of St Andrews
  3. Martin Gardner (1914 - 2010) - Biography MacTutor History of Mathematics, University of St Andrews
  4. Ulam spiral - OeisWiki The OEIS Foundation
  5. A054552: a(n) = 4*n^2 - 3*n + 1 The On-Line Encyclopedia of Integer Sequences
  6. A005846: Primes of the form k^2 + k + 41 The On-Line Encyclopedia of Integer Sequences
  7. A002837: Numbers k such that k^2 - k + 41 is prime The On-Line Encyclopedia of Integer Sequences
  8. A014556: Euler's "Lucky" numbers The On-Line Encyclopedia of Integer Sequences
  9. A006880: Number of primes < 10^n The On-Line Encyclopedia of Integer Sequences
  10. A056105: First spoke of a hexagonal spiral The On-Line Encyclopedia of Integer Sequences
  11. DLMF: §27.12 Asymptotic Formulas: Primes NIST Digital Library of Mathematical Functions
  12. sieve of Eratosthenes NIST Dictionary of Algorithms and Data Structures
  13. Eratosthenes (276 BC - 194 BC) - Biography MacTutor History of Mathematics, University of St Andrews