GCD & LCM Calculator

How do I find GCD and LCM?

How it is calculated

The greatest common divisor (GCD) is the largest whole number dividing both inputs; the least common multiple (LCM) is the smallest positive number that both divide. The tool finds the GCD with Euclid's algorithm: replace the pair (a, b) with (b, a mod b) until the remainder is zero, and the last non-zero value is the GCD. The LCM then follows from LCM = a ÷ GCD × b, which avoids overflow. Both inputs must be positive whole numbers; decimals are truncated to integers and zero or negatives give no result. The GCD is used to simplify fractions, while the LCM gives a common denominator.

Worked example

Take 12 and 18. Euclid: 18 mod 12 = 6, so (12, 18) → (18, 12) → (12, 6); then 12 mod 6 = 0, so the GCD is 6. LCM = 12 / 6 × 18 = 2 × 18 = 36. So GCD = 6 and LCM = 36. Check: 6 × 36 = 216 = 12 × 18, because for any two numbers GCD × LCM equals their product.

Try this example →

Common mistakes

  • Mixing up the two: the GCD is never larger than the smaller number, the LCM never smaller than the larger one.
  • Entering decimals such as 12.9, which are cut to 12.
  • Multiplying the numbers (12 × 18 = 216) and calling it the LCM, which only holds when they share no common factor.
  • Using zero or negative numbers, which the tool does not accept.

About this calculator

This calculator finds the greatest common divisor (GCD) — the largest number that divides both inputs evenly — and the least common multiple (LCM) — the smallest number that both inputs divide into evenly — for two integers, using the Euclidean algorithm under the hood.

GCD is used to reduce a fraction to its simplest form (dividing numerator and denominator by their GCD) and comes up in scheduling problems, like finding the largest even group size two teams can both be split into. LCM is used to find a common denominator when adding or subtracting fractions, and to solve 'when do these two repeating events line up again' problems, like two buses that pass a stop every 12 and 18 minutes. Students working through math homework and anyone solving a scheduling or fraction problem by hand use this to check their work quickly.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    Two numbers at a time is the limit here, but you can chain the results: the GCD of three numbers is the GCD of the first pair's GCD and the third number, and the LCM works the same way. The LCM is handy for timing. Two buses leaving every 12 and 18 minutes are together again after 36 minutes. To simplify a fraction like 18/12, divide both parts by the GCD, 6, to get 3/2. What are you using it for?

Popular calculators

All Calculators