Skip to main content
Mathematics LibreTexts

4.3: The Sieve of Eratosthenes

  • Page ID
    163863
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)

    Imagine a clever way to find all the hidden treasure (prime numbers) on a number island. That's exactly what the Sieve of Eratosthenes does! This ingenious method, named after the ancient Greek mathematician Eratosthenes who lived over 2,200 years ago, is like a number detective's toolkit. It helps us discover all the prime numbers up to any limit we choose.

    What makes the Sieve of Eratosthenes special is its simplicity and visual nature. Picture crossing off numbers on a giant calendar - that's essentially how it works! While mathematicians have developed other ways to identify prime numbers, the Sieve remains a favorite for its intuitive approach and its ability to find all primes within a range, not just determine if a single number is prime.

    This method isn't just an old relic - it's a powerful tool that can spark curiosity and deepen understanding of numbers in your future classroom. It turns abstract math into a fun, hands-on adventure that your students will remember!

    The Sieve of Eratosthenes Algorithm

    The Sieve of Eratosthenes is an efficient algorithm for finding all prime numbers up to a given limit. Here's a step-by-step breakdown of the algorithm:

    1. Create a list:
      • Start with a list of all integers from 2 to your chosen limit, n.
      • Initially, consider all numbers in this list as potential primes.
    2. Start with the first prime number, 2:
      • 2 is the smallest and first prime number.
    3. Mark multiples as composite:
      • Starting from 2^2 = 4 (as 2 * 2 is the first multiple of 2 that hasn't been crossed off yet), mark every multiple of 2 up to n as composite (not prime).
      • You can do this by counting in steps of 2 from 4 to n.
    4. Find the next unmarked number:
      • The next unmarked number in the list is prime.
      • In this case, it would be 3.
    5. Repeat the marking process:
      • Again, mark all multiples of this number (3 in this case) as composite.
      • Start from 3^2 = 9 (as all smaller multiples of 3 have already been marked by smaller primes), and count in steps of 3 up to n.
    6. Continue the process:
      • Keep repeating steps 4 and 5 until you've processed all numbers up to √n.
      • You only need to go up to √n because any composite number larger than √n must have at least one prime factor less than or equal to √n.
    7. Collect the results:
      • All unmarked numbers in your list are prime.
    Example \(\PageIndex{1}\)

    Let's find all primes up to 30:

    List: 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30

    1. Start with 2, mark multiples: 2, 3,
    2.  
    3. 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30
    4. Move to 3, mark multiples: 2, 3,
    5.  
    6. 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30
    7. Move to 5 (next unmarked), mark multiples: 2, 3,
    8.  
    9. 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30
    10. We're done because \(\sqrt{30} ≈ 5.5\), and we've processed all numbers up to 5.

    The unmarked numbers (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) are all the primes up to 30.

    This algorithm efficiently finds all primes in a given range, making it a powerful tool for number theory and various applications in computer science and mathematics.

    Try It! Sieve of Eratosthenes Widget

    Instructions:

    1. Choose a number up to which you want to find all prime numbers.
    2. On a piece of paper, try to apply the Sieve of Eratosthenes method to find these primes.
    3. Write down your process and the prime numbers you identified.
    4. Once you're done, enter your chosen number in the box below and click "Run Sieve".
    5. Compare your work with the steps and result shown by the widget.
    6. If your answer matches, great job! If not, review the steps to see where you might have made a mistake.
     

    How Can Understanding the Sieve Help in Teaching Math?

    1. Visualization of Abstract Concepts: The sieve turns the abstract idea of prime numbers into a visual, tangible process.
    2. Pattern Recognition: Students can observe patterns in the multiples being crossed out, reinforcing multiplication facts.
    3. Problem-Solving Skills: It introduces a systematic approach to solving a complex problem (finding all primes).
    4. Differentiated Learning: The sieve can be adapted for different skill levels by changing the number range.
    5. Cross-Curricular Connections: You can integrate history (ancient Greece) and technology (coding simple sieve programs) into math lessons.
    6. Foundation for Advanced Concepts: It lays the groundwork for understanding factors, multiples, and even basic cryptography.

    4.3: The Sieve of Eratosthenes is shared under a CC BY-SA 4.0 license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?