The greatest common divisor is the largest whole number dividing all of them, and the way to find it is not to factorise. Euclid's method is to divide, keep the remainder, and repeat. When the remainder reaches zero, the previous one is the answer. It works because any number dividing both a and b ...
Euclid’s algorithm does not need the factors. Divide, keep the remainder, repeat — the last non-zero remainder is the answer. Two sixteen-digit numbers resolve in about six steps, where factorising either one would take tens of millions of divisions. It is the oldest algorithm still in everyday use, and nothing has improved on it.
GCD OF 1,071, 462
gcd
21
lcm
23,562
Every one of them is a whole number of 21s: 51, 22 respectively. Nothing larger divides them all. Euclid took 3 steps.
| Step | Division | Remainder |
|---|---|---|
| 1 | 1,071 = 2 × 462 + 147 | 147 |
| 2 | 462 = 3 × 147 + 21 | 21 |
| 3 | 147 = 7 × 21 + 0 | 0 — stop |
3 steps against a bound of 15. Lamé proved in 1844 that the count never exceeds five times the number of digits in the smaller input, which here is 3 digits. The worst cases for any given size are consecutive Fibonacci numbers — gcd(75025, 46368) needs 23 steps, more than any random pair of that size manages. That bound is why Euclid stays fast on numbers far too large to factor.
Bézout: 1,071(−3) + 462(7) = 21. The gcd of any two numbers can always be written as a whole multiple of one plus a whole multiple of the other, and running the same divisions backwards produces the coefficients. It is what makes modular inverses computable, and so what makes RSA decryption possible at all.
THE ALGORITHM
Why it works. Any number dividing both a and b also divides their remainder, and any number dividing b and the remainder also divides a. So the pair (a, b) and the pair (b, a mod b) have exactly the same common divisors — replacing one with the other loses nothing while making the numbers smaller. Repeat and the smaller number reaches zero, at which point the other is the answer.
Euclid’s algorithm · exact for any size of input
Enter two or more whole numbers. Signs are ignored, because divisibility does not care about them — if 3 divides 12 it divides −12 equally.
Read the division chain rather than just the answer. Each line is one step of the algorithm, and the last non-zero remainder is the result.
Compare the step count with the bound shown. Euclid finishes in at most five times the digit count of the smaller number, which is what keeps it fast on very large inputs.
With exactly two numbers you also get the Bézout coefficients — the whole multiples of each that add to the gcd. They are what modular inverses are built from.
| Rule | Formula | What it is for |
|---|---|---|
| Euclid’s algorithm | gcd(a, b) = gcd(b, a mod b) | Repeat until the remainder is zero. The last non-zero remainder is the answer. |
| Base case | gcd(a, 0) = a | Everything divides zero, so the other number is the largest common divisor. |
| Two numbers | gcd(a,b) × lcm(a,b) = a × b | Always true for exactly two. Do not extend it to three — see below. |
| Three numbers | gcd·lcm = abc only if pairwise coprime | gcd(2,3,4) × lcm(2,3,4) = 12, not 24. The two-number identity does not generalise. |
| Correct triple identity | lcm(a,b,c) = abc·gcd(a,b,c) ÷ (gcd(a,b)gcd(b,c)gcd(a,c)) | Inclusion–exclusion on the exponents. Verified over 40,000 triples. |
| Several numbers | gcd(a,b,c) = gcd(gcd(a,b), c) | Fold pairwise. The order makes no difference to the result. |
| Bézout’s identity | gcd(a,b) = ax + by | Integers x and y always exist. The extended algorithm finds them. |
| Coprime | gcd(a, b) = 1 | No common factor above 1. Then lcm is simply the product. |
| Scaling | gcd(ka, kb) = k · gcd(a, b) | A common factor pulled out of both stays a common factor. |
| Reducing a fraction | a/b ÷ gcd(a,b) on both | Dividing through by the gcd gives lowest terms in one step. |
| Lamé’s bound | steps ≤ 5 × digits of the smaller | Proved in 1844. Verified here across 200,000 random pairs with no violations. |
| Worst case | consecutive Fibonacci numbers | gcd(75025, 46368) needs 23 steps — more than any random pair of that size. |
| Against factoring | Euclid is logarithmic; factoring is not | A 16-digit pair resolves in about six steps rather than 10⁷ divisions. |
| Negatives and zero | gcd(−a, b) = gcd(a, b); gcd(0,0) undefined | Sign is irrelevant. Two zeros have no greatest common divisor at all. |
24 Times Table
Calculate instantly →
Quadratic Equation Solver
Calculate instantly →
Logarithm Calculator
Calculate instantly →
Fraction Calculator
Calculate instantly →
Fraction Simplifier
Calculate instantly →
Linear Equation Solver
Calculate instantly →
25 Times Table
Calculate instantly →
26 Times Table
Calculate instantly →
27 Times Table
Calculate instantly →
Simultaneous Equations Solver (2×2)
Calculate instantly →
28 Times Table
Calculate instantly →
Exponent Calculator
Calculate instantly →
29 Times Table
Calculate instantly →
30 Times Table
Calculate instantly →
Times Tables Mega Calculator
Calculate instantly →
Square Root of 10
Calculate instantly →
Square Root of 1
Calculate instantly →
Square Root Mega
Calculate instantly →
Square Root of 2
Calculate instantly →
23 Times Table
Calculate instantly →
Last updated: August 4, 2026 · Euclid’s algorithm with Bézout coefficients · gcd × lcm = ab holds for two numbers, not for three.