Sieve of Eratosthenes Calculator

List every prime up to a chosen number using the ancient crossing out method.

Math and PercentUpdated 2026-11-203 min read
Sieve of Eratosthenes Calculator
Whole numbers from 2 to 10,000. The sieve lists primes up to and including this value.
Prime numbers
...
How many primes...
Largest prime...

What it does

The sieve of Eratosthenes is a way to find all prime numbers up to a chosen limit. Eratosthenes of Cyrene described it in the third century BC, and the method is still taught because it is simple and fast for moderate limits.

Write the numbers from 2 up to n in order. Cross out every second number after 2, then every third number after 3, then every fifth number after 5, and so on. The numbers that survive are prime, since any composite number has a factor smaller than itself and is crossed out when that factor is reached.

You only need to use seeds up to the square root of n. Once a prime is larger than the square root, its square is beyond the limit, so all of its multiples have already been removed by smaller primes. This is what keeps the work short.

This tool runs the sieve on the limit you enter and returns the full list, the count and the largest prime. The work happens in your browser and the list is bounded at 10,000 entries so the page stays responsive.

The sieve is a listing method, not a primality test for one huge number. For a single large integer, a test such as Miller-Rabin is the right tool.

How to use

  1. Enter a whole-number limit from 2 to 10,000.
  2. Read the main result to see the primes in ascending order.
  3. Check the count against the table below for a quick sanity check on common limits.
  4. Look at the largest prime, which is often close to but not equal to the limit.
  5. Try 30 to reproduce the ten primes in the worked example.
  6. Increase the limit gradually when exploring patterns, since very long lists are harder to scan.

Formula

Mark all multiples of each prime p from p² up to n, for every p with p² <= n. The unmarked integers from 2 to n are prime.
n
The upper limit, an integer from 2 to 10,000.
p
A prime used as a crossing out seed.
p²
The first multiple of p that has not already been crossed out by a smaller prime.
n/p
The number of multiples of p inside the range, which bounds the inner loop.

The engine uses a boolean array indexed by the integers up to n. It skips marking when a value has already been crossed out, which keeps the total work close to n times the sum of one over each prime. The square root bound appears as the loop condition i times i <= n.

Worked example

Example: primes up to 30

Enter 30 as the upper limit and list the primes up to and including 30.

  1. Start with the integers 2 through 30 marked as candidates.
  2. Seeds only need to run while p squared is at most 30, so p = 2, 3 and 5 are enough.
  3. Cross out multiples of 2 starting at 4: 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28 and 30.
  4. Cross out multiples of 3 starting at 9: 9, 12, 15, 18, 21, 24, 27 and 30.
  5. Cross out multiples of 5 starting at 25: 25 and 30. Some were already gone.
  6. The survivors are 2, 3, 5, 7, 11, 13, 17, 19, 23 and 29.
  7. The tool reports 10 primes with largest prime 29.

Reference table

Prime counts for common sieve limits
Limit nPrimes up to nLargest prime
1047
20819
301029
501547
1002597
1000168997

Limits

  • The list is capped at 10,000 so the page does not freeze on very large ranges.
  • This is a non cryptographic method. It is not suitable for testing one 100 digit integer.
  • The sieve assumes ordinary integers. It does not handle fractions, negatives or decimals.
  • Counts in the table are for the inclusive limit, so 100 includes the prime 97 and not 101.

Common mistakes

  • Starting the crossing out at p instead of p squared, which does extra work without changing the answer.
  • Running seeds past the square root of the limit, which repeats work already done.
  • Forgetting that 1 is not prime and must be removed before counting.
  • Assuming every odd survivor is prime even after a seed has been skipped.
  • Reading the count as the number of primes below n when the tool includes n itself when prime.

Try it yourself

Quick checks. Answers sit tucked under each question.

How many primes are there up to 30?

10. They are 2, 3, 5, 7, 11, 13, 17, 19, 23 and 29, with 29 the largest.

Which seeds do you need for n = 50?

2, 3, 5 and 7. The next prime 11 has a square of 121, which is above 50.

How many primes are below 100?

25. The largest is 97.

Questions

Who invented the sieve of Eratosthenes?

Eratosthenes of Cyrene, a Greek scholar working in the third century BC. Britannica describes the same crossing out procedure.

Why start crossing out at p squared?

Smaller multiples of p were already crossed out when earlier primes were processed, so starting at p squared avoids repeated work.

Is 1 a prime number?

No. The sieve removes 1 before marking multiples, and 1 is excluded from the count.

What is the largest input the tool accepts?

10,000. That keeps the list readable and the calculation instant in a browser.

Does the sieve find primes beyond the limit?

No. It returns exactly the primes from 2 up to the number you enter.

When should I use a primality test instead?

When you have one specific large number to check. The sieve is built for listing all primes in a range.

Sources

How this page was checked. The formula above was matched against the cited sources, and the worked example was run through the tool on this page before publishing. If you spot an error, contact us so we can fix it and note the correction.