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.

The greatest common divisor of integers and , written , is the largest positive integer that divides both without remainder. It matters because it is the engine behind reducing fractions to lowest terms, solving linear equations over the integers, and inverting elements in modular arithmetic. The surprising fact is that you can find the GCD of enormous numbers — without factoring either one — using only repeated subtraction or division, a process so fast that it is still the standard method after more than two thousand years. The Extended Euclidean Algorithm goes further, expressing as an integer combination , which is the key to division in modular systems like RSA encryption.

The Core Insight

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

Divisibility and Common Divisor

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:

1
⟳write with ; show common divisors of equal those of .

The base case that terminates the recursion:

2
⟳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:

3
⟳among integers for varying , exactly one lies in by the well-ordering of .

Bézout's Identity

For any integers and not both zero, there exist integers and such that

4
Moreover, is the smallest positive integer expressible in the form .

⟳the Extended Euclidean Algorithm constructs by tracking coefficients back through each division step.

GCD–LCM Relation

For positive integers and ,

5

⟳compare prime-factorization exponents — for each prime, .

Why It Holds / Derivation

The Euclidean Algorithm Terminates and is Correct

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.

Euclidean Algorithm tiling: gcd(48, 18) = 6

gcd(48, 18): peel off largest squares 18 18 12 side 6 = gcd 48 = 2·18 + 12, 18 = 1·12 + 6, 12 = 2·6 + 0 → gcd = 6

Euclid of Alexandria | fl. c. 300 BCE

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

Plain GCD by the Euclidean Algorithm

Given: Find . Steps — apply repeatedly, recording :

The last nonzero remainder is . Each line preserves the GCD by Step 1 of the proof.

Answer:

Extended Euclidean Algorithm — Bézout coefficients

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

  1. RSA cryptography — generating the private key requires computing a modular inverse, done by the Extended Euclidean Algorithm; guarantees the inverse exists.
  2. Reducing fractions — every computer algebra system and calculator simplifies by dividing both by .
  3. Gear ratios and mechanical timing — two meshing gears with tooth counts and return to their starting alignment after rotations, computed via .
  4. Audio and signal sampling — converting between sample rates (e.g., 44.1 kHz and 48 kHz) uses the GCD to find the smallest common resampling grid.
  5. Tiling and resolution scaling — rendering or cutting a rectangle into identical square units uses of side lengths, and aspect-ratio reduction (e.g., 1920:1080 → 16:9) divides by their GCD.
  6. The Stern–Brocot / continued-fraction methods in computer graphics for best rational approximations rely on Euclidean steps.
  7. Error-correcting codes and hashing — polynomial versions of the algorithm over finite fields decode Reed–Solomon codes used in CDs, QR codes, and data storage.

Historical Development

  • c. 300 BCE — Euclid, Elements VII.1–2, states the subtraction-based algorithm to test commensurability of magnitudes.
  • c. 200 BCE – 100 CE — Chinese mathematicians develop related remainder methods; the Sunzi Suanjing poses problems leading to the Chinese Remainder Theorem.
  • 6th century CE — Indian mathematician Aryabhata describes the kuṭṭaka ("pulverizer") method, an extended Euclidean procedure for solving linear congruences.
  • 1624 — Bachet de Méziriac states integer solutions of in his recreational mathematics text, foreshadowing Bézout.
  • 1779 — Étienne Bézout proves the identity now bearing his name in a more general (polynomial) setting.
  • 1801 — Gauss's Disquisitiones Arithmeticae systematizes congruences and the role of in number theory.
  • 1844 — Gabriel Lamé proves that the number of division steps is bounded by a constant times the number of digits — the first explicit algorithm complexity result, linked to Fibonacci numbers.
  • 1961 — Josef Stein publishes the binary GCD algorithm, replacing division with shifts and subtractions for efficiency on computers.
  • 20th–21st c. — The algorithm becomes foundational in computational number theory, underpinning public-key cryptography (RSA, 1977).

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

Before this

Where this leads