This site is a work in progress. New lessons are added regularly. Contact us

Primes and Composites

Learning goals

  • Define prime and composite by counting a number's factors
  • Explain why 11 is neither prime nor composite
  • Say why 22 is the only even prime
  • Test a number by trial division with the divisibility rules
  • Stop testing once the divisor times itself passes the number
  • Run the Sieve of Eratosthenes to list primes up to a limit

Factors, the starting point

A quick reminder from the last lesson. A factor (or divisor) of a whole number nn is a whole number that divides nn leaving remainder 00. To list the factors of nn, you ask of each candidate “does it divide nn evenly?” The factors of 1212 are

1,2,3,4,6,12,1, \quad 2, \quad 3, \quad 4, \quad 6, \quad 12,

because each of these divides 1212 with nothing left over, and no other whole number does. Two of those factors come free for every whole number greater than 11. Every such number is always divisible by 11 (one group containing everything) and by itself (one group the size of the whole number). So the real question, the one that sorts numbers into two camps, comes down to this. Does a number have only those two forced factors, or does it have more?

Defining prime and composite

This is the whole idea, stated carefully. We count only the distinct factors, and we work with whole numbers greater than 11.

A whole number greater than 11 is prime when it has exactly two distinct factors: 11 and itself, and nothing in between. The number 77 is prime because the only whole numbers that divide it are 11 and 77. Try anything else, say 22, 33, 44, 55, or 66, and a remainder appears.

A whole number greater than 11 is composite when it has more than two distinct factors. The number 1212 is composite because, beyond 11 and 1212, the numbers 2,3,4,2, 3, 4, and 66 also divide it. Having even one extra factor is enough to make a number composite.

Both of those claims are things you can check rather than take on trust. Below you choose how many dots there are and how many go in each row. When the rows come out even, the row width is a factor. When the last row is short, it is not, and the leftover dots are drawn hollow so you can count them.

Which row widths a number allows

12 dots in rows of 4 make 3 full rows with none left over. So 12 = 3 times 4. So 4 is a factor of 12. Dots laid out in equal rows, filling from the top left. Dots that do not complete a row are drawn hollow. Use the controls below the figure to change the number of dots or the row width.
Dots Rows of

12 dots in rows of 4 make 3 full rows with none left over. So 12 = 3 times 4. So 4 is a factor of 12.

Dots laid out in equal rows. Choose how many dots there are and how many go in each row; a short last row means the row width is not a factor.

Set the count to 1212 and walk the row width from 22 up to 66. Widths 22, 33, 44 and 66 all come out even, and only 55 leaves anything over, so 1212 has factors to spare and is composite. Now set the count to 77 and walk the same widths again. Every single one leaves a short row. Nothing between 11 and 77 divides it, which is exactly what makes 77 prime, and you have now checked it rather than been told it.

Every whole number greater than 11 falls into exactly one of these two groups, never both and never neither. Either its only factors are 11 and itself (prime), or it has at least one more (composite). Here is the start of the list, sorted:

2,3,5,7,11,13prime4,6,8,9,10,12composite\underbrace{2, 3, 5, 7, 11, 13}_{\text{prime}} \qquad\qquad \underbrace{4, 6, 8, 9, 10, 12}_{\text{composite}}

The word prime comes from the Latin for “first”, and the primes are first in the sense of being the simplest. They are the ones not built from smaller pieces. A composite number, as the name suggests, is “composed” of smaller factors.

Why 1 is neither prime nor composite

The number 11 looks like it might be prime, since nothing divides it except 11. But run it through the definition exactly. A prime needs two distinct factors. The number 11 has only one factor, namely 11 itself: the "11" and the “itself” are the same number, so they do not count twice.

Why 11 is excluded from the primes#

List the factors of 11. A factor of 11 is a whole number that divides 11 with no remainder. The only whole number that does this is 11, since 1÷1=11 \div 1 = 1 and any larger number divides 11 with a remainder. So the complete factor list of 11 is just

{1},\{1\},

a set with a single member. The definition of prime demands exactly two distinct factors, and 11 supplies only one, so 11 is not prime. It is not composite either, because composite means more than two factors, and one is fewer than two, not more. So 11 sits outside both groups on its own.

The exclusion of 11 is not a quirk of bookkeeping. Keeping 11 out of the primes is what makes the primes behave as clean building blocks in the next lesson. If 11 were prime, you could glue extra copies of it onto any factorization (6=2×3=1×2×3=1×1×2×36 = 2 \times 3 = 1 \times 2 \times 3 = 1 \times 1 \times 2 \times 3) and never get a single, settled answer. Leaving 11 aside keeps each number’s set of prime building blocks unique.

Why 2 is the only even prime

Look at the prime list again: 2,3,5,7,11,13,2, 3, 5, 7, 11, 13, \ldots. After 22, every entry is odd. That is no accident.

Try to find an even number past 22 that survives the definition. Take 1414. Being even hands it 22 as a factor for free, on top of the 11 and the 1414 that every number is forced to have. Its factor list is 1,2,7,141, 2, 7, 14, which is four factors, and a prime is allowed exactly two. That free gift of a 22 arrives with every even number, which is what decides the general case.

