Fermat's Little Theorem
Fermat's Little Theorem: If is prime and is not divisible by , then . Equivalently, for every integer . Key result in words: raising any integer to the -th power leaves it unchanged modulo a prime . Where it applies: modular arithmetic, primality testing, cryptography (RSA), and the structure of the multiplicative group . Who/when: stated by Pierre de Fermat in 1640; first published proof by Leonhard Euler, 1736.
In the world of arithmetic modulo a prime , multiplying every nonzero residue by a fixed nonzero element merely permutes that set. Permutations preserve products, so the product of all elements equals the product of all elements times . Cancelling the (invertible) product forces . The primality of is exactly what guarantees that nonzero residues can be cancelled — that is a field.
Formal Statement
For integers , and a positive integer , we write (" is congruent to modulo ") iff divides . The set of integers congruent to modulo is the residue class . Modular arithmetic is well-defined: if and , then and .
The theorem has two equivalent standard forms.
Derivation hint: this is the "coprime" form; it requires so that is invertible modulo .
Derivation hint: multiply [1] by ; this version holds even when since then both sides are . Here the symbols are: a prime number; an arbitrary integer; the greatest common divisor; and denotes congruence modulo .
Let be a prime. Then for every integer with , equation [1] holds. Equivalently, for every integer whatsoever, equation [2] holds. Moreover, the order of modulo — the least positive with — divides .
Derivation hint: by the division algorithm write with ; then forces by minimality of the order.
For any modulus and any integer coprime to ,
where is Euler's totient function, . FLT is the special case prime, since . Derivation hint: replace the full residue system in the proof below by the reduced residue system of units modulo , which has size .
Why It Holds / Derivation
We prove form [1]. Fix a prime and an integer with .
Step 1. Consider the set of nonzero residues . Form the products and reduce each modulo .
Step 2. No product is . Since is prime and and for , we have (Euclid's lemma). So each lies in .
Step 3. The products are distinct. If , then ; since , , forcing for . Hence the map is injective on a finite set, thus a bijection of onto itself — a permutation.
Step 4. Because multiplication is commutative, the product of all the equals the product of all elements of :
Derivation hint: Step 3 says the left product runs over the same set of residues, merely reordered.
Step 5. Factor out from each of the terms on the left:
Derivation hint: .
Step 6. Since is prime, — no factor of is divisible by . Therefore is invertible modulo and may be cancelled, yielding
Derivation hint: cancel the unit from both sides of [6]; cancellation is legitimate precisely because is a field.
∎:::proof[Alternative Proof via Induction (form [2])] We show for all integers by induction; negative and the coprime form follow.
Base: .
Inductive step: assume . By the binomial theorem,
Derivation hint: split off the and terms ( and ) from the binomial expansion. For , the binomial coefficient is divisible by , because divides the numerator but not the denominator (all factors are , and is prime). Hence the sum vanishes modulo , giving , completing the induction.
A magistrate at the parlement of Toulouse, Fermat pursued mathematics as an avocation yet helped found number theory, analytic geometry, probability, and the calculus of maxima and minima. He communicated results in letters — typically without proofs. In a letter of 18 October 1640 to Bernard Frénicle de Bessy he stated what we now call his Little Theorem, remarking he would send the proof "if it were not so long." That proof, if it existed, was never recorded; Euler supplied the first published demonstration nearly a century later. Fermat's habit of stating theorems without proof also produced his far harder Last Theorem ( has no positive integer solutions for ), resolved only by Wiles in 1994.
Building Intuition
Think of the nonzero residues mod as beads on a circular bracelet. "Multiply everything by " is a shuffle that picks up each bead and drops it in another slot — but it never collapses two beads together and never sends one to the empty (zero) slot. Because it's a clean reshuffle (a permutation), the collection of beads is unchanged; only the labels moved. The total product of bead-labels is therefore the same before and after, and the only difference between "before" and "after" is the factor of that got multiplied in times. So that accumulated factor must be invisible — i.e., . The primality of is what forbids two beads from merging: in , multiplying by sends both and toward collisions because is composite, and the bracelet trick fails.
Worked Examples
Given: Compute .
Step 1. is prime and , so FLT gives . (Check: .)
Step 2. Reduce the exponent modulo : , so .
Step 3. Therefore
Derivation hint: split the exponent using , then evaluate the residual .
Step 4. , so .
Given: Find the multiplicative inverse of modulo .
Step 1. Since is prime and , FLT gives , hence . So the inverse is .
Derivation hint: , so is the inverse.
Step 2. Compute by repeated squaring: . Then , .
Step 3. .
Step 4. Verify: . ✓
Common Misconceptions
The implication runs prime ⟹ congruence, not the reverse. From " for some particular " you cannot conclude that is prime. Composite numbers can satisfy the Fermat congruence for many bases; those that satisfy it for one base are Fermat pseudoprimes to that base, and those satisfying it for all coprime bases are Carmichael numbers. Also note the coprimality requirement in form [1]: if then , not — use form [2] instead, which is unconditional.
Take , which is composite. Yet for every integer coprime to ,
Derivation hint: is divisible by — the values of for — so FLT holds modulo each prime factor, and the Chinese Remainder Theorem combines them. A naive "Fermat test" with random bases would repeatedly declare "probably prime." Carmichael numbers () are infinite in number (Alford–Granville–Pomerance, 1994), which is why the strong (Miller–Rabin) test, not the plain Fermat test, is used in practice.
Connections
FLT is the prime case of Euler's Theorem via the Euler Totient Function, and both are corollaries of Lagrange's Theorem (Group Theory) applied to the unit group : an element's order divides the group order. The structure theorem that is cyclic sharpens FLT — it guarantees a Primitive Root of order exactly . The induction proof exposes the Freshman's Dream identity , a hallmark of the Frobenius Endomorphism in fields of characteristic . FLT also underpins Wilson's Theorem (via ), the Chinese Remainder Theorem when gluing congruences, and the theory of Quadratic Residues through Euler's criterion .
Real-World Applications
Historical Development
Subtleties & Limits
While FLT itself is settled, the boundary questions it spawns remain rich and partly open. Fermat quotients encode finer information; primes with are Wieferich primes, and only two ( and ) are known — whether infinitely many exist is open, and surprisingly, this connects to the first case of Fermat's Last Theorem. The distribution of bases for which a composite passes the Fermat test, the density of Carmichael numbers, and the exact strength of the Artin conjecture (that a given non-square integer is a primitive root for infinitely many primes — unproven unconditionally) all probe how sharply FLT's converse fails. Algorithmically, whether deterministic polynomial-time primality (achieved by AKS, 2002) can be made as fast as the Fermat-based probabilistic tests in practice remains a live engineering frontier.
See Also
Euler's Theorem · Euler Totient Function · Lagrange's Theorem (Group Theory) · Carmichael Number · Primitive Root · Wilson's Theorem · Chinese Remainder Theorem · Quadratic Residues · RSA Cryptosystem · Frobenius Endomorphism