GCD and LCM calculator — what it works out
Enter two or more whole numbers and this GCD and LCM calculator returns both values at once: the GCD (greatest common divisor) and the LCM (least common multiple). It also shows the Euclidean algorithm steps, so you see not just the answer but where it comes from.
GCD goes by other names depending on where you learned math: GCF (greatest common factor) is the standard term in US classrooms, and HCF (highest common factor) is the standard term in the UK, India, and much of the Commonwealth. All three — GCD, GCF, HCF — mean exactly the same thing, and this calculator covers all of them. GCD (or GCF/HCF) is what you use to simplify fractions; LCM is what you use to find a common denominator. The calculator handles negative numbers and zero, accepts any number of inputs (not just two), and updates the result as soon as you type.
How to use the calculator
- Enter your numbers. Type at least two whole numbers, separated by a space or comma — e.g.
12, 18. The calculator also accepts three or more numbers at once. - Read the GCD and LCM. Both results appear side by side immediately — there’s no need to pick which calculation to run.
- Expand the working. The Euclidean algorithm steps show each division-with-remainder down to the final answer.
- Negative numbers and zero both work. The sign of a number doesn’t change its GCD or LCM (the calculator works with absolute values) — no extra setting needed.
How GCD and LCM are calculated
The GCD (also called GCF or HCF) of two whole numbers is the largest number that divides both of them with no remainder. The LCM is the smallest number that both of them divide into evenly. The calculator finds the GCD with the Euclidean algorithm — one of the oldest known algorithms in mathematics, dating back to Euclid’s “Elements” around 300 BCE — then derives the LCM from it:
LCM(a, b) = |a × b| ÷ GCD(a, b)
The Euclidean algorithm works by repeated division: divide the larger number by the smaller one, keep the remainder, then repeat with the smaller number and that remainder — until the remainder hits 0. The last non-zero remainder is the GCD.
Step-by-step example: GCD and LCM of 12 and 18
- 18 divided by 12 leaves a remainder of 6 (since 18 = 1×12 + 6).
- 12 divided by 6 leaves a remainder of 0 (since 12 = 2×6 + 0).
- The last non-zero remainder is 6, so GCD(12, 18) = 6.
- The LCM follows from the formula: LCM = (12 × 18) ÷ 6 = 216 ÷ 6 = 36.
Prime factorization confirms the same result: 12 = 2²×3, 18 = 2×3². The GCD takes the lowest power of each shared factor: 2¹×3¹ = 6. The LCM takes the highest power of each factor appearing in either number: 2²×3² = 36. Both methods agree — the Euclidean algorithm is just faster, especially for large numbers, where factoring gets expensive.
GCD and LCM of three or more numbers
With more than two numbers, the calculator reduces them pairwise: it finds the GCD (or LCM) of the first two, combines that with the next number, and so on — the order doesn’t affect the final answer.
For 12, 18, and 30:
- GCD(12, 18) = 6 (see the example above).
- GCD(6, 30) = 6 (since 30 = 5×6 + 0).
- GCD(12, 18, 30) = 6.
- LCM(12, 18) = 36 (see the example above).
- LCM(36, 30): GCD(36, 30) = 6, so LCM = (36 ÷ 6) × 30 = 6 × 30 = 180.
- LCM(12, 18, 30) = 180.
Coprime numbers: when GCD equals 1
For 8 and 9: 9 = 1×8 + 1, then 8 = 8×1 + 0 → GCD(8, 9) = 1. Numbers like this are called coprime (or relatively prime) — they share no common divisor other than 1. When that happens, the LCM always equals the product of the numbers, since the divisor in the formula is 1: LCM = 8 × 9 = 72.
What GCD and LCM are used for: fractions
GCD simplifies fractions. To reduce a fraction to its lowest terms, divide the numerator and denominator by their GCD. For the fraction 12/18: GCD(12, 18) = 6, so 12÷6 = 2 and 18÷6 = 3 — the fraction 12/18 simplifies to 2/3, and it can’t be reduced any further.
LCM gives you a common denominator. To add or subtract fractions with different denominators, you convert them to a common denominator equal to the LCM of those denominators. For fractions with denominators 12 and 18, the common denominator is LCM(12, 18) = 36 — the smallest one possible, which keeps the numbers in the calculation as small as they can be. For three fractions with denominators 12, 18, and 30, the common denominator is the LCM of all three, which is 180.
Zero and negative numbers
The sign of a number doesn’t change its GCD or LCM — the calculator works with absolute values. GCD(−12, 18) gives exactly the same result as GCD(12, 18), which is 6, and the LCM is 36.
Zero is a special case. Zero is divisible by every number, so GCD(0, n) is always the absolute value of the other number: GCD(0, 5) = 5. But the only common multiple of zero and any number is zero itself, so LCM(0, 5) = 0. When both numbers are zero, the accepted convention is GCD(0, 0) = 0 — the calculator shows a short note explaining this isn’t an error.