Skip to content

The sieve of Eratosthenes animated: a step-by-step grid and primes hopping in arcs, with video export.

Arc colour: small primes blue, large primes goldTap a prime on the line to light its hops
Numbers up to

Each prime hops up the line by its own size, in half circles, and lands on every one of its multiples. The heads of all the hops climb together, so when they reach a number no hop has landed on, it is prime and starts hopping too. The bigger the prime, the bigger its arcs: together they make a cone.

Keys: Space plays and pauses, ← and → move one number, Shift with an arrow jumps to the next prime.

Press a prime to light its hops on the line.

None yet: press Play.
Shape
TikTok, Reels, Shorts
Video length

The video is the whole sieve from the start, drawn frame by frame at full size in your browser, with what happens written on it. The PNG is the moment on screen now, at twice the size. No watermark.

Found it useful? or .

What is the sieve of Eratosthenes?

The sieve of Eratosthenes is the oldest and simplest way to find all the prime numbers up to a limit. Write the numbers from 2 to n. The first one, 2, is prime: cross out all its multiples. The next number not crossed out, 3, is prime: cross out its multiples. Keep going. When the next prime squared is bigger than n, stop: every number still standing is prime. It is named after Eratosthenes of Cyrene, the Greek mathematician who also measured the size of the Earth, around 240 BC.

This page animates the sieve two ways. The Grid is the classic picture from the classroom: the numbers 1 to 100 (or up to 1000) in rows, each prime in its own colour, and its multiples crossed out one by one in that colour while a sentence under the picture says what happens. The Number line is a new way to see the same idea: every prime hops up the line by its own size, in half circles, landing on each of its multiples, and together the hops build a cone of arcs. Both play on their own, can be paused and stepped, and save as a PNG or a video.

Sieve of Eratosthenes as arcs: every prime hopping up a number line by its own size, building a cone of coloured arcs, made with the Sieve of Eratosthenes tool
Sieve of Eratosthenes as arcs: every prime hopping up a number line by its own size, building a cone of coloured arcs, made with the Sieve of Eratosthenes tool

How the sieve of Eratosthenes works, step by step

  1. List the numbers from 2 to n. 1 is not prime and is left out.
  2. Take the first number not crossed out. At the start it is 2. It is prime, because no smaller prime divides it.
  3. Cross out its multiples, starting from its square: 4, 6, 8, 10 … for 2; 9, 12, 15 … for 3. The multiples below the square are already crossed out by smaller primes (6 by 2, for example).
  4. Repeat with the next number not crossed out: 3, then 5, then 7.
  5. Stop when the prime squared is bigger than n. For n = 100 that is after 7, because 11 × 11 = 121. Every number left is prime: there are 25 primes up to 100.

Why start crossing out at p²? Any smaller multiple of p, say k × p with k < p, has a prime factor smaller than p, so it was crossed out when that smaller prime had its turn. And why stop at √n? A composite number up to n always has a prime factor no bigger than √n, so by then every composite is gone.

Worked example: the primes up to 30

Write 2 to 30. Start with 2: it is prime, so cross out 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28 and 30. The next number still standing is 3: it is prime, so cross out from 9 in steps of 3: 9, 12, 15, 18, 21, 24, 27, 30. Six of those were already gone because they are even; only 9, 15, 21 and 27 are new. The next number standing is 5: cross out from 25, so 25 and 30, and only 25 is new.

The next number standing is 7, and 7 × 7 = 49 is already past 30, so the sieve is finished. The numbers left are 2, 3, 5, 7, 11, 13, 17, 19, 23 and 29: ten primes up to 30. Set the grid to 30 and press the step button to follow exactly these moves, one crossing-out at a time, with the sentence under the picture saying which ones were already crossed out.

Common mistakes when doing the sieve by hand

The most common slip is to treat 1 as a prime; it is not, and it is never used to cross anything out, or every number would vanish. The second is to keep going after √n: once the prime you reach has a square bigger than n, there is nothing left to cross out, and continuing only wastes time. The third is to cross out the prime itself along with its multiples. Start at 2p, or better at p², never at p. Finally, a number crossed out twice is not a problem: 12 is a multiple of both 2 and 3, and it does not matter which one gets there first.

Other sieves for finding primes

The segmented sieve runs the same algorithm on one block of numbers at a time, so it can find primes up to billions with little memory, using only the primes up to √n to cross out each block. The sieve of Sundaram works only with odd numbers, crossing out every number of the form i + j + 2ij and turning each one left, k, into the prime 2k + 1. The sieve of Euler (the linear sieve) crosses out each composite exactly once, by its smallest prime factor, and runs in O(n) time. The sieve of Atkin uses quadratic forms and is faster in theory for very large limits. For learning and for limits up to tens of millions, the sieve of Eratosthenes is still the clearest and, in practice, about as fast as any of them.

