Prime Numbers Explained From the Ground Up
Understand what primes are, how to test a number by hand, why they are the building blocks of arithmetic and what remains unknown.
Key takeaways
- A prime has exactly two positive divisors, and a composite number has more; the number 1 is neither.
- To test whether n is prime by hand, try dividing by the primes up to the square root of n.
- Every whole number above 1 factors into primes in only one way, apart from order.
- There are infinitely many primes, they thin out gradually, and several simple questions about them are still open.
A prime number is a whole number greater than 1 that has exactly two positive divisors, 1 and itself. So 7 is prime, because nothing else divides it evenly. The number 12 is not, since 2, 3, 4 and 6 also divide it. Whole numbers greater than 1 that are not prime are called composite.
Primes matter because every whole number above 1 is either a prime or a product of primes, in essentially only one way. If multiplication builds numbers, primes are the pieces it builds them from.
A picture with tiles
Take 12 square tiles and arrange them into a full rectangle. You can make 1 by 12, 2 by 6 or 3 by 4. Now try 13 tiles. The only rectangle is the single row, 1 by 13.
That is what primality looks like: a prime number of tiles refuses to form any rectangle except a line. A composite number allows at least one with both sides longer than 1. One tile makes only a 1 by 1 square, a special case we will come back to.
Rectangles also show why divisors come in pairs. If 3 divides 12, then so does 12 ÷ 3 = 4, because they are the two sides of one shape.
The first primes
Here are the 25 primes below 100.
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 The number 2 is the only even prime, since every other even number is divisible by 2. After 5, no prime ends in 5 or 0, so larger primes end in 1, 3, 7 or 9. The reverse is false: 21, 27, 33 and 39 end in those digits and are composite.
You can produce such a list yourself with the sieve of Eratosthenes, which crosses out multiples until only primes remain.
Testing a number by hand
Suppose you want to know whether n is prime. You do not need to try every smaller number. If n = a × b with both factors greater than 1, at least one of them is no bigger than √n, because two numbers both larger than √n would multiply to more than n.
Better still, you need only try primes, since a number divisible by 6 is already divisible by 2.
Is 223 prime? √223 is about 14.9, so test 2, 3, 5, 7, 11, 13
2 223 is odd
3 2 + 2 + 3 = 7, not divisible by 3
5 does not end in 0 or 5
7 7 × 31 = 217, remainder 6
11 11 × 20 = 220, remainder 3
13 13 × 17 = 221, remainder 2
so 223 is prime Compare 221, which looks just as stubborn. It passes the tests for 2, 3, 5, 7 and 11, and then 221 = 13 × 17. Divisibility rules speed up the first few checks.
Building blocks
Keep splitting a composite number until nothing splits further. For example, 84 = 4 × 21 = 2 × 2 × 3 × 7. Starting with 12 × 7 or 6 × 14 leads to the same list. This is the fundamental theorem of arithmetic, whose proof is in unique factorization.
With the primes of a number in hand, many questions become easy. You can tell whether it is a square, find all its divisors, or compare it with another number to get their greatest common divisor and least common multiple.
What divisibility by a prime tells you
Primes have a property that composite numbers lack. If a prime divides a product, it divides at least one of the factors. Because 7 divides 14 × 15 = 210, it must divide 14 or 15, and indeed it divides 14.
A composite number can slip between the factors. The number 6 divides 4 × 9 = 36 without dividing 4 or 9, because it takes one 2 from the first and one 3 from the second. A prime has no parts to distribute.
This property drives many everyday deductions. If n² is even, then 2 divides n × n, so 2 divides n. The same step with 3 shows that if n² is a multiple of 3, so is n. It is the hinge in classic proofs that √2 and √3 are irrational.
It also explains cancellation in remainder arithmetic. Working with remainders on division by a prime, a product can be 0 only if one of the factors is 0. On a 12-hour clock, by contrast, 3 × 4 lands on 0 although neither 3 nor 4 does.
There is no largest prime
Euclid's argument shows that any finite list of primes is incomplete. Multiply the listed primes together and add 1. The result leaves remainder 1 when divided by any prime on the list, so its prime factors must be new ones. Euclid's proof walks through the details and a common misreading.
Record primes, the largest ones actually written down, run to tens of millions of digits as of the mid-2020s, and they are of a special form called Mersenne primes. The record keeps changing, which is only possible because the supply is endless.
How primes are spread
Primes become less common as numbers grow, but slowly.
| Up to | Number of primes |
|---|---|
| 10 | 4 |
| 100 | 25 |
| 1,000 | 168 |
| 10,000 | 1,229 |
| 100,000 | 9,592 |
| 1,000,000 | 78,498 |
The prime number theorem, proved in 1896 by Jacques Hadamard and Charles de la Vallée Poussin independently, says that the count of primes up to x is approximately x divided by the natural logarithm of x, with a relative error that shrinks toward zero. For a million that estimate gives about 72,000, low by several percent, and the approximation improves very gradually. See how primes thin out.
Up close the pattern is irregular. There are neighbors such as 101 and 103, and there are long empty stretches. In fact you can build a gap as long as you like: the numbers 101! + 2 through 101! + 101 are all composite, since 101! + k is divisible by k. (Here 101! means 1 × 2 × ... × 101.)
Patterns that are real and patterns that are not
Every prime above 3 is one more or one less than a multiple of 6. The other remainders, 0, 2, 3 and 4, force divisibility by 2 or 3. The converse fails, since 25 and 35 also sit next to multiples of 6.
Some formulas look as if they generate primes. The expression n² + n + 41 gives a prime for every whole n from 0 to 39. Then n = 40 gives 1681 = 41². Forty successes in a row proved nothing about the next case.
No simple, practical formula is known that produces exactly the primes. Formulas that technically do exist tend to hide the primes inside their own definitions or to be useless for computing.
Sorting primes by remainder
Dividing the odd primes by 4 splits them into two teams. Some leave remainder 1, such as 5, 13, 17 and 29. Others leave remainder 3, such as 3, 7, 11, 19 and 23. Each team is infinite, and over the long run each holds about half of the primes.
The teams behave differently. Every prime in the first is a sum of two squares: 5 = 1 + 4, 13 = 4 + 9 and 29 = 4 + 25. No prime in the second is, because a square leaves remainder 0 or 1 on division by 4, so two squares can never add to a number leaving remainder 3. The first half of that statement takes real work to prove and is explored in sums of two squares.
A far-reaching theorem of Dirichlet generalizes the infinitude. If a and d share no common factor and d is positive, then the progression a, a + d, a + 2d and so on contains infinitely many primes. For d = 10, this means infinitely many primes end in each of 1, 3, 7 and 9.
Common mistakes with primes
- Calling every odd number prime. The odd numbers 9, 15, 21 and 25 are composite.
- Stopping trial division too early. To check 289 you must go up to 17, since 289 = 17².
- Assuming a product of primes plus 1 is itself prime. It need not be.
- Taking a number's look as evidence. Both 91 = 7 × 13 and 119 = 7 × 17 are often mistaken for primes.
A good habit is to memorize the squares of the small primes: 4, 9, 25, 49, 121, 169, 289. They tell you at a glance which primes a trial needs. A number below 121 that is not divisible by 2, 3, 5 or 7, and is greater than 1, must be prime.
Open questions
Several questions that need no advanced vocabulary remain unanswered as of the mid-2020s.
- Are there infinitely many twin primes, pairs differing by 2? Major progress has shown that some bounded gap occurs infinitely often.
- Is every even number above 2 a sum of two primes? This is Goldbach's conjecture.
- Is there always a prime between consecutive squares? This is Legendre's conjecture.
- Are there infinitely many primes of the form n² + 1?
Check a current source for status, since this field moves.
Where primes show up
Public-key cryptography multiplies large primes, relying on the apparent difficulty of reversing that product. Computer scientists use primes in hashing, a way of scattering data evenly. Check digit schemes often work modulo a prime, because every nonzero remainder then has a multiplicative inverse. Modular arithmetic explains what that means.
Biologists have suggested that the 13 and 17 year cycles of some cicadas reflect the advantages of prime periods. It is an interesting hypothesis, and other explanations are discussed alongside it.
Common questions
Is 1 prime?
No. It has only one positive divisor, and counting it as prime would spoil unique factorization. See why 1 is not prime.
Can negative numbers be prime?
In elementary work primes are positive by definition. In more general algebra, −7 is also called a prime element, since it differs from 7 only by the factor −1.
Is there a fast way to test huge numbers?
Yes. Practical tests settle whether a number with hundreds of digits is prime very quickly, without finding any factors when it is composite. Factoring is the hard direction.