GCF and LCM Calculator

Find the GCF and LCM of 2–6 numbers, with full working.

Whole numbers (2 to 6)

Try an example

GCF (greatest common factor)

6

LCM (least common multiple)

36

The GCF of 12 and 18 is 6, and the LCM is 36.

GCF is also called GCD (greatest common divisor) or HCF (highest common factor).

Fix the highlighted field to update the result.

Prime factorizations

GCF and LCM from prime factors
NumberPrime factorization
1212 = 2² × 3
1818 = 2 × 3²
GCF2 × 3 = 6 (common primes, lowest powers)
LCM2² × 3² = 36 (every prime, highest powers)

Euclid’s algorithm, then the LCM

Divide and keep the remainder until it is 0; then LCM = a × b ÷ GCF
PairDivision step
gcd(12, 18)18 = 1 × 12 + 6
gcd(12, 18)12 = 2 × 6 + 0
gcd(12, 18)Remainder 0, so the GCF is the last divisor: 6
lcm(12, 18)12 × 18 ÷ 6 = 36

How to use

  1. Enter two to six whole numbers, one per box. Leave the extra boxes empty.
  2. Read the GCF and LCM at once.
  3. Below the result, see each number’s prime factorization and every step of Euclid’s algorithm.

The GCF is also called the GCD (greatest common divisor) or HCF (highest common factor).

How the GCF and LCM are calculated

Prime factor method: write each number as a product of primes.

  • GCF: multiply the primes that appear in every number, each at its lowest power.
  • LCM: multiply every prime that appears anywhere, each at its highest power.

Euclid’s algorithm: divide the larger number by the smaller and keep the remainder. Repeat with the divisor and the remainder until the remainder is 0. The last divisor is the GCF.

For two numbers, LCM = a × b ÷ GCF. For three or more, work in pairs.

Examples

  • 12 and 18: 12 = 2² × 3 and 18 = 2 × 3². The GCF is 2 × 3 = 6, and the LCM is 2² × 3² = 36.
  • Euclid for 48 and 18: 48 = 2 × 18 + 12, then 18 = 1 × 12 + 6, then 12 = 2 × 6 + 0. The GCF is 6.
  • 8, 12 and 20: gcd(8, 12) = 4, then gcd(4, 20) = 4. lcm(8, 12) = 24, then lcm(24, 20) = 120.
Numbers GCF LCM
12, 18 6 36
15, 20 5 60
15, 18 3 90
54, 36 18 108
8, 9, 21 1 504
8, 12, 20 4 120
Zero, negative numbers and coprime numbers

When the GCF is 1, the numbers are called relatively prime, or coprime, like 8, 9 and 21.

Every whole number divides 0, so gcd(a, 0) = a. By convention the LCM is 0 when any number is 0. Negative numbers use their absolute values, so the GCF and LCM are always positive.

To add fractions, the LCM of the denominators is the least common denominator. The fraction calculator uses it in its steps.

Frequently asked questions

What’s the difference between GCF and LCM?

The GCF is the biggest number that divides all your numbers; the LCM is the smallest number they all divide into. For 12 and 18, the GCF is 6 and the LCM is 36.

Are GCF, GCD and HCF the same?

Yes. Greatest common factor (common in US schools), highest common factor (UK and India) and greatest common divisor (maths and programming) all mean the largest whole number dividing every number.

How do I find the LCM from the GCF?

For two numbers, divide their product by the GCF: lcm(a, b) = |a × b| ÷ gcd(a, b). For 15 and 18, that is 270 ÷ 3 = 90.

How does Euclid’s algorithm work?

Divide the larger number by the smaller and keep the remainder. Repeat with the divisor and the remainder until the remainder is 0. The last non-zero remainder is the GCF.

What is the GCF if one number is 0?

It is the other number, made positive: every integer divides 0, so gcd(a, 0) = |a|. The GCF of 0 and 0 has no largest divisor, so enter at least one non-zero number.

How do I find the GCF or LCM of three or more numbers?

Work in pairs: find the answer for the first two numbers, then combine that result with the next number. For 8, 12 and 20 the GCF is 4 and the LCM is 120.

Embed this calculator

Add this calculator to your own website for free. Copy the code below and paste it into your page’s HTML. The attribution link is optional.