GCD and LCM Calculator

MathLast updated: August 17, 2026

The greatest common divisor (GCD) is the largest number that divides all of the given numbers exactly, while the least common multiple (LCM) is the smallest number that is a multiple of all of them. The GCD is what you use to reduce fractions; the LCM is what you use to put fractions over a common denominator and to find when periodic events coincide.

This calculator handles more than two numbers as well: just paste the values separated by commas, spaces, or line breaks. Along with the results it gives a table showing the prime factorization of every number and of the GCD and LCM themselves, and when exactly two numbers are entered it also verifies GCD × LCM = a × b.

Enter at least 2 and at most 20 positive integers, separated by commas, spaces, or line breaks.

Formula

GCD: multiply the SMALLEST powers of the shared prime factors
LCM: multiply the LARGEST powers of all the prime factors
For two numbers: GCD(a, b) × LCM(a, b) = a × b
Euclidean algorithm: GCD(a, b) = GCD(b, a mod b)

The identity GCD × LCM = a × b holds ONLY for two numbers; it cannot be used as a check with three or more. Another common error is taking the larger exponents for the GCD: the GCD uses the smaller exponents, the LCM the larger ones.

How to Calculate

  1. Type your numbers into the box — commas, spaces, or line breaks all work as separators.
  2. Make sure you have entered at least 2 and at most 20 positive integers.
  3. Read the GCD and LCM results; if you entered two numbers, the GCD × LCM check appears in the interpretation.
  4. Use the table to inspect the prime factorization of every input and of the two results.

Worked Examples

12 and 18

Since 12 = 2² × 3 and 18 = 2 × 3², the GCD takes the smaller exponents and gives 2 × 3 = 6, while the LCM takes the larger ones and gives 2² × 3² = 36. Check: 6 × 36 = 216 = 12 × 18.

GCD — greatest common divisor: 6 · LCM — least common multiple: 36 · Count of numbers entered: 2

Three numbers: 4, 6, and 8

For 4 = 2², 6 = 2 × 3, and 8 = 2³, the largest number dividing all three is GCD = 2; the smallest of their common multiples is LCM = 2³ × 3 = 24.

GCD — greatest common divisor: 2 · LCM — least common multiple: 24 · Count of numbers entered: 3

Bus departure problem: 15, 25, and 35

Three buses leaving every 15, 25, and 35 minutes will depart together again LCM(15, 25, 35) = 525 minutes after their first joint departure. The GCD of these numbers is 5.

GCD — greatest common divisor: 5 · LCM — least common multiple: 525 · Count of numbers entered: 3

Frequently Asked Questions

How do you calculate the GCD?
Factor the numbers into primes and multiply the smallest powers of only the SHARED prime factors. For 12 = 2² × 3 and 18 = 2 × 3², the shared factors are 2 and 3; with the smaller exponents this gives 2¹ × 3¹ = 6. For two numbers, the Euclidean algorithm (repeated division with remainder) is a faster route.
How do you calculate the LCM?
Multiply the largest powers of ALL the prime factors appearing in the factorizations. For 12 = 2² × 3 and 18 = 2 × 3² this gives 2² × 3² = 36. In practice the formula LCM(a, b) = a × b / GCD(a, b) is also used.
Which problems call for the GCD and which for the LCM?
The GCD typically appears in 'divide into equal parts' problems, such as cutting fabrics of different lengths into equal and as-large-as-possible pieces. The LCM appears in 'meeting again' problems: events that repeat at different intervals (buses, bells, blinking lights) falling on the same moment.
What does it mean for numbers to be coprime?
Numbers whose GCD is 1 are called coprime (relatively prime); 8 and 15, for instance, are coprime even though neither is prime on its own. The LCM of two coprime numbers is simply their product.
Does GCD × LCM = a × b always hold?
It holds only for TWO numbers. With three or more it generally fails: for 4, 6, and 8, GCD × LCM = 2 × 24 = 48 while the product is 192. That is why the calculator shows the check only when exactly two numbers are entered.
Can the GCD be larger than the smallest of the numbers?
No. Because the GCD divides every one of the numbers, it cannot exceed the smallest of them; at most it equals it (when the smaller number divides the others). In the same way, the LCM can never be smaller than the largest number.