Primes and Composite Numbers

What is the smallest set of building blocks? From these, every whole number can be assembled by multiplication alone. This question, ancient and still generative, is the doorway to the theory of primes. A prime number is a positive integer greater than 1. It has exactly two positive divisors. Every other integer greater than 1 is composite, meaning it breaks apart into smaller factors. This distinction looks almost too simple to matter. Yet it is the seed from which the entire multiplicative structure of the integers grows. The idea matters because multiplication, unlike addition, has no obvious "unit of measure." Addition is generated by the single element 1. Multiplication of integers, however, is generated by infinitely many elements — the primes. None of these reduces further. Understanding which numbers are prime matters greatly. So does knowing how to detect primality by trial division. And knowing how every integer decomposes into primes matters too. Together these give us the first rigorous foothold on deeper questions. How many primes are there? How are they distributed? Can every number be built uniquely from them? The big picture is this: primes play the role for multiplication that atoms play for matter. They are like the number 1 for addition — except there are infinitely many types of "atom." Discovering their laws occupies number theory from its first page to its research frontier. These laws include how many primes exist, how they are spaced, and how factorization behaves. This article sits at the very foundation. It fixes the definitions and establishes the mechanical tool of trial division for testing primality. It also proves that every integer greater than 1 admits at least one decomposition into primes. This is the existence half of what will later become the Fundamental Theorem of Arithmetic. What this article delivers: precise definitions of prime and composite numbers, a fully justified trial-division algorithm. This includes the proof that checking divisors up to n\sqrt{n} suffices. It also offers a rigorous proof by strong induction. This proof shows that every integer greater than 1 factors into primes. There are worked examples on genuinely awkward numbers. A counterexample shows why the hypothesis n>1n>1 cannot be dropped. Finally, there is a forward glance toward uniqueness of factorization and the Infinitude of Primes.

Key takeaways
  • A prime p>1p>1 has exactly two positive divisors: 11 and pp itself; anything else greater than 11 is composite.
  • The number 11 is neither prime nor composite — it is a special case, the multiplicative unit.
  • Trial division tests primality by checking candidate divisors only up to n\sqrt{n}, not up to nn.
  • Every integer n>1n>1 has at least one prime divisor — this is the engine behind factorization.
  • Strong induction proves every integer n>1n>1 is a product of (one or more) primes — existence of factorization.
  • Key idea: primes are the irreducible multiplicative atoms of Z>1\mathbb{Z}_{>1}, and every integer decomposes into them.

Where this lives today

Trial division and the elementary structure of primes are not merely historical curiosities; they underlie practical and theoretical machinery across mathematics and computing. In cryptography, the RSA public-key system relies on the practical difficulty of factoring large composite numbers (the product of two large primes) even though existence of a factorization is guaranteed by the theorem above — the gap between "a factorization exists" and "a factorization is easy to find" is precisely what protects encrypted data. In computer science, trial division (and its refinements, such as the sieve methods and probabilistic tests like Miller–Rabin) forms the baseline algorithm against which faster primality tests and factoring algorithms are measured. In pure number theory, the existence-of-factorization result proved here is the first half of the Fundamental Theorem of Arithmetic, whose uniqueness half underlies virtually all further arithmetic (computing greatest common divisors via prime exponents, defining arithmetic functions like φ\varphi and σ\sigma, and studying Diophantine equations). In statistics and random number generation, prime moduli are chosen for linear congruential generators because primality guarantees useful algebraic structure (Modular Arithmetic modulo a prime forms a field). Finally, the question this article opens the door to — how many primes are there, and how are they spaced? — leads directly to Euclid's proof of the Infinitude of Primes and, further out, to the Prime Number Theorem and the Riemann Hypothesis.

Ask the tutor: How does Euclid's Lemma turn this existence proof into a full proof of unique factorization?

DefinitionPrime and composite numbers

Let nn be an integer with n>1n > 1. We say nn is prime if its only positive divisors are 11 and nn itself. Equivalently, nn is prime if whenever n=abn = ab with a,ba, b positive integers, one of a,ba, b equals 11 (and the other equals nn). We say nn is composite if it is not prime, i.e. if there exist integers a,ba, b with 1<a<n1 < a < n, 1<b<n1 < b < n, and n=abn = ab. The integer 11 is declared to be neither prime nor composite (it has only one positive divisor, namely itself, so it fits neither definition). By convention, primality and compositeness are defined only for integers strictly greater than 11.

