Divisibility, GCD, and the Euclidean Algorithm

One-line statement: For integers (not both zero), the greatest common divisor is the largest positive integer dividing both, and the Euclidean Algorithm computes it via repeated division with remainder. Key result in words: can be expressed as an integer linear combination (Bézout's identity), and the Euclidean Algorithm finds it in division steps. Where it applies: number theory, cryptography (RSA, modular inverses), abstract algebra (PIDs, ideals), computer algebra, rational arithmetic. Who/when: Euclid (~300 BCE, Elements Book VII); formalized over millennia into modern number theory.

A nonzero integer divides an integer , written , if for some integer . The greatest common divisor of two integers (not both zero) is the unique largest positive integer that divides both. The Euclidean Algorithm exploits the invariance of the gcd under subtraction of multiples — — to reduce the problem rapidly to a base case. The surprising and deeply consequential fact is Bézout's identity: the gcd is always expressible as for integers , which makes the gcd not just a number but a generator of an ideal. This single algorithm underlies modular inverses, the structure of , and the entire edifice of public-key cryptography.

The Core Insight

If divides both and , then divides every integer combination . In particular divides for any integer . Therefore the set of common divisors of equals the set of common divisors of . Choosing replaces with the remainder , which is strictly smaller. Iterating shrinks the numbers until the remainder is — and the last nonzero remainder is the gcd. The gcd is preserved at every step; only the representation gets simpler.

Formal Statement

Divisibility

For integers with , we say divides (equivalently is a divisor of , or is a multiple of ), written , if there exists an integer with:

1
⟳this is a definition; is the quotient. Note for every nonzero , since .

Basic properties (for nonzero divisors where needed): and imply ; implies for all ; divisibility is transitive (, ); and with forces .

Division Algorithm

For any integers and with , there exist unique integers (quotient) and (remainder) such that:

2
⟳existence by taking so that ; uniqueness by assuming two representations and bounding their difference below .

Greatest Common Divisor

For integers not both zero, the greatest common divisor is the unique positive integer satisfying:

3
⟳the third clause (every common divisor divides ) is stronger than mere maximality in size; it characterizes the gcd up to sign and is the form that generalizes to rings.

By convention for , and is undefined (or set to ). Integers are coprime (relatively prime) when .

Bézout's Identity

For integers not both zero, there exist integers such that:

4
⟳let be the smallest positive value of ; show and via the division algorithm (a smaller positive remainder would contradict minimality), and that any common divisor divides .

Equivalently, is the smallest positive element of the set , and that set is exactly the set of all multiples of — i.e. the ideal in .

Key Reduction Lemma

For integers with and :

5
⟳show the common-divisor sets of and coincide. If and then ; conversely if and then .

Why It Holds / Derivation

Correctness and Termination of the Euclidean Algorithm

We prove the algorithm — assume WLOG — computes the gcd and halts.

Step 1 — Setup. Define , . Repeatedly apply the division algorithm:
6
⟳each line is one application of [2] with divisor , producing remainder .
Step 2 — Termination. The remainders form a strictly decreasing sequence of nonnegative integers . A strictly decreasing sequence of nonnegative integers must reach in finitely many steps. Let be the first zero remainder; then is the last nonzero remainder. Step 3 — Invariance. By [5], each division step preserves the gcd:
7
⟳direct application of the Key Reduction Lemma to line [6].
Step 4 — Chaining. Composing [7] from up through :
8
⟳telescope the chain of equalities; the final term uses .

Hence the algorithm returns .

Complexity. Each two consecutive remainders satisfy (since either already, or forcing and ). Thus the number of steps is . The worst case occurs for consecutive Fibonacci numbers (Lamé's theorem), giving roughly steps where is the golden ratio.

One pass of the Euclidean Algorithm on gcd(48, 18) = 6

gcd(48,18): repeated division until remainder 0 48 = 18·2 + 12 18 = 12·1 + 6 12 = 6·2 + 0 ← last nonzero remainder = 6 = gcd 48 18 12 6

Euclid of Alexandria | fl. ~300 BCE

Euclid, working at the Library of Alexandria, presented the algorithm now bearing his name in the Elements, Propositions VII.1–VII.2, originally phrased for "magnitudes" via repeated subtraction (anthyphairesis, "reciprocal subtraction"). His version applied both to integers and to commensurable geometric lengths; if the subtraction never terminates, the magnitudes are incommensurable — the same idea that proves irrational. The algorithm is among the oldest still in everyday computational use, and the ideal-theoretic generalization (gcd as ideal generator) flows directly from his proof structure.

Building Intuition

Picture two rulers of integer lengths and laid end-to-end measuring problems. The gcd is the length of the largest "tile" that can pave both rulers exactly with no gap. The Euclidean Algorithm tiles the long ruler with copies of the short one, then re-tiles the leftover strip with copies of it, and so on — the leftover that finally tiles perfectly is the answer. Geometrically: draw an rectangle, repeatedly cut off the largest possible square; the side of the smallest square you can cut equals . Bézout's identity then says: among all combinations you can build with signed copies of the two rulers, the shortest nonzero length you can reach is exactly the gcd — you can never reach anything shorter, and you can reach every multiple of it.

Worked Examples

Plain Euclidean Algorithm: gcd(1071, 462)

Given: , . Steps (each line is ):
9
⟳apply [2] each line; last nonzero remainder is the gcd.

The last nonzero remainder is .

Check: and , and . ✓

Extended Euclidean Algorithm: Bézout coefficients & a modular inverse

Given: find with , then compute if it exists. Forward pass:
10
⟳standard division chain; gcd is the last nonzero remainder, .

So .

Back-substitution (express as a combination):
11
⟳substitute each remainder from the bottom of [10] upward, collecting coefficients of the two original numbers.
Modular inverse? Since , has no inverse mod 240 — the congruence is unsolvable. (An inverse exists iff the numbers are coprime.) However, , so is a "half-inverse." For contrast: , and the same method gives since .

Common Misconceptions

"Greatest" means largest in magnitude — and that's the whole definition. Not quite. The defining property [3] is that the gcd is divisible-into by every common divisor, not merely larger than them. These coincide in , but in general rings (e.g. polynomial rings) "largest" has no meaning while the divisibility characterization still works. Also beware: for all , but equals the gcd only for special — Bézout coefficients are not unique (you can add ). Bézout fails when "gcd" is the largest common divisor in a non-PID. In the ring , the elements and have only units as common divisors (a "gcd" of in the divisibility sense), yet no elements satisfy . The ideal is not principal. The lesson: Bézout's identity is equivalent to being a principal ideal domain, not a free gift of having gcds. Over we are safe because is a PID; the Euclidean Algorithm is precisely what proves this.

Connections

The Euclidean Algorithm is the computational engine behind much of elementary number theory and algebra. Via Bézout's identity it produces modular inverses, the backbone of solving Linear Congruences and the Chinese Remainder Theorem. Bézout's identity also gives the cleanest proof of Euclid's Lemma ( or ), which in turn yields the Fundamental Theorem of Arithmetic. Abstractly, a ring on which a Euclidean Algorithm runs is a Euclidean Domain, which is automatically a Principal Ideal Domain and hence a Unique Factorization Domain — a tower of implications all anchored by repeated division. The same algorithm runs verbatim on the polynomial ring over a field, computing polynomial gcds and underpinning partial fractions and continued fractions.

Real-World Applications

  • RSA cryptography: computing the private exponent uses the Extended Euclidean Algorithm; security relies on coprimality of and .
  • Modular arithmetic / hashing: finding multiplicative inverses in for error-correcting codes, checksums, and finite-field arithmetic (AES uses gcd over ).
  • Rational number arithmetic: every computer algebra system reduces fractions to lowest terms by dividing out .
  • Continued fractions & Diophantine approximation: the quotients of the algorithm are the continued-fraction expansion of , used in calendar design (leap-year rules) and gear-ratio construction (Antikythera mechanism, clockmaking).
  • Computer graphics & rasterization: Bresenham-style line algorithms and lattice-point counting use gcd to find primitive direction vectors and tiling periods.
  • Cryptographic key agreement (Diffie–Hellman, elliptic curves): inversion in finite fields via extended gcd is a core primitive.
  • Signal processing / sampling: the gcd of sampling periods determines the period of a sum of periodic signals.

Historical Development

  • ~300 BCE — Euclid's Elements Books VII & X present the algorithm via repeated subtraction for integers and incommensurable magnitudes.
  • ~500 CE — Aryabhata's kuttaka ("pulverizer") method solves linear Diophantine equations , equivalent to the extended algorithm, for astronomical calculations.
  • 628 CE — Brahmagupta extends Indian work on linear Diophantine equations and modular reasoning.
  • 1624 — Bachet de Méziriac states the integer solvability of when in his Problèmes plaisants.
  • 1779 — Étienne Bézout publishes results on resultants and linear combinations; the identity is later named for him (though stated earlier by Bachet).
  • 1801 — Gauss's Disquisitiones Arithmeticae systematizes congruences, gcd, and the structure of .
  • 1844 — Gabriel Lamé proves the worst-case step count is bounded via Fibonacci numbers — an early result in the analysis of algorithms.
  • Late 1800s–1900s — Dedekind, Kummer, and Noether generalize gcd to ideals, defining Euclidean domains, PIDs, and UFDs.
  • 1976–1978 — Diffie–Hellman and RSA make the extended Euclidean inverse computation a cornerstone of modern cryptography; binary and subquadratic gcd variants (Stein, 1967; Knuth–Schönhage) optimize it for machines.

Subtleties & Limits

The Euclidean Algorithm itself is fully resolved, but its surroundings host genuine difficulties. (1) Which rings are Euclidean? It is unknown for many number rings whether a Euclidean function exists; the question "is the ring of integers of norm-Euclidean?" is settled only for finitely many , and the general "Euclidean but not norm-Euclidean" classification involves deep open conjectures (related to Artin's conjecture on primitive roots). (2) Average-case analysis: the average number of steps for random inputs is (Heilbronn, Dixon), but the finest distributional questions connect to dynamical systems and transfer operators (Baladi–Vallée) that remain active research. (3) gcd of polynomials over inexact (floating-point) coefficients is ill-posed — tiny perturbations destroy common factors — motivating ongoing work on "approximate gcd." (4) The relationship between the Euclidean property and being a PID is subtle: every Euclidean domain is a PID, but there exist PIDs (e.g. ) that are not Euclidean for any function — proving non-Euclideanness required new techniques.

See Also

Bézout's Identity · Euclid's Lemma · Continued Fractions · Principal Ideal Domain · Unique Factorization Domain · Modular Arithmetic · Diophantine Equations · Least Common Multiple

Before this

Where this leads