Euclidean algorithm

The Euclidean algorithm is a procedure for finding the greatest common divisor of two integers. It repeatedly replaces a pair of numbers with the smaller number and the remainder from division, stopping when that remainder is zero; the last nonzero remainder is the greatest common divisor. Its extended form also finds integer coefficients expressing that divisor as a linear combination of the original numbers.

Last updated
21 October 2026
Confidence
High (99%)
Sources
5
Versions
1
This article was researched and drafted with AI assistance and checked by an automated review pass. It is not guaranteed to be accurate — verify important facts against the references below.

Procedure

For positive integers a and b with a ≥ b, divide a by b and write a = qb + r, where q is the quotient and 0 ≤ r < b. Replace the pair (a, b) with (b, r) and repeat. For example, to find the greatest common divisor of 252 and 105: 252 = 2 × 105 + 42; 105 = 2 × 42 + 21; 42 = 2 × 21 + 0. The final nonzero remainder, 21, is the greatest common divisor. If the starting numbers are equal, the first remainder is zero and that common value is the answer.

Why it works

A number divides both a and b exactly when it divides both b and the remainder r = a − qb. The two pairs therefore have the same common divisors and the same greatest common divisor. At each step, the remainder is a nonnegative integer smaller than the previous divisor, so the sequence must terminate. When the remainder reaches zero, the last nonzero remainder divides the preceding terms; because the common divisors have been preserved at every step, it is the greatest common divisor of the original pair.

The extended algorithm and applications

Working backward through the division equations expresses the greatest common divisor d as an integer linear combination of the inputs: d = xa + yb for some integers x and y. This is known as Bézout's identity. In the example above, 21 = 5 × 105 − 2 × 252. The result helps determine when an equation ax + by = c has integer solutions: such solutions exist exactly when the greatest common divisor of a and b divides c. When that divisor is 1, the coefficients also provide a multiplicative inverse in modular arithmetic. The algorithm is used in number theory and remains practical for computer calculation.

Historical context

The method is named for Euclid, whose Elements describes finding a greatest common measure of two numbers in Book VII. Proposition 2 presents a repeated-subtraction procedure: subtract the smaller magnitude from the larger until the common measure is exposed. Repeated division with remainders is a more efficient form of the same principle. Britannica dates Euclid's account to about 300 BCE. The modern algorithm retains the ancient idea that replacing a pair by a smaller pair can preserve its common divisors while making progress toward a result.

Key facts

Purpose
Finds the greatest common divisor of two integers using successive divisions and remainders.
Stopping rule
Stop when the remainder is zero; the last nonzero remainder is the greatest common divisor.
Extended form
Expresses the greatest common divisor as an integer linear combination of the original inputs.
Historical source
Euclid's Elements, Book VII, includes a greatest-common-measure procedure; Britannica dates the account to about 300 BCE.

Ask about this article

Answers use only “Euclidean algorithm” and its references, with citations.

References

  1. 1.
    Euclidean algorithm Algorithm, Division & GCD

    Encyclopaedia Britannica · encyclopedia · reliability: high · retrieved 21 October 2026

    Supports: Definition, iterative division example, historical attribution to Euclid, and uses in mathematics.

  2. 2.
    Euclidean Algorithm

    Wolfram MathWorld · other · reliability: high · retrieved 21 October 2026

    Supports: Remainder-based procedure, its termination and output, extended form, and related mathematical applications.

  3. 3.
    Euclid's Elements, Book VII, Proposition 2

    Clark University (David E. Joyce's translation and commentary) · other · reliability: high · retrieved 21 October 2026

    Supports: Primary-text presentation of Euclid's repeated-subtraction procedure for finding a greatest common measure.

  4. 4.
    Euclid (325 BC - 265 BC) - Biography

    MacTutor History of Mathematics Archive, University of St Andrews · other · reliability: high · retrieved 21 October 2026

    Supports: Historical context for Euclid, his teaching in Alexandria, and the Elements.

  5. 5.
    Extended Euclidean Algorithm

    Wolfram MathWorld · other · reliability: high · retrieved 21 October 2026

    Supports: Applications of the extended procedure to linear Diophantine equations and modular inverses.

References are suggested by the research engine and may be incomplete. Unverified URLs are omitted rather than guessed.

Article history

  1. Version 121 October 2026 · EditorCreated by Zapia