Primes and Composites

Watch the video explainer

Learning goals

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

Factors, the starting point

A factor (or divisor) here means a positive whole number that divides a number without a remainder. For 1212, the factors are

1,2,3,4,6,12.1,\quad2,\quad3,\quad4,\quad6,\quad12.

Every whole number greater than 11 has 11 and itself as two distinct factors. The question is whether it has any others.

Defining prime and composite

Count distinct factors only: a factor counts once, even when it appears twice in a factor pair.

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.

Use the rows below to check those definitions. Change the number of dots and the row width. A full set of rows means the width is a factor; hollow dots in a short row mean it is not.

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.

Try 1212 dots with row widths 22 through 66. The widths 22, 33, 44, and 66 fit, so 1212 is composite. Now try 77 dots with the same widths. Every width leaves a remainder; only 11 and 77 fit, so 77 is prime.

Every whole number greater than 11 is exactly one of prime or composite. Its factors either stop at 11 and itself, or include at least one more.

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

Zero is outside both definitions: it is not greater than 11.

Why 1 is neither prime nor composite

The number 11 has just one factor, 11. The phrases "11" and “itself” name the same factor, so they do not count twice. A prime needs two distinct factors, and a composite needs more than two; 11 is neither.

There is a useful reason for keeping 11 out of the prime list. Multiplying by 11 never changes a number:

6=2×3=1×2×3=1×1×2×3.6=2\times3=1\times2\times3=1\times1\times2\times3.

If 11 counted as prime, a list of prime factors could gain extra 11s without changing its product. The next lesson uses a prime list that is unique apart from order.

Why 2 is the only even prime

The factors of 22 are just 11 and 22, so 22 is prime. For a larger even number, such as 1414, being even supplies an extra factor, 22. Its factors include 11, 22, and 1414, already too many for a prime.

The same reasoning applies to every even number greater than 22: the factor 22 is different from both 11 and the number itself. Thus 22 is the only even prime. Being odd does not guarantee being prime: 9=3×39=3\times3 is odd and composite.

Check your understanding

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

Answer choices

Check your understanding

Which explanation correctly describes both 11 and even numbers greater than 22?

Answer choices

Testing a number by trial division

Trial division means testing possible divisors in turn. For a number greater than 11, a factor other than 11 and itself proves it composite. The divisibility rules make the first tests easy:

Why skip composite divisors? If 44 divided your number, 22 would divide it too; if 99 divided it, 33 would. More generally, a composite divisor has a smaller prime factor. That smaller prime would already have been tested. The next section tells you how far the search needs to go.

The stopping rule: when can you quit?

Factors come in pairs, so a search can stop before reaching the number itself. For 3636, the pairs are 1×361\times36, 2×182\times18, 3×123\times12, 4×94\times9, and 6×66\times6. Each pair has a smaller partner at most 66, and 6×6=366\times6=36. A factor above 66 would be the larger partner of a pair found earlier.

For a whole number nn greater than 11, test prime divisors dd while d×d≤nd\times d\le n. Stop once d×d>nd\times d>n. A factor found makes nn composite; if every prime in that range fails, nn is prime. The equal case counts too: 4949 still needs the test at 77, since 7×7=497\times7=49.

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.

Every composite has a small partner to find: two factors both past the stopping point would multiply to more than the number. Checking the smaller partners therefore covers every possible pair.

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:

51=3×17.51 = 3 \times 17.

So 5151 is composite. The digit-sum test for 33 catches factors the eye misses, so run it early.

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

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

The Sieve of Eratosthenes

To find all the primes up to a limit, cross out composites together instead of testing each number separately. This is the Sieve of Eratosthenes: like a sieve separating objects, it removes the numbers you do not want and leaves the primes.

Write the whole numbers from 22 to the limit. Circle 22 and cross out its larger multiples. Then circle the smallest number neither circled nor crossed out, and cross out its larger multiples. Repeat with the next such number.

Why is each newly circled number prime? Any smaller factor would already have caused it to be crossed out. Keep the circled prime itself; only its larger multiples are composite.

For a limit of 3030, the passes for 22, 33, and 55 remove every composite. The next prime is 77, and 7×7>307\times7>30. By the stopping rule, every uncrossed number is now prime.

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; no separate pass is needed for 7 or any larger prime, since 7 times 7 already passes 30. The ten numbers left circled are the primes up to 30.

Check your understanding

Run the Sieve of Eratosthenes from 22 through 1818. Which list remains after the composites are crossed out?

Answer choices

Common mistakes

Practice

Multiple Choice Questions (MCQ)

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

Core practice

Practice problems at the level of the course, to be worked out on paper. Hints one at a time, then the answer or the full worked solution, with your progress kept in this browser.

Core practice Work it out on paper 10 problems 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.

Go deeper (optional)

You can skip this and keep going. Read it if you want to know more.

The full stopping-rule argument, with letters

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

For 91=7×1391=7\times13, the smaller partner is 77. Since 7≤137\le13,

7×7≤7×13=91.7\times7\le7\times13=91.

So this factor pair has a partner within the range we test.

The smaller partner might be composite. For 90=9×1090=9\times10, it is 99. Its smallest divisor above 11 is the prime 33, which also divides 9090. Again the prime is in range:

3×3≤9×9≤90.3\times3\le9\times9\le90.

Now take any whole number n>1n>1. If it is composite, it has a factor pair other than 11 and nn. Call the smaller factor ss and the larger tt. Since s≤ts\le t, multiplication gives

s×s≤s×t=n.s\times s\le s\times t=n.

Thus every composite has a factor s>1s>1 with s×s≤ns\times s\le n. Choose the smallest divisor p>1p>1 of ss. This pp must be prime: if it were composite, a factor between 11 and pp would also divide ss, contradicting the choice of pp as the smallest. Since pp divides ss and ss divides nn, it divides nn too. Also p≤sp\le s, so p×p≤np\times p\le n. Every composite therefore has a prime factor in the tested range.

Suppose all primes in that range have failed, yet nn were composite. Its small prime factor would have been tested and would have succeeded, contradicting those failed tests. Therefore nn, which is greater than 11, is prime. A factor exactly at the boundary must be tested too.

A bit of history (optional)

Eratosthenes worked at Alexandria’s great library in Egypt in the third century BCE. His interests stretched from poetry to geography and mathematics, and he became its chief librarian. One method associated with his name, the sieve, works on a simple list of numbers.

The ancient description begins with odd numbers starting at 33. Strike out larger multiples of 33, then of 55, and continue: the surviving numbers are odd primes. The modern version usually starts with 22 and includes a pass removing the even composites.

We know this method through later writers, including Nicomachus, who described Eratosthenes’ sieve centuries after Eratosthenes lived. No instructions for the method written by Eratosthenes himself survive. The Dictionary of Scientific Biography account traces those sources; MacTutor’s biography describes his life at Alexandria.

Your progress

See all your progress →