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.
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
- Elementary Number Theory (Raji), §1.6 The Euclidean Algorithm (gcd(4147, 10672) = 29 = 175·4147 − 68·10672) — LibreTexts Mathematics
- Elementary Number Theory (Raji), §2.4 Least Common Multiple — LibreTexts Mathematics
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