The Sieve of Eratosthenes is an ancient and efficient algorithm used to find all prime numbers up to a given integer n. It was developed by the Greek mathematician Eratosthenes around 240 BCE. It is used in number theory ,cryptography and computer science for solving prime-related problems efficiently.
The functioning, importance, applications, and potential for efficient problem-solving of this algorithm will all be covered in this article.
Sieve of Eratosthenes Working

Follow the steps below to find the prime numbers up to n (n = 20 in our case)
- Initialization: List numbers from 2 to n. Assume all are prime initially.
- Start with 2: Mark 2 as prime. Cross out its multiples (e.g., 4, 6, 8, ...).
- Next unmarked number: Go to the next unmarked number (e.g., 3). Mark it as prime and cross out its multiples (e.g., 9, 12, ...).
- Repeat: Continue with each subsequent unmarked number (e.g., 5, 7, 11, ...).
- Stop at √n: For n = 20, √20 ≈ 4.47, so you only need to check numbers up to 4 (i.e., 2 and 3 in this case). Beyond that, remaining unmarked numbers are automatically prime.
Result – The Prime Numbers up to 20: 2, 3, 5, 7, 11, 13, 17, 19
Prime Number up to 100
Here's how the Sieve of Eratosthenes works for numbers up to 100.

Given:- N is 100
The procedure of marking the prime numbers between 1 and 100 is as described below:
Step 1: Write numbers from 1 to 100 in grid.
Step 2: Cross out 1 (not prime).
Step 3: Circle 2 (prime) and cross all its multiples.
Step 4: Circle 3 and cross all its multiples.
Step 5: Continue:
- Circle 5, cross its multiples.
- Circle 7, cross its multiples.
- Circle 11, cross its multiplies
Step 6: Continue until you've processed all numbers up to √100 (i.e 10). After that, all remaining uncrossed numbers in the list are primes.
So, The circled numbers are the prime numbers from 1 to 100 are {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.}
Sieve of Eratosthenes Uses & Example
The Sieve of Eratosthenes is important because it provides a fast and simple way to find all prime numbers up to a given limit. Its efficiency makes it ideal for use in many computer algorithms where prime numbers are needed. It is used in different fields like:
Computer Science: Used in hash functions, random number generators, and olving problems in algorithms.
Cryptography: Helps in creating large prime numbers for secure systems like RSA..
Mathematics: Acts as a core tool in number theory. Helps in studying the distribution of primes, prime factorization, and mathematical proofs involving primes.
Signal Processing: Helps in building systems that send and receive signals.
Engineering: Used in error-checking, networks, and digital design.
Practice Problem Based On Seive of Eratosthenes
Question 1. Find all the prime numbers between 1 and 30.
Question 2. Find all the prime numbers between 1 and 75.
Question 3. List all the prime numbers up to 120 using the Sieve of Eratosthenes method.
Question 4. List all the prime numbers up to 40 using the Sieve of Eratosthenes method.
Answer:-
- 2, 3, 5, 7, 11, 13, 17, 19, 23, 29
- 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73.
- 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, 101, 103, 107, 109, 113.
- 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37
Also Read
- Sieve of Eratosthenes in Programming
- Practice the Concept: Try implementing it with code – {Practice}