Greatest common divisor (GCD)

6

Least common multiple (LCM): 36

LCM = (first number ÷ GCD) × second number

How it works

The GCD is the largest whole number that divides evenly into both numbers, found using the Euclidean algorithm.

The LCM is the smallest whole number that both numbers divide evenly into, found from the GCD: (first number ÷ GCD) × second number.

The Euclidean algorithm finds the GCD by repeated division rather than by testing every candidate factor. For 84 and 126, dividing 126 by 84 leaves a remainder of 42; dividing 84 by that 42 leaves a remainder of zero, so the last non-zero remainder, 42, is the GCD. The LCM then follows in one step: (84 ÷ 42) × 126 = 2 × 126 = 252.

Formula: LCM = (first number ÷ GCD) × second number

Examples

Two numbers with common factors

12 and 18 have a GCD of 6 and an LCM of 36.

Two coprime numbers

4 and 7 share no common factor other than 1, so their GCD is 1 and their LCM is their product, 28.

Large numbers with a large common factor

3,600 and 4,800 share a GCD of 1,200, and their LCM is 14,400, which is four times the smaller input and three times the larger.

One number divides the other

When one value divides evenly into the other, the GCD is the smaller number and the LCM is the larger: 24 and 6 give a GCD of 6 and an LCM of 24.

Common uses

  • Reducing a ratio or a pair of quantities to their simplest form, since the GCD divides both sides — simplifying a ratio is the same reduction.
  • Timing two repeating cycles so that they coincide: a 15-minute timer and a 21-minute timer next chime together after 105 minutes, the shortest interval both cover exactly.
  • Scaling two quantities up to a whole number of equal portions, so a batch of 4 and a batch of 6 both divide neatly into 12 equal parts.
  • Reducing a fraction by hand, such as 14/84 simplified to 1/6 by dividing the numerator and the denominator by their GCD of 14.

Things to keep in mind

  • Both numbers must be positive whole numbers.
  • "HCF" (highest common factor) is another name for the same thing as GCD — the two terms are used in different regions for an identical calculation.
  • Decimals are rejected rather than rounded, so entering 12.5 raises an error instead of quietly using 12 or 13.
  • The least common multiple is refused once either input passes 9,007,199,254,740,991, the largest whole number a JavaScript calculation can hold exactly, because an LCM is usually far larger than either input.
  • Results are rounded to 12 significant digits and displayed to at most 10 decimal places, so a long least common multiple can be rounded even when both inputs are held exactly.

Frequently asked questions

What is the difference between GCD and HCF?

Nothing — GCD (greatest common divisor) and HCF (highest common factor) are two names for exactly the same calculation.

How is the LCM related to the GCD?

Once you know the GCD, the LCM is (first number ÷ GCD) × second number. For 12 and 18, that is (12 ÷ 6) × 18 = 36.

Can I get the same answers by factorising instead?

Yes. Factorise each number into primes, then keep every prime raised to the smaller of the two powers for the GCD, and every prime raised to the larger power for the LCM. The Factors Calculator lists the whole-number factors of a number and the Prime Number Checker picks out the prime ones; the factors and primes guide sets out the method.

Why is the least common multiple often much bigger than the two inputs?

The GCD keeps only what the two numbers share, while the LCM has to be divisible by each number in full, including every prime power that appears in either of them, so it picks up the parts the other number is missing. That is why 3,600 and 4,800 share 1,200 but need 14,400. Because the LCM is the product of the two inputs divided by their GCD, a large shared factor keeps it small relative to that product, and a GCD of 1 makes it the full product.

Background and method