b2KIT

Prime Number Sieve Visualizer

Watch the Sieve of Eratosthenes eliminate composites in real time. Explore prime gaps, twin primes, and prime density.

Tested tool guide Tested browser tools Checked August 16, 2026

What Prime Number Sieve Visualizer does, with a checked example

Type an upper bound and watch the Sieve of Eratosthenes work through the numbers in order: 2 strikes out every even, then 3, 5, 7, and so on, until the square of the current prime exceeds the bound and every survivor is prime. The view also tallies prime gaps, twin primes, and the fraction of integers below the bound that are prime. The surprise most users hit: marking starts at the prime's square, not at twice the prime, so a composite like 6 is struck out once, by 2, and never touched again. The run is exact for the chosen bound - nothing is probabilistic.

Worked example

A concrete input and expected output from the current implementation.

Input

Run the sieve with n = 100

Expected output

25 primes survive: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97. Largest prime gap below 100 is 8 (between 89 and 97). There are 8 twin-prime pairs: (3,5), (5,7), (11,13), (17,19), (29,31), (41,43), (59,61), (71,73). Primes make up 25 of the 100 integers from 1 to 100, so density is 0.25.

The sieve strikes out every multiple of 2, then of 3, then of 5, and each later prime; the 25 numbers never struck are exactly the primes below 100, a standard census. The pair 89 and 97 are consecutive primes, and no other consecutive pair in the range is farther apart, which makes 8 the record gap.

How the result is produced

1

The algorithm

All integers from 2 to n start uncrossed. The tool takes the smallest uncrossed number, declares it prime, and crosses out its multiples starting at its square - the multiples below the square already carry a smaller prime factor, so this avoids redundant strikes. The first uncrossed number is then the next prime. Once the current prime's square exceeds n, every remaining uncrossed number is prime.

2

The statistics

Each composite is struck out by its smallest prime factor, and that order is what the animation shows. The overlays read off the result: consecutive-prime gaps, twin pairs (primes two apart), and density, the count of primes divided by n. Density falls toward zero as n grows, following roughly 1/ln(n) by the prime number theorem. Every gap except the first is even, because all primes above 2 are odd.

Good uses

  • Fact-checking a specific number: run the sieve to the candidate and see whether it survives or is struck out, which settles primality for that value without trusting a random online list.
  • Teaching the algorithm: a classroom or tutorial can watch the elimination order and the square-starting rule, the step most written explanations skip, then pause the run to count what got crossed out.
  • Small-scale number theory: count twin pairs under a bound, compare the largest prime gap as the bound climbs, or check whether the density you see at 1,000 roughly matches 1/ln(1,000) at the next step.

Limits and checks

  • Bound inclusion: sieving to n covers the integers from 1 to n, and 1 is never counted as prime. A density of 25 for n = 100 means 25 primes among all 100 integers, so the denominator includes 1 and the composites, not just the tested numbers.
  • Scale and memory: an animated run performs one strike per multiple, so very large bounds can stall the animation or the tab. Everything computes locally in the browser, so a bigger bound costs memory and time rather than a server round trip; the statistics are still exact for any range the page manages to finish.
  • Range-bound records: the displayed largest gap is the maximum over consecutive primes below your bound only, and it grows erratically - the record gap under 100 is 8, while under 200 it is 14. Read it as a fact about the chosen range, not about primes in general.

Common questions

Why does the animation skip over some multiples - isn't the sieve supposed to mark everything?

Every composite is struck exactly once, by its smallest prime factor. Marking starts at p squared: multiples like 2p, 3p, and so on up to (p-1)p were already struck out when their smaller prime factor was processed, so re-marking them would waste a step. The order you see is therefore the order composites first acquire a factor, which is why 6 vanishes at the 2 pass, not at 3.

Does a bigger bound ever change what the sieve proves?

The sieve's verdict is exact at every size it can finish: survivors below n are precisely the primes below n. What shifts with scale is the picture - density keeps falling (about one integer in ln(n) is prime, per the prime number theorem), and record gaps grow. Unproven claims such as whether twin primes continue forever are separate from its output and are not settled by any run.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools