Skip to main content
The new Teacher Workspace is here. Your first 3 assignments are free. Try it →

Sieve of Eratosthenes

The Sieve of Eratosthenes is a prime-finding algorithm used in Combinatorics and number theory. It works by starting with 2 to n and crossing out multiples of each prime, leaving the primes unmarked.

Last updated July 2026

What is the Sieve of Eratosthenes?

The Sieve of Eratosthenes is a systematic way to find all prime numbers up to a chosen limit by eliminating composite numbers in waves. In Combinatorics, it shows up as a clean algorithmic pattern for separating prime and composite structure without checking every number one by one.

You start with the integers from 2 through n. Keep 2, since it is prime, then cross out every multiple of 2 greater than 2. The next unmarked number is 3, so you keep it and cross out every multiple of 3. Then you move to the next unmarked number, which is 5, then 7, and so on. When you finish, the numbers that are still unmarked are exactly the primes.

The reason this works is that every composite number has a prime factor. So if a number is not prime, it will eventually get crossed out when you reach one of its prime divisors. That is why the sieve does not need to test each number directly for primality. It uses the structure of multiples instead.

A small example makes the process easier to see. If you sieve up to 20, you start by crossing out 4, 6, 8, 10, 12, 14, 16, 18, and 20 from the list. Then from 3 you cross out 9, 15, and 18, though 18 is already crossed out. After that, 5 gives 10 and 20, and 7 gives 14. The remaining unmarked numbers are 2, 3, 5, 7, 11, 13, 17, and 19.

One common mistake is to keep crossing out multiples of every unmarked number forever. You only need to continue while the prime you are using is at most the square root of n. Any larger composite number would already have a smaller prime factor, so it would have been removed earlier. That cutoff is part of what makes the sieve efficient.

Why the Sieve of Eratosthenes matters in COMBINATORICS

The Sieve of Eratosthenes matters in Combinatorics because it gives you a fast way to identify primes, and primes sit underneath many counting and number-theory problems. If a problem involves factorization, divisibility, modular arithmetic, or building counting arguments from prime structure, the sieve is a practical tool for getting the prime list first.

It also models a bigger combinatorial habit: instead of checking every object individually, you organize them by a rule and remove the ones that fail. That same thinking shows up in inclusion-exclusion style counting, where you systematically account for overlaps instead of brute-forcing every case.

In algorithmic terms, the sieve is a good example of an efficient procedure with a predictable pattern. You can explain why it works, trace the marking steps, and estimate how long it takes. That makes it useful in homework problems that ask for an algorithm trace, a runtime comparison, or a justification of why a list contains exactly the primes up to n.

It also connects to later ideas like generating primes in large ranges. If the full list does not fit in memory, a segmented version of the sieve keeps the same logic but works on chunks. So the basic sieve is often the first step before more advanced prime-counting or computational number theory methods.

Keep studying COMBINATORICS Unit 5

Official unit cheatsheet

open one-pager

How the Sieve of Eratosthenes connects across the course

Prime Number

The sieve’s output is the list of prime numbers, so you need to know what makes a number prime in the first place. A prime has exactly two positive divisors, 1 and itself, which is why it survives the sieve. The algorithm is really a way of finding every number with that property up to n.

Composite Number

Composite numbers are exactly the values the sieve removes. Each one has a prime factor, which guarantees that it will be crossed out when the sieve reaches one of those prime divisors. If you can explain why a number is composite, you can explain why the sieve marks it.

Algorithm

The sieve is a classic algorithm, meaning it is a step-by-step procedure for solving a problem. In Combinatorics, that matters because many problems are not just about the answer, but about the method. A good solution often includes the steps, the stopping point, and a reason the method is efficient.

k-wise intersections

The sieve is not an intersection-counting method, but it shares a mindset with k-wise intersections: organize objects by overlapping properties and track what remains after repeated filtering. In both settings, the work comes from handling structure carefully instead of treating each case as isolated.

Is the Sieve of Eratosthenes on the COMBINATORICS exam?

A quiz question might give you a number like 50 and ask you to list the primes, show the sieve steps, or explain why a certain number gets crossed out. You would write the starting list, mark multiples of 2, then 3, then the next unmarked primes until you pass the square root of the limit. If the prompt asks for reasoning, you should say that every composite number has a prime factor, so it will be eliminated when that factor is reached.

If the task is about efficiency, compare the sieve to testing primality one number at a time. If the task is about a proof or explanation, focus on why the unmarked numbers are exactly the primes, not just on the mechanics of crossing out multiples.

Key things to remember about the Sieve of Eratosthenes

  • The Sieve of Eratosthenes finds all primes up to n by crossing out multiples of each prime.

  • It works because every composite number has a prime factor, so it will eventually be removed.

  • You only need to sieve up to the square root of n, since larger composites already have smaller factors.

  • The sieve is faster than testing each number separately, which is why it shows up in algorithmic counting work.

  • A clean way to use it is to trace the markings step by step and stop when the next prime squared is bigger than n.

Frequently asked questions about the Sieve of Eratosthenes

What is the Sieve of Eratosthenes in Combinatorics?

It is an algorithm for finding every prime number up to a chosen limit. You begin with the numbers from 2 to n, then cross out multiples of 2, 3, 5, and the other primes in order. The numbers left unmarked are the primes.

How does the Sieve of Eratosthenes work?

The sieve works by removing composite numbers in stages. Each time you reach the next unmarked number, you treat it as prime and cross out its multiples. That process continues until the prime you are using is larger than the square root of the limit.

Why do you only go up to the square root in the sieve?

If a number is composite, it has at least one factor less than or equal to its square root. That means by the time you reach primes up to sqrt(n), every composite number up to n has already been marked. Going past that would only repeat work.

How is the sieve different from checking each number for primality?

Checking each number separately asks, one by one, whether it has any divisors. The sieve flips the process around and marks multiples of primes instead. That is usually much faster when you want all primes in a range, not just one prime test.