Greatest Common Divisor and the Euclidean Algorithm
The greatest common divisor (GCD) of two integers is the largest positive integer dividing both. The Euclidean Algorithm computes it efficiently by repeated division: . It is foundational to number theory and underlies modular arithmetic, fractions, and modern cryptography. The method appears in Euclid's Elements (c. 300 BCE), making it one of the oldest algorithms still in everyday use.
A common divisor of and is also a common divisor of and (and more generally ). So replacing the larger number by its remainder upon division by the smaller never changes the set of common divisors — but it shrinks the numbers fast. Repeat until one number becomes ; the other is the GCD.
Formal Statement
For integers and with , we say divides (written ) if there exists an integer such that . A common divisor of and is an integer with and . The greatest common divisor is the largest such positive integer (defined for not both zero).
The central recursive identity:
Derivation hint: write with ; show common divisors of equal those of . The base case that terminates the recursion:
Derivation hint: every integer divides , so the common divisors of and are exactly the divisors of ; the largest is . The Division Algorithm guarantees each step is well-defined:
Derivation hint: among integers for varying , exactly one lies in by the well-ordering of .
For any integers and not both zero, there exist integers and such that
Moreover, is the smallest positive integer expressible in the form .
Derivation hint: the Extended Euclidean Algorithm constructs by tracking coefficients back through each division step.
For positive integers and ,
Derivation hint: compare prime-factorization exponents — for each prime, .
Why It Holds / Derivation
Step 1 — The key lemma. Suppose . We claim the common divisors of are exactly the common divisors of . If and , then , so divides and . Conversely, if and , then , so divides and .
Step 2 — Equal sets, equal maxima. Since the two pairs share the same set of common divisors, they share the same greatest common divisor:
Step 3 — Termination. By equation , each remainder satisfies . So the second argument strictly decreases at every step while staying non-negative. A strictly decreasing sequence of non-negative integers must reach in finitely many steps.
Step 4 — Reading off the answer. When the remainder hits , equation gives the GCD as the last nonzero remainder.
∎Imagine tiling a rectangle of size with the largest possible identical square tiles. Cut off the biggest square you can (side ) repeatedly from the -side; what's left is a smaller rectangle . Repeat. The process must end with a rectangle that is perfectly filled by squares of some side — and that is . Every cut throws away a region that was already tileable by the final square, so the final square size never changes. The algorithm is literally a geometric subtraction game.
Euclid, working in Hellenistic Alexandria, compiled the Elements, thirteen books that organized Greek mathematics into a deductive system. Propositions VII.1–VII.2 describe what we now call the Euclidean Algorithm, framed geometrically as anthyphairesis ("reciprocal subtraction") of line segments and quantities. Euclid used it to determine whether two magnitudes are commensurable (have a common measure). His version used repeated subtraction rather than division, but the logic is identical. Almost nothing is known of Euclid's life; his lasting monument is the method of rigorous proof that the Elements established and that this algorithm exemplifies.
Worked Examples
Given: Find .
Steps — apply repeatedly, recording :
The last nonzero remainder is . Each line preserves the GCD by Step 1 of the proof.
Answer:
Given: Find integers with .
Forward (find the GCD):
Back-substitute to express as a combination:
So , . Check: . ✓
Answer:
Common Misconceptions
The GCD is not found by listing prime factors for large numbers — and you don't need to. Students often think you must factor and first. Factoring is computationally hard for large numbers; the Euclidean Algorithm sidesteps it entirely, using only divisions. Also note: is defined for negatives via , and conventionally is undefined (or set to ), since every integer divides and there is no largest common divisor.
Bézout coefficients are not unique. A student might claim "there is one pair with ." In the example above, , but also . In general, all solutions are
where . There are infinitely many.
The GCD threads through much of elementary number theory. Two integers with are called coprime, the central condition in Modular Arithmetic for an element to have a multiplicative inverse. Bézout's identity is the engine behind solving Linear Diophantine Equations , which are solvable exactly when . The GCD also underlies Fractions in Lowest Terms (divide numerator and denominator by their GCD) and connects to the Fundamental Theorem of Arithmetic via the prime-exponent formula for and .
Real-World Applications
Historical Development
Subtleties & Limits
The Euclidean Algorithm is fast, but precise questions about it remain rich. Its worst case occurs for consecutive Fibonacci numbers, , which forces the maximum number of steps — this links the algorithm to the golden ratio , since the step count grows like . The average-case behavior connects to deep results in the metric theory of continued fractions (the Gauss–Kuzmin distribution), where the average number of steps involves constants like . Generalizing GCD to rings beyond leads to the theory of Euclidean domains and the open subtlety that some unique-factorization domains admit no Euclidean function at all — so "having a GCD" is strictly weaker than "having a Euclidean algorithm."
See Also
Least Common Multiple · Bézout's Identity · Coprime Integers · Euclidean Domains · Fibonacci Numbers · Modular Arithmetic · Continued Fractions · Fundamental Theorem of Arithmetic