CalcMathic

Numbers and fractions

GCF and LCM calculator

Type two to four whole numbers separated by commas. The calculator breaks each into prime factors, then builds the greatest common factor and the least common multiple from them.

Whole numbers from 1 up, for example 24, 36, 60.

Press Calculate. The answer and every step of the working will show here.

How it works

The greatest common factor (GCF) is the biggest number that divides evenly into all of your numbers. The least common multiple (LCM) is the smallest number that all of them divide into. Both come from the same place: the prime factorization of each number.

A prime factorization writes a number as a product of primes. For 12 that is 2 × 2 × 3, written 2^2 × 3. For 18 it is 2 × 3 × 3, written 2 × 3^2. Once the primes are laid out, the rules are short. For the GCF, take only the primes that appear in every number, each to the smallest power it has. For the LCM, take every prime that appears in any number, each to the largest power it has.

The calculator finds the prime factors by trial division, which is the same method as a factor tree. It prints the factorization of each number, then the two products. For exactly two numbers, it also shows the check GCF × LCM = the product of the two numbers, which always holds and is a fast way to catch a slip. The result cards also reduce the fraction made from your two numbers, since dividing by the GCF is how fractions are simplified.

The formula

  • GCF = the product of the shared primes, each to its smallest power
  • LCM = the product of all primes that appear, each to its largest power
  • For two numbers: GCF × LCM = a × b
  • Coprime numbers have GCF = 1, so their LCM is simply a × b

Worked example

Find the GCF and LCM of 12 and 18. The prime factors are 12 = 2^2 × 3 and 18 = 2 × 3^2. The shared primes are 2 and 3. The smallest power of 2 is 2^1 and the smallest power of 3 is 3^1, so the GCF is 2 × 3 = 6. The largest power of 2 is 2^2 and the largest power of 3 is 3^2, so the LCM is 4 × 9 = 36. Check: 6 × 36 = 216 and 12 × 18 = 216.

More examples

Three numbers. For 24, 36 and 60: 24 = 2^3 × 3, 36 = 2^2 × 3^2 and 60 = 2^2 × 3 × 5. Every number has a 2 and a 3, with smallest powers 2^2 and 3^1, so the GCF is 4 × 3 = 12. The largest powers are 2^3, 3^2 and 5, so the LCM is 8 × 9 × 5 = 360.

Numbers with nothing in common. 8 = 2^3 and 9 = 3^2 share no prime, so the GCF is 1 and the LCM is 8 × 9 = 72. Numbers like these are called coprime.

Simplifying a fraction. To reduce 12/18, divide both by their GCF of 6 and you get 2/3.

Larger numbers. 48 and 180: 48 = 2^4 × 3 and 180 = 2^2 × 3^2 × 5. The GCF is 2^2 × 3 = 12 and the LCM is 2^4 × 3^2 × 5 = 720.

Common mistakes

  • Mixing up the two. The GCF is never bigger than the smallest number, and the LCM is never smaller than the biggest. If your GCF is larger than one of the numbers, something went wrong.
  • Using the biggest power for the GCF. The GCF uses the smallest shared power, and the LCM uses the largest power.
  • Leaving out primes that appear in only one number. They are ignored for the GCF but must be included in the LCM.
  • Stopping a factor tree too early. 12 = 3 × 4 is not finished, because 4 is not prime. Keep going until every branch ends in a prime.
  • Treating 1 as a prime. It is not. The number 1 has no prime factors, which is why a list that includes 1 has a GCF of 1.

When to use it

The GCF simplifies fractions, splits things into equal groups, and finds the largest square tile that fits a rectangular floor. If you have 24 pencils and 36 erasers and want identical kits with nothing left over, the GCF of 12 tells you the most kits you can make.

The LCM finds common denominators when adding fractions, and solves "when will these happen together again" problems such as bus timetables, gears and repeating patterns. Teachers set both in the same unit because the prime factor method answers both questions at once.

Read the guideGCF and LCM explained with three methods7 min read

Common questions

What is the difference between GCF and GCD?

Nothing. Greatest common factor (GCF), greatest common divisor (GCD) and highest common factor (HCF) are three names for the same number. Textbooks in the US usually say GCF.

How do I find the GCF of three or four numbers?

Use the same method. List the prime factors of each number and take the primes that appear in all of them, each to the smallest power. The calculator accepts up to four numbers.

Is there a quick way to check my LCM?

The LCM must be a multiple of every number you started with. For two numbers you can also check that GCF × LCM equals the product of the two numbers, as shown in the last step.

What if the GCF is 1?

Then the numbers are coprime, or relatively prime. They can still be composite: 8 and 9 are both composite, yet they share no factor. Their LCM is just their product.

Why do I need the LCM to add fractions?

Fractions can only be added when the pieces are the same size. The least common denominator is the LCM of the bottoms. For 1/6 + 1/4 the LCM of 6 and 4 is 12, so you add 2/12 + 3/12 = 5/12.

Can I enter zero or a decimal?

No. Factors and multiples are defined here for positive whole numbers. Zero and decimals show an error. Use the decimal to fraction calculator if you want to convert a decimal first.

You might also need

Need a quick calculation instead? The free scientific calculator on the homepage handles roots, powers, trig and logs, and the math guides explain each method step by step.