The Sieve of Eratosthenes finds every prime up to a limit by repeatedly crossing out the multiples of each prime you find. Whatever survives is prime.
It's elegant, ancient and still one of the fastest ways to generate a list of primes.
How the sieve works
- Write the numbers 2 to N.
- Circle 2 (prime) and cross out every multiple of 2.
- Move to the next un-crossed number (3), circle it, cross out its multiples.
- Repeat. Everything still circled is prime.
A small example up to 30
The survivors are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 — the ten primes below 30. You only need to sieve multiples up to √N.
Why it's efficient
Each composite is crossed out by its prime factors rather than tested individually. This makes the sieve far faster than checking each number for primality when you want all primes in a range.
Sieve vs trial division
Use the sieve to generate many primes at once; use trial division (as in the Prime Number Checker) to test a single number.
- The sieve finds all primes up to N by crossing out multiples.
- Only sieve up to the square root of N.
- It's ideal for generating many primes at once.
- For testing one number, trial division is simpler.
Frequently asked questions
What is the Sieve of Eratosthenes?
An ancient algorithm that finds all prime numbers up to a limit by iteratively crossing out the multiples of each prime.
Why only cross out up to the square root?
Any composite number has a prime factor no larger than its square root, so larger primes have nothing new left to cross out.
Is the sieve faster than checking each number?
For generating all primes in a range, yes — it avoids testing every number individually.
Math educators and engineers building free, accurate calculators with step-by-step solutions, visual diagrams and AI insights.
Related articles
How to Find the LCM: 4 Methods Explained (2026 Guide)
Learn how to find the Least Common Multiple (LCM) using four methods — prime factorization, the GCF formula, l…
How to Find the GCD Using the Euclidean Algorithm
The Euclidean algorithm finds the Greatest Common Divisor in just a few steps. Learn how it works, why it work…
How to Simplify Fractions Fast (Using the GCD)
Simplify any fraction to lowest terms in one step using the Greatest Common Divisor. Learn the method, see wor…