Ulam Spiral
Make an Ulam spiral: write the whole numbers on a square spiral, 1 in the middle, 2 to its right, then round and round, and shade the primes. The tool draws grids from 3 × 3 to 501 × 501 (251,001 numbers), with the numbers in the cells for worksheets up to 51 × 51, any start number, either direction and any first step. Primes come from an exact sieve, and you can shade twin primes instead, or nothing at all for a find-the-primes worksheet. Highlight any quadratic a·n² + b·n + c to see its cells, with a check of whether they lie on one straight line, switch to the Sacks spiral, or type a number to find its cell. Download a PDF, a 300 DPI PNG or an SVG. Nothing is uploaded.
100% private — everything runs in your browser. Everything runs in your browser; nothing is uploaded.
Print at 100% (Actual size). Real size prints on one sheet when the drawing fits; the check bar in the footer lets you confirm the scale. The SVG holds the drawing at the printed size.
Spiral
Highlight a quadratic a·n² + b·n + c
Find a number
Page
Runs in your browser with our own code: nothing you type is uploaded or saved. Every cell, prime and line is worked out by our own code (an exact sieve and whole-number geometry). You may use what you make here, including commercially, with no credit needed.
How to make an Ulam spiral
- Pick a preset, or choose the layout: the Ulam square spiral or the Sacks spiral.
- Set the size, the start number, the direction and what to shade.
- Turn on the numbers and grid for a worksheet, or the quadratic highlight to see a line.
- Choose Fitted to one page or Real size and the paper.
- Download the PDF and print at 100% (Actual size), or the PNG or SVG.
What you can use it for
- Maths lessons: primes, squares and quadratic sequences
- Find-the-primes worksheets with numbered cells
- Posters and classroom displays
- Number-pattern projects
- Plotter, laser and vinyl art from the SVG
- Checking where a number lands on the spiral
The 15 presets
| Preset | Layout | Numbers | Shaded | |
|---|---|---|---|---|
| Numbers 1–121 on an 11 × 11 grid, primes shaded | square, 11 × 11 | 1–121 | 30 primes | fitted |
| Worksheet: 1–225 on 15 × 15, nothing shaded (find the primes yourself) | square, 15 × 15 | 1–225 | nothing | fitted |
| Numbers 1–441 on 21 × 21, primes shaded | square, 21 × 21 | 1–441 | 85 primes | fitted |
| 201 × 201 cells (1–40,401), primes in black | square, 201 × 201 | 1–40,401 | 4,236 primes | fitted |
| 401 × 401 cells (1–160,801), primes in navy | square, 401 × 401 | 1–160,801 | 14,752 primes | fitted |
| 501 × 501 cells (1–251,001), the largest | square, 501 × 501 | 1–251,001 | 22,115 primes | fitted |
| Start at 41: n² + n + 41 highlighted, 41 × 41 | square, 41 × 41 | 41–1,721 | 256 primes | fitted |
| 4n² − 2n + 41 highlighted, 101 × 101 | square, 101 × 101 | 1–10,201 | 1,252 primes | fitted |
| Twin primes only, 151 × 151 | square, 151 × 151 | 1–22,801 | 771 twin primes | fitted |
| Clockwise, first step up: 1–225, numbered | square, 15 × 15 | 1–225 | 48 primes | fitted |
| Round dots for primes, 61 × 61 | square, 61 × 61 | 1–3,721 | 519 primes | fitted |
| Real size: 9 × 9 at 15 mm cells, numbered, nothing shaded | square, 9 × 9 | 1–81 | nothing | real size |
| Sacks spiral, 1–10,000, primes as dots | Sacks spiral | 1–10,000 | 1,229 primes | fitted |
| Sacks spiral, 1–2,500, perfect squares marked (on the +x axis) | Sacks spiral | 1–2,500 | 367 primes | fitted |
| Sacks spiral, 1–50,000, fine dots | Sacks spiral | 1–50,000 | 5,133 primes | fitted |
Every count is worked out by the tool from the cells it draws.
Where the numbers go: the rings
| Ring | Numbers | How many | Cell of the last number | Every cell checked |
|---|---|---|---|---|
| 0 | 1 | 1 | (0, 0) | yes |
| 1 | 2–9 | 8 | (1, −1) | yes |
| 2 | 10–25 | 16 | (2, −2) | yes |
| 3 | 26–49 | 24 | (3, −3) | yes |
| 4 | 50–81 | 32 | (4, −4) | yes |
| 5 | 82–121 | 40 | (5, −5) | yes |
| 6 | 122–169 | 48 | (6, −6) | yes |
| 7 | 170–225 | 56 | (7, −7) | yes |
| 8 | 226–289 | 64 | (8, −8) | yes |
Ring k holds 8k numbers and ends at (k, −k), the bottom right corner, with (2k + 1)², an odd square. The cells use x to the right and y up, with 1 at (0, 0).
How many primes on each grid
| Grid | Numbers (from 1) | Primes | Share |
|---|---|---|---|
| 11 × 11 | 121 | 30 | 24.79% |
| 21 × 21 | 441 | 85 | 19.27% |
| 51 × 51 | 2,601 | 378 | 14.53% |
| 101 × 101 | 10,201 | 1,252 | 12.27% |
| 201 × 201 | 40,401 | 4,236 | 10.48% |
| 501 × 501 | 251,001 | 22,115 | 8.81% |
The sieve checked against published counts
| Up to | Primes found by the tool | Published count | Same |
|---|---|---|---|
| 1,000 | 168 | 168 | yes |
| 100,000 | 9,592 | 9,592 | yes |
| 1,000,000 | 78,498 | 78,498 | yes |
The published counts are from the prime-counting function table on Wikipedia (read 12 November 2026).
Quadratic lines
| Quadratic | Start number | Grid | Cells | Primes among them | On one straight line |
|---|---|---|---|---|---|
| n² + n + 41 | 41 | 41 × 41 | 41 | 40 | from n = 0 |
| 4n² − 2n + 41 | 1 | 101 × 101 | 51 | 44 | from n = 20 |
| 4n² + 2n + 41 | 1 | 101 × 101 | 51 | 44 | from n = 20 |
| 4n² − 2n + 1 | 1 | 101 × 101 | 51 | 17 | from n = 0 |
| 4n² + 1 | 1 | 101 × 101 | 51 | 18 | from n = 0 |
| n² + n + 41 | 1 | 101 × 101 | 101 | 87 | no |
The straight-line check uses whole-number cross products on the cells the tool draws.
Sacks spiral: the squares on one line
| k | k² | Angle 2π√n | x (r = √n) | y |
|---|---|---|---|---|
| 1 | 1 | 360° | 1 | 0 |
| 2 | 4 | 720° | 2 | 0 |
| 3 | 9 | 1080° | 3 | 0 |
| 4 | 16 | 1440° | 4 | 0 |
| 5 | 25 | 1800° | 5 | 0 |
| 6 | 36 | 2160° | 6 | 0 |
Each perfect square k² is a whole number of turns round, so it lands on the positive x axis at distance k.
What prints
| Download | What is in it |
|---|---|
| The spiral fitted to one page or at real size, vector, with the counts and a check bar | |
| PNG 300 DPI | The same sheet as a picture |
| SVG | The spiral at the printed size: shaded cells as one path, every dot as an exact circle, the numbers as text |
For a cutter that needs DXF, use SVG to DXF.
Which tool to use
| You want | Use |
|---|---|
| Primes on a square or Sacks spiral, numbered worksheets | Ulam Spiral (this page) |
| Seeds placed by the golden angle | Phyllotaxis |
| Mandelbrot, Julia and line fractals | Fractal Generator |
| Square grids for your own number charts | Graph Paper |
| Numbers in base 2, 3 or 16 | Number Base Converter |
Other tools: the Fractal Generator renders Mandelbrot, Julia and line fractals, Graph Paper prints grids and the Number Base Converter writes numbers in other bases.
More free tools
Geometry, patterns and printables?
Drawing and print tools that run privately in your browser, with no sign-up and no watermark.
Frequently asked questions
What is the Ulam spiral?
The whole numbers written on a square spiral with the prime numbers marked. It was devised by the mathematician Stanisław Ulam in 1963 and made popular by Martin Gardner’s Mathematical Games column in Scientific American in March 1964. It is also called the prime spiral.
How is it built?
1 goes in the centre, 2 to its right, 3 above 2, and the numbers carry on anticlockwise in square rings. Ring k holds the numbers (2k − 1)² + 1 to (2k + 1)², so ring 1 holds 2 to 9 and ring 2 holds 10 to 25, and each ring ends at the bottom right corner. The table below shows the first rings; our tests check the cell of every number up to 251,001 against a step-by-step walk.
Why do diagonal lines show up?
Lines in the spiral are the values of quadratic polynomials, as Ulam and Gardner noted, and some quadratics give many primes. The tool marks the primes with an exact sieve; it does not predict them. Turn on the quadratic highlight to see which cells a polynomial such as 4n² − 2n + 41 lands on.
What happens if I start at 41?
Then Euler’s polynomial n² + n + 41 runs along one diagonal through the centre, and its first 40 values (n = 0 to 39) are all prime, as the tool counts (40 of 40). The next value, n = 40, is 1,681 = 41 × 41, which is not.
Does 4n² − 2n + 41 lie on a straight line?
On a spiral that starts at 1, its cells lie on one straight line from n = 20 on. For smaller n the number is too close to the corner of its ring and the cells wrap round the corner. The tool works out from which n the highlighted cells are on one line, with exact whole-number geometry, and draws the line only through those cells.
What are twin primes?
Two primes that differ by 2, such as 11 and 13 or 17 and 19. Choose Twin primes to shade only the primes that have a twin.
What is the Sacks spiral?
A variant devised by Robert Sacks in 1994: the number n is placed at distance √n from the centre and angle 2π√n, so the numbers run along an Archimedean spiral with one perfect square per turn, and the squares 1, 4, 9, 16 … all land on the same line to the right of the centre. Turn on Mark the perfect squares to see them.
How do I know the primes are right?
They come from a sieve of Eratosthenes. Our tests check it against a written-out list of the 168 primes below 1,000, against trial division for every number the spiral can show (up to 261,002), and against the published counts of 9,592 primes below 100,000 and 78,498 below 1,000,000.
How big can it go?
The square spiral goes up to 501 × 501 (251,001 numbers) and the Sacks spiral up to 100,000 numbers; every preset draws in under 2 seconds in our tests. Numbers inside the cells work up to 51 × 51, where they are still large enough to read on a printed page.
Can it print at real size?
Yes, when the drawing fits on one sheet: choose Real size and set the cell size (Ulam), the diameter (Sacks) or the spacing c and seed size (phyllotaxis). Every printed cell, dot and seed is within 0.2 mm of its true place and size in our tests, on US Letter and A4, as long as you print at 100% (Actual size); the check bar in the footer lets you confirm the scale. Bigger drawings print fitted to the page.
Is it free?
Yes. There is no sign-up, no watermark and no limit.
Is anything uploaded?
No. Every number, cell and seed is worked out by JavaScript in your browser. Nothing you type is sent anywhere or saved when you close the page.