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.

100% private — runs in your browser

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

  1. Pick a preset, or choose the layout: the Ulam square spiral or the Sacks spiral.
  2. Set the size, the start number, the direction and what to shade.
  3. Turn on the numbers and grid for a worksheet, or the quadratic highlight to see a line.
  4. Choose Fitted to one page or Real size and the paper.
  5. 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

PresetLayoutNumbersShadedPrint
Numbers 1–121 on an 11 × 11 grid, primes shadedsquare, 11 × 111–12130 primesfitted
Worksheet: 1–225 on 15 × 15, nothing shaded (find the primes yourself)square, 15 × 151–225nothingfitted
Numbers 1–441 on 21 × 21, primes shadedsquare, 21 × 211–44185 primesfitted
201 × 201 cells (1–40,401), primes in blacksquare, 201 × 2011–40,4014,236 primesfitted
401 × 401 cells (1–160,801), primes in navysquare, 401 × 4011–160,80114,752 primesfitted
501 × 501 cells (1–251,001), the largestsquare, 501 × 5011–251,00122,115 primesfitted
Start at 41: n² + n + 41 highlighted, 41 × 41square, 41 × 4141–1,721256 primesfitted
4n² − 2n + 41 highlighted, 101 × 101square, 101 × 1011–10,2011,252 primesfitted
Twin primes only, 151 × 151square, 151 × 1511–22,801771 twin primesfitted
Clockwise, first step up: 1–225, numberedsquare, 15 × 151–22548 primesfitted
Round dots for primes, 61 × 61square, 61 × 611–3,721519 primesfitted
Real size: 9 × 9 at 15 mm cells, numbered, nothing shadedsquare, 9 × 91–81nothingreal size
Sacks spiral, 1–10,000, primes as dotsSacks spiral1–10,0001,229 primesfitted
Sacks spiral, 1–2,500, perfect squares marked (on the +x axis)Sacks spiral1–2,500367 primesfitted
Sacks spiral, 1–50,000, fine dotsSacks spiral1–50,0005,133 primesfitted

Every count is worked out by the tool from the cells it draws.

Where the numbers go: the rings

RingNumbersHow manyCell of the last numberEvery cell checked
011(0, 0)yes
12–98(1, −1)yes
210–2516(2, −2)yes
326–4924(3, −3)yes
450–8132(4, −4)yes
582–12140(5, −5)yes
6122–16948(6, −6)yes
7170–22556(7, −7)yes
8226–28964(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

GridNumbers (from 1)PrimesShare
11 × 111213024.79%
21 × 214418519.27%
51 × 512,60137814.53%
101 × 10110,2011,25212.27%
201 × 20140,4014,23610.48%
501 × 501251,00122,1158.81%

The sieve checked against published counts

Up toPrimes found by the toolPublished countSame
1,000168168yes
100,0009,5929,592yes
1,000,00078,49878,498yes

The published counts are from the prime-counting function table on Wikipedia (read 12 November 2026).

Quadratic lines

QuadraticStart numberGridCellsPrimes among themOn one straight line
n² + n + 414141 × 414140from n = 0
4n² − 2n + 411101 × 1015144from n = 20
4n² + 2n + 411101 × 1015144from n = 20
4n² − 2n + 11101 × 1015117from n = 0
4n² + 11101 × 1015118from n = 0
n² + n + 411101 × 10110187no

The straight-line check uses whole-number cross products on the cells the tool draws.

Sacks spiral: the squares on one line

kk²Angle 2π√nx (r = √n)y
11360°10
24720°20
391080°30
4161440°40
5251800°50
6362160°60

Each perfect square k² is a whole number of turns round, so it lands on the positive x axis at distance k.

What prints

DownloadWhat is in it
PDFThe spiral fitted to one page or at real size, vector, with the counts and a check bar
PNG 300 DPIThe same sheet as a picture
SVGThe 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 wantUse
Primes on a square or Sacks spiral, numbered worksheetsUlam Spiral (this page)
Seeds placed by the golden anglePhyllotaxis
Mandelbrot, Julia and line fractalsFractal Generator
Square grids for your own number chartsGraph Paper
Numbers in base 2, 3 or 16Number 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.

See all free tools →

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.