calculators.dev

LCM and GCD Calculator

The greatest common divisor (GCD) and least common multiple (LCM) are the two workhorses of whole-number arithmetic. The GCD is the largest number that divides two integers exactly — the key to reducing a fraction or simplifying a ratio. The LCM is the smallest number both integers divide into — the key to finding a common denominator or lining up two repeating cycles. This calculator finds both at once for any two whole numbers using Euclid's algorithm, the oldest method still in everyday use.

Calculate

Default result: 4

A whole number.

A whole number.

LCM and GCD Calculator · Result

calculators.dev

Greatest common divisor (GCD)

4

12 × 8

Least common multiple (LCM)
24
4

Reviewed by the calculators.dev team · Last updated 2026-06-23

How to calculate

Enter two whole numbers. The calculator runs Euclid's algorithm: it divides the larger number by the smaller, keeps the remainder, then repeats with the smaller number and that remainder until the remainder reaches zero. The last non-zero remainder is the greatest common divisor. From there the least common multiple comes straight from the relationship LCM = (a × b) ÷ GCD. Both results appear together and update the moment you change either number.

GCD by Euclid: gcd(a, b) = gcd(b, a mod b), repeating until the second number is 0; the remaining first number is the GCD. LCM from the GCD: lcm(a, b) = |a × b| ÷ gcd(a, b). The two are linked — their product always equals the product of the original numbers, so finding one immediately gives the other.
Example calculation

Euclid's algorithm finds the GCD of 12 and 8 by repeated remainders: 12 divided by 8 leaves 4, then 8 divided by 4 leaves 0, so the last non-zero remainder, 4, is the greatest common divisor. The least common multiple then follows from the identity LCM = (12 × 8) ÷ GCD = 96 ÷ 4 = 24 — the smallest number both 12 and 8 divide into evenly.

gcd
4
lcm
24

Assumptions

  • Both inputs are whole numbers; the GCD and LCM are defined for integers, not for decimals or fractions.
  • Negative numbers are handled by their absolute value, since divisibility ignores sign.
  • The GCD of a number and zero is the number itself, and the LCM in that case is zero, because zero has no positive multiples in common.

Common mistakes

  • Confusing the GCD with the LCM — the GCD is never larger than the smaller input, while the LCM is never smaller than the larger input.
  • Listing every factor by hand and missing one, where Euclid's remainder method cannot slip.
  • Trying to take the GCD of non-integers; convert to whole numbers first or the idea does not apply.

Frequently asked questions

What is the GCD of 12 and 8?

The greatest common divisor of 12 and 8 is 4 — the largest whole number that divides both exactly.

How is the LCM related to the GCD?

They multiply to the product of the two numbers: LCM × GCD = a × b. So LCM = (a × b) ÷ GCD; for 12 and 8 that is 96 ÷ 4 = 24.

What is Euclid's algorithm?

A fast way to find the GCD by repeatedly replacing the larger number with the remainder of dividing it by the smaller, until the remainder is zero.

Is the GCD the same as the GCF?

Yes. Greatest common divisor (GCD) and greatest common factor (GCF) are two names for the same thing — the largest number that divides both inputs.