GCF and LCM Calculator

Enter two or more whole numbers separated by commas or spaces. You get the greatest common factor and least common multiple, the prime factorization of each number and the Euclidean algorithm worked step by step.

2 to 20 positive whole numbers, separated by commas, spaces or new lines.

Results update as you type.

Result

Greatest common factor of 12, 18, 24
6
Least common multiple
72
Prime factors of 12
2² × 3
Prime factors of 18
2 × 3²
Prime factors of 24
2³ × 3
Product of all numbers
5,184

Euclidean algorithm for 18 and 12

  1. 18 = 1 × 12 + 6
  2. 12 = 2 × 6 + 0

The remainder reaches 0 in the last line, so the divisor there is the answer: GCF(18, 12) = 6.

With more than two numbers, repeat with the running result: GCF(6, 24) = 6. So GCF(12, 18, 24) = 6.

What are the GCF and the LCM?

The greatest common factor (GCF, also called the greatest common divisor or highest common factor) of a set of whole numbers is the largest number that divides all of them exactly. The least common multiple (LCM) is the smallest positive number that all of them divide into exactly. For 12, 18 and 24 the GCF is 6 and the LCM is 72: 6 is the biggest number that goes into all three, and 72 is the first number that appears in all three times tables. The GCF can never be larger than the smallest number in the set, and the LCM can never be smaller than the largest.

Finding them with prime factorization

Write each number as a product of primes, then compare the powers of each prime. The GCF takes the lowest power of every prime that appears in all the numbers; the LCM takes the highest power of every prime that appears in any of them.

NumberPrime factorizationPower of 2Power of 3
122² × 32²3
182 × 3²23²
242³ × 32³3
GCFlowest powers23
LCMhighest powers2³3²

Example: GCF(12, 18, 24) = 2 × 3 = 6 and LCM(12, 18, 24) = 2³ × 3² = 8 × 9 = 72. The prime factorization calculator shows how each factorization is found.

The Euclidean algorithm

Factoring becomes slow for large numbers, so the GCF of two numbers is usually found with the Euclidean algorithm, which only needs division. Divide the larger number by the smaller and note the remainder, then divide the previous divisor by that remainder, and keep going until the remainder is 0. The last divisor is the GCF. For 18 and 12: 18 = 1 × 12 + 6, then 12 = 2 × 6 + 0, so GCF(18, 12) = 6. It works because any number that divides both a and b also divides the remainder of a ÷ b, so each step keeps the same set of common factors while making the numbers smaller. For three or more numbers, take the GCF of the first two, then the GCF of that result and the next number, and so on.

GCF × LCM = a × b

For any two positive whole numbers, the product of their GCF and LCM equals the product of the numbers themselves. With 12 and 18: GCF = 6, LCM = 36, and 6 × 36 = 216 = 12 × 18. This gives a fast route to the LCM once Euclid has produced the GCF: LCM(a, b) = a × b ÷ GCF(a, b). Note that the identity only holds for two numbers. For 12, 18 and 24 the product is 5,184 while GCF × LCM is 6 × 72 = 432.

Where the GCF and LCM are used

  • Simplifying fractions: divide the numerator and denominator by their GCF. 18/24 ÷ 6 gives 3/4.
  • Adding fractions: the lowest common denominator is the LCM of the denominators. 1/12 + 1/18 uses 36: 3/36 + 2/36 = 5/36. The fraction calculator does this automatically.
  • Equal groups and tiling: the largest square tile that covers a 12 by 18 floor without cutting is 6 by 6.
  • Repeating events: buses leaving every 12 and every 18 minutes depart together every LCM(12, 18) = 36 minutes.
  • Ratios: dividing both parts of a ratio by their GCF gives its simplest form, as in the ratio calculator.

How to use this calculator

  1. Type two or more positive whole numbers (up to 20) in the box, separated by commas, spaces or line breaks.
  2. The GCF appears as the headline figure, with the LCM, each prime factorization and the product below.
  3. Follow the Euclidean algorithm steps for the first two numbers to see how the GCF is reached, and the chain of GCFs when you entered more than two.
  4. Click Reset to return to the example 12, 18, 24.

Tips and common mistakes

  • Mixing up the two: the GCF is never bigger than your smallest number and the LCM is never smaller than your largest. If a result breaks that rule, you have swapped them.
  • The LCM is not simply the product: 12 × 18 = 216, but the LCM is 36. The product is only the LCM when the numbers are coprime.
  • Zero and negatives: this calculator works with positive whole numbers only. Every number divides 0, so GCF and LCM involving 0 are not useful.
  • Huge LCMs: the LCM of many unrelated numbers grows quickly. The calculator reports when the exact value exceeds 9,007,199,254,740,991 rather than showing a rounded figure.

Frequently asked questions

Is the GCF the same as the GCD and the HCF?

Yes. Greatest common factor (GCF), greatest common divisor (GCD) and highest common factor (HCF) are three names for the same number: the largest whole number that divides every number in the set without a remainder. US textbooks tend to say GCF, UK and Indian textbooks say HCF, and mathematicians say GCD.

What does it mean when the GCF is 1?

The numbers share no factor apart from 1 and are called coprime or relatively prime, such as 8 and 15. A fraction whose numerator and denominator are coprime is already in lowest terms, and the LCM of two coprime numbers is simply their product.

Can the LCM be smaller than one of the numbers?

No. The LCM is a multiple of every number in the set, so it is always at least as large as the largest number. It equals the largest number exactly when that number is already a multiple of all the others, for example LCM(4, 6, 12) = 12.

How do I find the GCF of very large numbers?

Use the Euclidean algorithm rather than factoring. Repeatedly divide the larger number by the smaller and keep the remainder; the last non-zero remainder is the GCF. Even for 12-digit numbers this takes at most a few dozen divisions, whereas finding the prime factorization of a large number can take far longer.

How do I find the lowest common denominator of fractions?

The lowest common denominator is the LCM of the denominators. To add 1/12 and 1/18, enter 12 and 18: the LCM is 36, so the fractions become 3/36 and 2/36 and the sum is 5/36. The fraction calculator linked below does the whole addition for you.

Related calculators