Why 22 is the only even prime#

First, 22 itself is prime: its only factors are 11 and 22, which is exactly two, so it qualifies.

Now watch one other even number, say 2020. It ends in 00, so 22 divides it and 22 is a factor. The number 2020 already carried 11 and 2020 as factors, and this 22 is neither of them, so it is a third one. Three distinct factors is one more than a prime is allowed, so 2020 is composite.

Only two things about 2020 were used: it is even, and it is bigger than 22. So take any even number nn greater than 22. Being even means 22 divides it, so 22 is a factor. But nn already has 11 and nn as factors, and since nn is larger than 22, this 22 is a third, different one. With at least three distinct factors, nn is composite.

So every even number past 22 is composite, which leaves 22 as the only even prime.

This gives you a fast first filter. If a number bigger than 22 ends in 0,2,4,6,0, 2, 4, 6, or 88, you can declare it composite on sight, no division needed. The candidates for “prime” past 22 are only the odd numbers, and even among those, plenty (like 99, 1515, 2121) turn out to be composite.

Check your understanding

How many of these four numbers are prime: 11, 22, 99, 1111?

Answer choices

Testing a number by trial division

To decide whether a number nn is prime, you hunt for a factor other than 11 and nn. Find even one and nn is composite; find none and nn is prime. The direct method is trial division: try the candidate divisors in turn and watch for a clean division. You do not need to test every number below nn, and you do not need long division either. That is because the divisibility rules from the last lesson do most of the work.

Test the candidates in increasing order, 2,3,5,7,2, 3, 5, 7, \ldots, and lean on the rules you already know:

You can skip every even candidate after 22, since an even divisor would make nn even and you have already checked 22. You can also skip multiples of 33 after 33, so in practice you test 2,3,5,7,11,13,2, 3, 5, 7, 11, 13, \ldots, the primes themselves. A few small divisors are enough to settle even a fairly large number. The explanation is the stopping rule, which is the heart of the method.

The stopping rule: when can you quit?

Testing divisors one by one could go on a long time. The key shortcut is that you can stop early: once a candidate divisor dd grows large enough that d×dd \times d passes nn, you are done. If nothing has divided nn by the time you reach that point, nn is prime. The reason is a fact about how factors come in pairs.

Watch the factors of 3636 do it. They arrive two at a time: 11 with 3636, 22 with 1818, 33 with 1212, 44 with 99, and 66 with 66. Every one of those pairs has a partner of 66 or less, and 66 is the number whose square is 3636. So testing 2,3,4,5,62, 3, 4, 5, 6 finds every pair there is. A divisor above 66 could only be the larger partner of a pair you already caught by its smaller one.

In plain terms: keep testing divisors d=2,3,5,7,d = 2, 3, 5, 7, \ldots only while d×dnd \times d \le n. As soon as d×dd \times d passes nn, stop. For n=97n = 97, you test d=2,3,5,7d = 2, 3, 5, 7 (since 7×7=49977 \times 7 = 49 \le 97) and then consider d=11d = 11, but 11×11=12111 \times 11 = 121, which is already past 9797, so 1111 is the signal to stop. None of 2,3,5,72, 3, 5, 7 divided 9797, so 9797 is prime. You confirmed a prime by trying just four small divisors.

Factor pairs of 36 fold around 6The factors of 36 listed as pairs whose product is 36: 1 and 36, 2 and 18, 3 and 12, 4 and 9, 6 and 6. Every pair has a partner that is 6 or smaller.Factor pairs of 36 (product = 36)smallerlarger1x362x183x124x96x6
Factors of 36 pair up around the value whose square is 36, which is 6. Each small factor on the left has a partner on the right; once the divisor passes 6, every new factor would only repeat a partner already found.

The pairing that 3636 showed you is the whole reason, and it holds for every number.

Why you may stop once the divisor times itself passes nn#

Try it on 9191 with the divisor 77. The division gives 91÷7=1391 \div 7 = 13, so the 77 arrives holding a partner, and 91=7×1391 = 7 \times 13. Those two partners fall either side of the value whose square is 9191, which sits between 99 and 1010. They are forced to: two partners both above it would multiply past 9191, since even 10×10=10010 \times 10 = 100 overshoots. So the smaller partner 77 is the one a search meets first, and it is met while 7×7=497 \times 7 = 49 is still under 9191.

Now the same reasoning with letters. Whenever a number dd divides nn, the division produces a partner. If n÷d=en \div d = e, then

n=d×e,n = d \times e,

so dd and ee are a pair of factors whose product is nn. They always come together: find one and you have found the other.

Now compare the pair against the value where a number times itself equals nn. The two partners cannot both be larger than it, or their product would overshoot nn. So whichever of dd and ee is the smaller, call it ss, satisfies s×sns \times s \le n. The larger partner has no such bound: for 91=7×1391 = 7 \times 13 the smaller is 77, and 13×1313 \times 13 is far past 9191.

Every composite number therefore has a factor ss small enough to meet before your trial divisor reaches the point where it times itself passes nn. Suppose you have tested every candidate up to there and none divided nn. Then no factor pair is left to find, so nn has no factor besides 11 and nn, and nn is prime. Any factor past that point would drag in a partner you already tried and ruled out.