Intuition

Think of the positive integers greater than 11 as objects sitting on an assembly line, and multiplication as the operation of gluing two smaller objects together. Some objects — the primes 2,3,5,7,11,13,…2, 3, 5, 7, 11, 13, \dots — cannot be produced by gluing two smaller pieces (other than the trivial gluing with the identity factor 11). Every other object, the composites, can be pulled apart into at least two nontrivial pieces. If those pieces are themselves composite, pull them apart again; since the pieces strictly shrink and are bounded below by 22, this process must terminate, and it terminates exactly when every remaining piece is prime. That intuitive "pulling apart until stuck" process is precisely the content of the proof below, made rigorous through strong induction. Trial division formalizes the search for a nontrivial divisor. To test whether nn is prime, we do not need to check every integer from 22 to n−1n-1: if n=abn = ab with a,b>1a,b > 1, then aa and bb cannot both exceed n\sqrt{n}, since their product would then exceed nn. So it suffices to search for a divisor no larger than n\sqrt{n}. This single inequality is what makes primality testing by hand feasible even for numbers in the hundreds.

Figure
Trial division: only divisors up to √n matter
Testing n = 221 for primality: √221 ≈ 14.87 2 4 6 8 10 12 13 √221≈14.87 no divisor found here... 221 ÷ 13 = 17 exactly, so 13 is a prime factor of 221 (13 < √221). Conclusion: 221 = 13 × 17 is composite; no need to test past 15.

Central results

LemmaLeast divisor greater than 1 is prime

Let nn be an integer with n>1n > 1, and let dd be the smallest divisor of nn satisfying d>1d > 1. Then dd is prime.

Proof

Such a dd exists because the set {k∈Z:k∣n, k>1}\{k \in \mathbb{Z} : k \mid n,\ k > 1\} is nonempty (it contains nn itself, since n∣nn \mid n and n>1n>1) and is a set of positive integers, hence has a least element by the Well-Ordering Principle. Suppose, for contradiction, that dd is not prime. Since d>1d > 1 and dd is not prime, dd is composite, so by definition there exist integers a,ba, b with

d=ab,1<a<d,1<b<d.d = ab, \qquad 1 < a < d, \qquad 1 < b < d.

Since a∣da \mid d and d∣nd \mid n, divisibility is transitive (if a∣da \mid d and d∣nd \mid n then d=amd = a m and n=dkn = d k for integers m,km,k, so n=a(mk)n = a(mk), giving a∣na \mid n), hence a∣na \mid n. But aa satisfies 1<a<d1 < a < d, so aa is a divisor of nn that is greater than 11 and strictly smaller than dd. This contradicts the minimality of dd among divisors of nn exceeding 11. Therefore the assumption that dd is composite is false, and since d>1d>1, dd must be prime. ■\blacksquare

∎
TheoremTrial division bound

Let nn be an integer with n>1n > 1. If nn is composite, then nn has a divisor aa with 1<a≤n1 < a \le \sqrt{n}. Consequently, if nn has no divisor dd with 1<d≤n1 < d \le \sqrt{n}, then nn is prime.

Proof

Suppose nn is composite. By definition there exist integers a,ba, b with

n=ab,1<a<n,1<b<n.n = ab, \qquad 1 < a < n, \qquad 1 < b < n.

We claim at least one of a,ba, b satisfies ≤n\le \sqrt{n}. Suppose instead, for contradiction, that both a>na > \sqrt{n} and b>nb > \sqrt{n}. Since a,b>0a, b > 0, multiplying these two strict inequalities preserves the direction (product of positive numbers is monotone in each argument when both sides are positive), giving

ab>n⋅n=n.ab > \sqrt{n} \cdot \sqrt{n} = n.

But ab=nab = n, so we obtain n>nn > n, a contradiction. Hence at least one of a,ba,b, call it aa, satisfies a≤na \le \sqrt{n}; and since a>1a>1 by hypothesis, aa is a divisor of nn with 1<a≤n1 < a \le \sqrt{n}. This proves the first statement. The second statement is the logical contrapositive of the first: "if nn composite then ∃\exists divisor ≤n\le \sqrt n" is equivalent to "if no divisor ≤n\le \sqrt n then nn not composite." Since n>1n > 1 and nn is not composite, by the trichotomy built into the definitions (n=1n=1 excluded, nn prime or composite exhaust the remaining cases for n>1n>1), nn must be prime. ■\blacksquare

