A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Fermat's Little Theorem

Graduate Depth 78 in the knowledge graph ☐ I know this ☆ Set as goal
36topics build on this
367prerequisites beneath it
See this on the map →
Properties of CongruencesGroup Definition and Examples→→Cryptographic Applications: RSAEuler's Criterion+3 more
fermats-little-theorem prime-powers modular-exponentiation

Core Idea

If p is prime and gcd(a,p) = 1, then ap-1 ≡ 1 (mod p). This cornerstone result characterizes the exponent structure of multiplicative groups mod p and enables fast modular exponentiation in cryptography.

Explainer

You already know from congruence properties that modular arithmetic is self-consistent: if a ≡ b (mod p), then ak ≡ bk (mod p). Fermat's Little Theorem takes this arithmetic into the multiplicative structure: if p is prime and a is not divisible by p, then ap-1 ≡ 1 (mod p). The key intuition comes from examining the set of multiples {a, 2a, 3a, ..., (p-1)a} reduced mod p. Because p is prime and gcd(a, p) = 1, these p-1 values are all distinct and nonzero — they produce the set {1, 2, ..., p-1} in some scrambled order. So their product equals the product of all nonzero residues: a · 2a · 3a · ... · (p-1)a ≡ 1 · 2 · 3 · ... · (p-1) (mod p). Factoring out ap-1 from the left yields ap-1 · (p-1)! ≡ (p-1)! (mod p). Since (p-1)! is nonzero mod p, cancel it to get ap-1 ≡ 1 (mod p).

The theorem has a tidy corollary: for any integer a (not just those coprime to p), ap ≡ a (mod p). This form is often more convenient because no divisibility check is needed. Both forms appear throughout number theory and in computing.

The practical power is enormous. Modular exponentiation — the engine of RSA encryption — relies on reducing large exponents mod (p-1). For example, to compute 7100 mod 13: since 13 is prime, 712 ≡ 1 (mod 13). Write 100 = 8·12 + 4, so 7100 = (712)8 · 74 ≡ 18 · 74 ≡ 74 ≡ 2401 ≡ 9 (mod 13). Without Fermat's Little Theorem, this computation over cryptographic-scale numbers — hundreds of digits long — would be infeasible.

If you have encountered group theory, the result has a clean restatement: the nonzero residues mod p form a multiplicative group of order p-1. By Lagrange's theorem, every element's order divides the group order, so ap-1 = 1 for all elements a. Fermat's Little Theorem is Lagrange's theorem specialized to the group (Z/pZ)*. This group-theoretic view also explains why the exponent is p-1 specifically: it equals the size of the group, not an arbitrary bound.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Set Operations: Union, Intersection, and Complement → Proof by Cases → Proving by Cases and Exhaustion → Vacuous Truth and Trivial Cases → Proof by Cases (Proof by Exhaustion) → Mathematical Induction → Divisibility and Greatest Common Divisor → The Euclidean Algorithm → Modular Arithmetic and Congruences → Properties of Congruences → Fermat's Little Theorem

Longest path: 79 steps · 367 total prerequisite topics

Prerequisites (2)

Leads To (5)