Euclidean Algorithm Calculator (GCD Steps)

Find the GCD of two whole numbers with the Euclidean algorithm, step by step, plus the LCM and the Bézout identity gcd = ax + by.

A whole number with up to 60 digits. Negative numbers use their size (the GCD is never negative).

Results

Greatest common divisor (GCD)
29
Euclidean algorithm (7 divisions)
10,672 = 2 × 4,147 + 2,378 4,147 = 1 × 2,378 + 1,769 2,378 = 1 × 1,769 + 609 1,769 = 2 × 609 + 551 609 = 1 × 551 + 58 551 = 9 × 58 + 29 58 = 2 × 29 + 0 The last non-zero remainder is 29, so gcd = 29.
Bézout identity (gcd as a combination of a and b)
29 = 175 × 4147 − 68 × 10672
Found by working the division steps backwards (the extended Euclidean algorithm).
Least common multiple
1,526,096
lcm = |a × b| ÷ gcd.
a/b in lowest terms
143/368

How it’s calculated

The Euclidean algorithm finds the greatest common divisor (GCD) without factoring. Divide the larger number by the smaller, then replace the pair by (smaller number, remainder) and repeat. Any number that divides both numbers also divides the remainder, so the GCD never changes; the remainders shrink until one is 0, and the last non-zero remainder is the GCD.

a = q × b + r (0 ≤ r < b) gcd(a, b) = gcd(b, r) stop when r = 0: the last non-zero remainder is the GCD lcm(a, b) = |a × b| ÷ gcd(a, b)

Working the steps backwards writes the GCD as a combination of the two numbers, gcd = a·x + b·y (the Bézout identity). This is the extended Euclidean algorithm, used to solve linear Diophantine equations and to find modular inverses.

Example: gcd(4147, 10672). 10672 = 2 × 4147 + 2378; 4147 = 1 × 2378 + 1769; 2378 = 1 × 1769 + 609; 1769 = 2 × 609 + 551; 609 = 1 × 551 + 58; 551 = 9 × 58 + 29; 58 = 2 × 29 + 0. The last non-zero remainder is 29, and working backwards gives 29 = 175 × 4147 − 68 × 10672. The LCM is 4147 × 10672 ÷ 29 = 1,526,096.

Frequently asked questions

Is GCD the same as GCF and HCF?

Yes. Greatest common divisor (GCD), greatest common factor (GCF) and highest common factor (HCF) are three names for the same number.

Why does the Euclidean algorithm work?

If d divides a and b, it also divides a − q × b, which is the remainder r. So a and b have exactly the same common divisors as b and r. The numbers keep shrinking, so the process ends, and gcd(g, 0) = g.

What are Bézout coefficients used for?

They solve ax + by = gcd(a, b). When the GCD is 1, the coefficient of a is the inverse of a modulo b, which is how modular inverses (used in RSA) are found.

How many steps does it take?

Very few. The number of divisions is at most about 5 times the number of digits of the smaller number (Lamé’s theorem), so even 60-digit numbers need only a few hundred steps.

Embed this calculator

Add this free calculator to your own website. Copy the code below into your page’s HTML:

Need this calculator branded, changed or built around your own prices?See custom business solutions →

Sources

Formulas are taken from the free public references above. Results are provided “as is” for informational and educational purposes only. See our disclaimer.

Added · Last updated · How we check our calculators

Spotted a mistake or missing option? Report a problem· Suggest a calculator