∎

This theorem is precisely what licenses the trial-division algorithm: to test nn for primality, one only checks candidate divisors 2,3,4,…,⌊n⌋2, 3, 4, \dots, \lfloor \sqrt{n} \rfloor (or more efficiently just 22 and the odd numbers up to n\sqrt n); finding none of them dividing nn certifies primality.

TheoremExistence of prime factorization

Every integer n>1n > 1 can be written as a product of one or more primes (a single prime counts as a "product" of one prime).

Proof

We argue by strong induction on nn, for n≥2n \ge 2. Base case. n=2n = 2. Since 22's only positive divisors are 11 and 22, 22 is prime, and a single prime trivially counts as a product of primes (a product with one factor). Inductive step. Let n>2n > 2 and suppose, as the strong induction hypothesis, that every integer mm with 2≤m<n2 \le m < n can be written as a product of primes. We must show nn can be written as a product of primes. By the Lemma above (least divisor greater than 1 is prime), nn has a prime divisor pp; write n=p⋅mn = p \cdot m for some integer m≥1m \ge 1. Case 1: m=1m = 1. Then n=pn = p is itself prime, hence a product of one prime, and we are done. Case 2: m>1m > 1. Since p≥2p \ge 2, we have n=pm≥2mn = pm \ge 2m, and because n>2n > 2 and p≥2p \geq 2, in fact m=n/p≤n/2<nm = n/p \le n/2 < n. So mm satisfies 2≤m<n2 \le m < n (the lower bound m≥2m \geq 2 holds because we are in the case m>1m > 1 and mm is an integer). By the strong induction hypothesis, mm can be written as a product of primes:

m=q1q2⋯qkm = q_1 q_2 \cdots q_k

for some primes q1,…,qkq_1, \dots, q_k (with k≥1k \ge 1). Then

n=p⋅m=p⋅q1q2⋯qk,n = p \cdot m = p \cdot q_1 q_2 \cdots q_k,

which exhibits nn as a product of primes (pp together with q1,…,qkq_1,\dots,q_k). In both cases nn is a product of primes. By the principle of strong induction, every integer n≥2n \ge 2 is a product of primes. ■\blacksquare

∎
CorollaryTrial division terminates in a factorization

Repeatedly applying trial division — extracting a smallest prime factor p≤np \le \sqrt{n} (or concluding nn itself is prime when no such factor exists) and recursing on the quotient — produces, after finitely many steps, a complete prime factorization of any integer n>1n>1.

Proof

Each extraction step replaces the current number nn by a strictly smaller integer m=n/p≥1m = n/p \ge 1 (since p≥2p \ge 2), or halts because the current number is itself prime. The sequence of successive quotients is a strictly decreasing sequence of positive integers, hence by the Well-Ordering Principle it cannot decrease forever; it must reach a value that is prime (or 11, which occurs only after all prime factors have been extracted, contributing no further factor). This terminating process is exactly the constructive content of the existence proof above, so it outputs a valid prime factorization. ■\blacksquare

∎

Worked examples

Example 1 — testing a moderately large odd composite by hand: n=391n = 391. We want to know whether 391391 is prime, and if not, find its factorization, using trial division only up to 391\sqrt{391}. First, 391≈19.77\sqrt{391} \approx 19.77, so by the Trial Division Bound Theorem it suffices to test primes up to 1919: namely 2,3,5,7,11,13,17,192, 3, 5, 7, 11, 13, 17, 19.

  • 391391 is odd, so 2∤3912 \nmid 391.
  • Digit sum 3+9+1=133+9+1 = 13, not divisible by 33, so 3∤3913 \nmid 391.
  • Does not end in 00 or 55, so 5∤3915 \nmid 391.
  • 391/7=55.857…391 / 7 = 55.857\ldots, not an integer (7×55=3857 \times 55 = 385, 391−385=6≠0391 - 385 = 6 \neq 0), so 7∤3917 \nmid 391.
  • 391/11=35.5…391 / 11 = 35.5\ldots (11×35=38511 \times 35 = 385, remainder 66), so 11∤39111 \nmid 391.
  • 391/13=30.07…391 / 13 = 30.07\ldots (13×30=39013 \times 30 = 390, remainder 11), so 13∤39113 \nmid 391.
  • 391/17=23.0391 / 17 = 23.0 exactly: check 17×23=39117 \times 23 = 391. Indeed 17×23=17×20+17×3=340+51=39117 \times 23 = 17\times20 + 17\times3 = 340+51=391. ✓