Worked example 1 Is 5151 prime or composite?

The number 5151 is odd and does not end in 00 or 55, so 22 and 55 are out. Try the next candidate, 33, with the digit-sum rule:

5+1=6=3×2,5 + 1 = 6 = 3 \times 2,

so 33 divides 5151. That is a third factor besides 11 and 5151, which settles it:

51=3×17.51 = 3 \times 17.

So 5151 is composite. A number can look prime at a glance and still hide a factor; the digit-sum test for 33 catches many that the eye misses.

Worked example 2 Is 8383 prime or composite?

Test divisors in order, stopping once a divisor times itself passes 8383.

It is odd, so 22 fails. Its digit sum is 8+3=118 + 3 = 11, not a multiple of 33, so 33 fails. It does not end in 00 or 55, so 55 fails. Try 77:

83÷7=11 remainder 6,83 \div 7 = 11 \text{ remainder } 6,

so 77 fails too. The next candidate is 1111, but check the stopping rule first:

11×11=121>83,11 \times 11 = 121 > 83,

so we have passed the stopping point. No divisor up to here worked, so there is no factor pair to find. Therefore 8383 is prime. Notice we only had to try 2,3,5,2, 3, 5, and 77.

Check your understanding

You are testing whether 7979 is prime by trying prime divisors. What is the largest prime you need to test before you can stop?

Answer choices

The Sieve of Eratosthenes

To find all the primes up to some limit at once, there is a method faster than testing each number on its own. That method has been known since antiquity as the Sieve of Eratosthenes (a way to find every prime below a limit by crossing out multiples). The idea is to start with every number and strain out the composites, leaving the primes behind. A sieve does the same, straining out what you do not want.

Write the whole numbers from 22 up to your limit. Then repeat one move:

  1. Circle the smallest number not yet crossed out. It is prime (nothing below it divided it, or it would already be crossed out).
  2. Cross out every larger multiple of that number. They are all composite, since they have it as a factor.

The first prime is 22, so circle it and cross out 4,6,8,10,4, 6, 8, 10, \ldots. The next surviving number is 33, so circle it and cross out 6,9,12,6, 9, 12, \ldots. Then 55, then 77, and so on. By the stopping rule, once the circled prime times itself passes your limit, everything still standing is prime and you are finished.

Sieve of Eratosthenes from 2 to 30The numbers 2 to 30 in a grid. Ten primes (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) are circled; the composites are struck through and dimmed.Primes up to 30 (circled)23456789101112131415161718192021222324252627282930
The Sieve of Eratosthenes on the numbers 2 to 30. Cross out the multiples of 2, then of 3, then of 5; the multiples of 7 and up are already gone below 30, since 7 times 7 passes 30. The ten numbers left circled are the primes up to 30.

Worked example 3 List every prime between 2020 and 3030

Run each candidate through the quick tests, remembering that any even number or any multiple of 55 in this range is composite immediately.

The even numbers 22,24,26,2822, 24, 26, 28 and the multiple of 55, namely 2525, are all composite. That leaves the odd, non-multiple-of-55 numbers 21,23,27,2921, 23, 27, 29 to examine:

21=3×7,27=3×9,21 = 3 \times 7, \qquad 27 = 3 \times 9,

so 2121 and 2727 are composite (both have digit sums divisible by 33). Now test 2323 and 2929. Neither is even, neither is a multiple of 33 (2+3=52 + 3 = 5 and 2+9=112 + 9 = 11), and neither ends in 00 or 55. The next divisor would be 77, but 7×7=497 \times 7 = 49 already passes both numbers, so we stop.

Therefore the primes between 2020 and 3030 are

23and29.23 \quad \text{and} \quad 29.

Check your understanding

Which one of these numbers is prime?

Answer choices

Common mistakes

Practice

Multiple Choice Questions (MCQ)

Progressively harder sets of questions. Each opens on its own page.

Free Response Questions (FRQ)

Longer questions in parts, to be worked out on paper. Progressive hints, the answer on its own so you can check yourself and try again, then the full worked solution, plus a rubric to mark your own work against.

Free response Work it out on paper 5 questions Start →
More practice (optional)

Extra sets, as hard as the Challenge set. Each one opens on its own page.

More resources (optional)

Other explanations of this lesson, if you want a second take.

A bit of history (Optional)

Eratosthenes, a Greek scholar, wanted to know how big the Earth is. He did not travel it. He compared the shadows cast at noon in two Egyptian towns, and came remarkably close to the true figure.

That was his habit: find the cheap route. He lived in the third century BCE, and he ran the great library at Alexandria in Egypt. Books came to him rather than the other way round.

Primes handed him the same kind of problem. Testing numbers one at a time is slow work. So he stopped testing them one at a time. Write every number down, then cross out the multiples of two, then of three, then of five. Whatever survives is prime, and you never divided anything.

That is the sieve you ran in this lesson, circling a survivor and striking out its multiples. It is over two thousand years old, and computers still run it when they need every prime below a bound. Nobody has found a plainer way to do what you did by hand.