A small trick halves the work: since 2 is the only even prime, sieve only the odd numbers and add 2 at the end. The Prime Spiral on this site does exactly that to find the 2.4 million primes below 40 million in about half a second.

How to use the Sieve of Eratosthenes tool

  1. Pick a picture. Number line for the hopping arcs, or Grid for the classic table. Both start playing at once.
  2. Choose how far to sieve. In Sieve, set the numbers up to 100, 250, 500, 1000 or 2000 on the number line, or 30, 100, 200, 500 or 1000 on the grid.
  3. Go at your own pace. Pause, then use the step buttons (or the left and right arrow keys) to move one number or one crossing-out at a time. Drag the Progress slider to jump, and change the speed from ½× to 4×.
  4. Ask about a number. On the grid, hover a number to see its prime factors, such as 91 = 7 × 13, and tap it to outline all its multiples.
  5. Keep the primes. The Primes found list grows as the sieve runs; Copy puts every prime up to your limit on the clipboard.
  6. Save it. In Save, choose 9:16, 16:9 or 1:1 and make a video of the whole sieve, or save the current moment as a PNG.

The sieve as arcs on a number line

On the number line every prime p jumps forward by p again and again: from p to 2p, from 2p to 3p, and so on, each jump drawn as a half circle of diameter p. A number that one of these hops lands on is a multiple of a smaller prime, so it is composite. All the hops climb together, at the same pace as the front that reaches each new number, so when the front reaches a number that no hop has landed on, nothing smaller divides it: it is prime, it lights up, and it starts hopping too.

Because a prime's arcs are as wide as the prime is large, small primes draw many tight loops near the line and large primes draw a few wide ones. Together they fill a cone whose edge rises at a steady slope, since the biggest arc at any height is about half that height. The colours run from blue for the smallest primes to gold for the largest. It is the same algorithm as the grid, only every crossing-out is drawn as a jump; with 2000 numbers you see more than 4000 hops at once.

Why is the sieve of Eratosthenes efficient?

The sieve never divides. It only adds: to cross out the multiples of p it steps p at a time. The total work up to n is about n × log log n steps, which grows barely faster than n itself, so finding all primes up to ten million takes a fraction of a second on a laptop. Checking each number on its own by trial division would take far longer. The price is memory: the sieve keeps one mark for every number up to n, which is why very large ranges are sieved in segments.

Many numbers are crossed out more than once. 12 is crossed out by 2 and again by 3; the grid shows the second time briefly and says "already crossed out by 2". In the grid each number keeps the colour of the first prime that crossed it out, which is always its smallest prime factor.

Sieve of Eratosthenes in code

The whole algorithm fits in a few lines. In JavaScript: const composite = new Uint8Array(n + 1); for (let p = 2; p * p <= n; p++) if (!composite[p]) for (let m = p * p; m <= n; m += p) composite[m] = 1; Every index from 2 to n still at 0 is prime. The same loop is used by this page, and by the Prime Spiral to find millions of primes in a moment.

For teachers and students

Put the grid on a projector with 1 to 100, pause after each prime and ask the class which numbers will go next; the step button moves one crossing-out at a time. The 16:9 video drops into slides, and the 9:16 video is ready for a class TikTok or Reel. Students can check a hand-made 100 square against the Primes found list: there are 25 primes up to 100, 46 up to 200, 95 up to 500 and 168 up to 1000.

More about primes

Once the primes are found, see what they look like in the Prime Spiral, where each prime p sits at distance p and angle p radians and millions of them form spiral arms and 280 rays. The Riemann Hypothesis Visualizer shows how the zeros of the zeta function rebuild the count of primes.

Frequently Asked Questions

What is the sieve of Eratosthenes in simple words?

It is a way to find all primes up to a number: list the numbers, and for each prime in turn cross out its multiples. The numbers never crossed out are the primes.

When do you stop the sieve of Eratosthenes?

When the next prime squared is larger than the last number. For 1 to 100 you only need the primes 2, 3, 5 and 7, because 11² = 121 is more than 100.

How many primes are there up to 100?

25: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89 and 97. Up to 1000 there are 168.

Why is 1 not a prime number?

A prime has exactly two divisors, 1 and itself, and 1 has only one. Leaving 1 out also keeps the fact that every number splits into primes in exactly one way.

What is the time complexity of the sieve of Eratosthenes?

O(n log log n) time and O(n) memory for the numbers up to n.

Who invented the sieve of Eratosthenes?

It is credited to Eratosthenes of Cyrene, a Greek scholar of the 3rd century BC, through a description by Nicomachus of Gerasa written some 300 years later.

Can I save the animation as a video?

Yes. Open Save, choose a shape (9:16 for TikTok and Reels, 16:9 for YouTube and slides, 1:1 for posts) and a length, and press Make video. It is made in your browser as an MP4, with no watermark.