So 1717 divides 391391, with 391=17×23391 = 17 \times 23. Since 2323 is itself prime (its only divisors below 23≈4.8\sqrt{23}\approx 4.8 to check are 2,32,3; 2323 is odd and 2+3=52+3=5 not divisible by 33), we conclude

391=17×23,391 = 17 \times 23,

a product of two primes. Note that we found the factor 1717 before reaching 19=⌊391⌋19 = \lfloor\sqrt{391}\rfloor, consistent with the theorem's guarantee that a composite number's smallest nontrivial factor lies at or below n\sqrt{n}.

Example 2 — a number requiring the full induction argument to unwind: n=2×3×5×7+1=211n = 2 \times 3 \times 5 \times 7 + 1 = 211. This example is chosen because 211211 is one more than the product of the first four primes — a classic "does the pattern break" test case, and it illustrates that trial division, not the appearance of the number, is what determines primality. Compute 211≈14.53\sqrt{211} \approx 14.53, so we must test primes up to 1414: that is 2,3,5,7,11,132,3,5,7,11,13.

  • 211211 is odd: 2∤2112 \nmid 211.
  • Digit sum 2+1+1=42+1+1=4: not divisible by 33.
  • Does not end in 00 or 55: 5∤2115 \nmid 211.
  • 211/7=30.14…211/7 = 30.14\ldots (7×30=2107\times 30 = 210, remainder 11): 7∤2117 \nmid 211.
  • 211/11=19.18…211/11 = 19.18\ldots (11×19=20911\times19=209, remainder 22): 11∤21111 \nmid 211.
  • 211/13=16.23…211/13 = 16.23\ldots (13×16=20813\times16=208, remainder 33): 13∤21113 \nmid 211.

No prime up to 1414 divides 211211, and by the Trial Division Bound Theorem this certifies that 211211 is prime — there is no need to test 1717 or beyond, since any composite factorization would force a factor ≤211\le \sqrt{211}. This illustrates the induction proof concretely: 211211 falls into the "Case 1" branch of the inductive step (m=1m=1), because its smallest divisor greater than 11 turns out to be 211211 itself.

CounterexampleWhy the hypothesis n>1n>1 is essential

The Existence of Prime Factorization theorem requires n>1n > 1. Consider dropping this hypothesis and asking whether n=1n = 1 can be written as a product of primes. If n=1n=1 were required to be a product of primes q1q2⋯qkq_1 q_2 \cdots q_k with k≥1k \ge 1, then since every prime qi≥2q_i \ge 2, the product would satisfy q1⋯qk≥2>1q_1 \cdots q_k \ge 2 > 1, contradicting n=1n=1. So 11 cannot be written as a product of one or more primes — the theorem's conclusion genuinely fails at n=1n=1. (If one instead allows the "empty product," conventionally equal to 11, then 11 is a product of zero primes — but this is a different, extended convention, not the statement proved above, and it is exactly why 11 is excluded from being called prime or composite: admitting it as prime would force factorizations to be non-unique, since one could always append extra factors of 11. The hypothesis n>1n>1 is not a cosmetic restriction; without it the clean statement "k≥1k \ge 1 primes multiply to nn" is false.)

Scope, edge cases & common traps

SituationCorrect treatment
n=1n = 1Neither prime nor composite; excluded from both theorems above
n=2n = 2Prime (the only even prime); base case of the induction
nn negative or zeroPrimality/compositeness undefined; definitions apply only to integers >1>1
Testing divisors up to n−1n-1Unnecessary and inefficient; n\sqrt n suffices by the Trial Division Bound Theorem
Assuming factorization is uniqueNot proved here — existence only; uniqueness is the Fundamental Theorem of Arithmetic

The mathematician behind it

Origins · 1 minEuclid of Alexandria and how this was discovered
EO
Euclid of Alexandria
fl. c. 300 BCE · Hellenistic Alexandria, Ptolemaic Egypt

Euclid systematized the theory of divisibility and primes in Books VII–IX of the Elements, giving the first rigorous definitions of prime and composite numbers and proving foundational results including the existence of prime factors and the infinitude of primes. Almost nothing is known of his life beyond his association with the great Library of Alexandria; his mathematical legacy, transmitted through countless manuscript copies, shaped the axiomatic method itself.

