Prime Spiral

Last Updated : 8 Sep, 2026

Prime Spiral, commonly known as the Ulam Spiral, is a graphical representation of prime numbers arranged in a spiral format.

  • The spiral consists of positive integers arranged in a square pattern, with prime numbers specially marked.
  • The visualization reveals clear diagonal, horizontal, and vertical patterns of prime numbers.
  • The number spiral is usually started with 1 at the center, but it can begin with any number.
Ulams-spiral
Small Prime Spiral

When 41 is placed at the center, one diagonal contains an unbroken sequence of 40 consecutive primes. The sequence runs from 1523 (southwest) through 41 (center) to 1601 (northeast).

This is the longest known example of its kind.

Construction

To construct the prime spiral, we can use the following steps:

Step 1: Start by placing the number 1 at the center of a square grid. Proceed to fill the grid in a spiral pattern with subsequent integers (2, 3, 4, etc.)

Step 2: Identify and mark the prime numbers in the spiral. This can be done by circling them or coloring them differently from the composite numbers.

Step 3: Upon marking the primes, striking diagonal lines become apparent, illustrating a non-random distribution of primes within the spiral.

Using these steps we will get, the spiral of numbers with highlighted primes.

General Visual Representation

When visualizing the prime numbers using the Ulam Spiral (or Prime Spiral), if we extend this arrangement infinitely, intriguing patterns emerge, revealing that prime numbers tend to cluster along certain diagonal lines, although no clear formula or rule governs their exact distribution.

This can be seen in the following larger representation of the Ulam spiral.

Prime-Spirals
Prime spiral of size 201 ⨉ 201

Prime Density in the Prime Spiral

Quadratic PolynomialRangePrime Count
n2 - n + 410 to 4040
4n2 - 2n + 410 to 40Approximately 6.6 times the density of random numbers
Comment

Explore