GCD and LCM Calculator
Find the greatest common divisor (highest common factor) and the least common multiple of two or more whole numbers, with the prime factors that explain them.
The GCD (also called HCF) is the largest number that divides all of the inputs; the LCM is the smallest number they all divide into.
How the gcd and lcm calculator works
The GCD (also called HCF) is the largest number that divides all of the inputs; the LCM is the smallest number they all divide into. Euclid's algorithm finds the GCD by repeated remainders; for two numbers, LCM = a × b ÷ GCD. For more numbers the calculator folds the operation across the list.
Formula: gcd(a, b) = gcd(b, a mod b); lcm(a, b) = |a × b| / gcd(a, b)
Worked examples
| Inputs | Greatest common divisor | Note |
|---|---|---|
| 12, 18, 30 | 6 | gcd 6, lcm 180 |
| 8 and 12 | 4 | gcd 4, lcm 24 |
| 7 and 9 | 1 | coprime; lcm 63 |
FAQFrequently asked questions
What is the difference between GCD and HCF?
Nothing — greatest common divisor and highest common factor are the same thing.
When do I need the LCM?
Adding fractions with different denominators (the common denominator is the LCM) and timing problems ("when do the two buses next leave together?").
How does Euclid's algorithm work?
Replace the larger number with the remainder of dividing it by the smaller, and repeat until the remainder is zero; the last non-zero number is the GCD.
What is the LCM of three numbers?
Take the LCM of the first two, then the LCM of that result and the third.
Does 0 have a GCD?
gcd(a, 0) = a for any a; the calculator ignores zeros.
Where these figures come from
- NIST Digital Library of Mathematical Functions — reference definitions for elementary and special functions
- Wolfram MathWorld — definitions and formulas for every topic on this page
- NIST/SEMATECH e-Handbook of Statistical Methods — the statistical formulas (mean, variance, z, confidence intervals, sample size)
- National curriculum in England — Mathematics — the terms and methods taught in UK schools
Last checked: September 2026. Formulas are fixed by mathematics and do not change with tax years or regulations.