History
- c. 300 BCE — Euclid's Elements, Books VII–IX, define prime and composite numbers and prove a prime divides any product it divides (Euclid's Lemma).
- c. 200 BCE — Eratosthenes devises the Sieve of Eratosthenes, an efficient method for listing all primes up to a bound, implicitly relying on trial division ideas.
- 1801 — Gauss's Disquisitiones Arithmeticae gives the first fully modern, explicit statement and proof of unique factorization (the Fundamental Theorem of Arithmetic).
- 1896 — Hadamard and de la Vallée Poussin independently prove the Prime Number Theorem, describing the asymptotic density of primes.
- 2002 — Agrawal, Kayal, and Saxena publish the AKS primality test, showing primality can be decided in deterministic polynomial time, a modern descendant of the trial-division question "how do we certify primality efficiently?"
Why is 1 excluded from being prime or composite?

Declaring 11 neither prime nor composite is not arbitrary — it keeps later theorems clean. If 11 were called prime, then factorizations would stop being unique: 6=2×3=2×3×1=2×3×1×1=⋯6 = 2\times 3 = 2\times3\times1 = 2\times3\times1\times1=\cdots would all count as valid, different-length factorizations of the same number. Excluding 11 from primality means the Fundamental Theorem of Arithmetic can assert a single factorization (up to reordering) for every integer greater than 11, without an asterisk about stray factors of 11. The exclusion is a deliberate convention chosen precisely so the uniqueness theorem remains true and simple.

Is trial division the fastest way to test primality?

No. Trial division runs in time roughly proportional to n\sqrt n, which is efficient for small numbers (hundreds or thousands) but becomes impractical for numbers with hundreds of digits, as arise in cryptography. Modern primality tests such as Miller–Rabin (probabilistic, extremely fast) and AKS (deterministic, polynomial-time, proven correct in 2002) vastly outperform trial division for large inputs. However, trial division remains the conceptually simplest complete algorithm, and it is the natural starting point for understanding why any primality test must work.

Does the theorem in this article guarantee a unique factorization into primes?

No — this article proves only existence: every integer greater than 11 can be written as some product of primes. It does not prove that this product is unique up to the order of the factors; that stronger and more subtle statement is the Fundamental Theorem of Arithmetic, whose proof requires an additional tool (Euclid's Lemma: if a prime divides a product, it divides one of the factors) beyond what is used here.

How do I know the trial-division search bound n\sqrt n is correct and not just a rule of thumb?

It is a proved fact, not a heuristic: the Trial Division Bound Theorem shows that if n=abn=ab with 1<a,b<n1<a,b<n, then assuming both a,b>na,b>\sqrt n leads to ab>nab>n, contradicting ab=nab=n. So one of the two factors must be ≤n\le\sqrt n. This is a strict logical consequence of the ordering of real numbers, not an empirical pattern, and it holds for every composite nn without exception.

Can a negative integer or zero be prime?

By the standard convention used throughout elementary number theory (and in this article), primality and compositeness are defined only for integers strictly greater than 11. Zero and negative integers are simply outside the domain of these definitions. In more advanced settings (ring theory), the notion of "prime element" is extended to include appropriate negative integers like −2-2 up to multiplication by units, but that generalization is a separate, later construction and does not apply to the elementary definitions given here.

If a number fails divisibility by 2, 3, and 5, is it automatically prime?

No — this is exactly the trap described in the warning above. Passing a few small divisibility tests only rules out those specific small primes; it says nothing about larger prime factors like 7,11,13,…7, 11, 13, \dots up to n\sqrt n. For example 91=7×1391 = 7\times13 is not divisible by 2,3,2,3, or 55, yet it is composite. Only checking every integer (or every prime) up to ⌊n⌋\lfloor\sqrt n\rfloor and finding no divisor legitimately certifies primality.

Why does the proof use strong induction rather than ordinary induction?

Ordinary induction lets you assume the statement for n−1n-1 only, but the inductive step here needs the statement for m=n/pm = n/p, which can be much smaller than n−1n-1 (e.g. for n=100n=100, p=2p=2 gives m=50m=50, far below 9999). Strong induction assumes the statement for all integers from the base case up to n−1n-1, which is exactly the flexibility needed to invoke the hypothesis at the specific smaller value mm produced by dividing out a prime factor.

Before this

Where this leads