Davided.

GCD & LCM Calculator

Find the GCD (greatest common divisor, also called GCF or HCF) and LCM (least common multiple) of two or more numbers, with the Euclidean algorithm steps shown.

✓ Last reviewed: Sources: Wikipedia — Greatest common divisor

Report a correction

Spotted a wrong result, label or typo? Tell us — we review every report.

Values recognized: 0

Enter two or more whole numbers, separated by spaces, commas, semicolons, or new lines — e.g. 12, 18, 30. Negative numbers are allowed and are treated as their absolute value.

Your result

Fill in the fields above to see your result.

Related calculators

GCD and LCM calculator — what it works out

Enter two or more whole numbers and this GCD and LCM calculator returns both values at once: the GCD (greatest common divisor) and the LCM (least common multiple). It also shows the Euclidean algorithm steps, so you see not just the answer but where it comes from.

GCD goes by other names depending on where you learned math: GCF (greatest common factor) is the standard term in US classrooms, and HCF (highest common factor) is the standard term in the UK, India, and much of the Commonwealth. All three — GCD, GCF, HCF — mean exactly the same thing, and this calculator covers all of them. GCD (or GCF/HCF) is what you use to simplify fractions; LCM is what you use to find a common denominator. The calculator handles negative numbers and zero, accepts any number of inputs (not just two), and updates the result as soon as you type.

How to use the calculator

  1. Enter your numbers. Type at least two whole numbers, separated by a space or comma — e.g. 12, 18. The calculator also accepts three or more numbers at once.
  2. Read the GCD and LCM. Both results appear side by side immediately — there’s no need to pick which calculation to run.
  3. Expand the working. The Euclidean algorithm steps show each division-with-remainder down to the final answer.
  4. Negative numbers and zero both work. The sign of a number doesn’t change its GCD or LCM (the calculator works with absolute values) — no extra setting needed.

How GCD and LCM are calculated

The GCD (also called GCF or HCF) of two whole numbers is the largest number that divides both of them with no remainder. The LCM is the smallest number that both of them divide into evenly. The calculator finds the GCD with the Euclidean algorithm — one of the oldest known algorithms in mathematics, dating back to Euclid’s “Elements” around 300 BCE — then derives the LCM from it:

LCM(a, b) = |a × b| ÷ GCD(a, b)

The Euclidean algorithm works by repeated division: divide the larger number by the smaller one, keep the remainder, then repeat with the smaller number and that remainder — until the remainder hits 0. The last non-zero remainder is the GCD.

Step-by-step example: GCD and LCM of 12 and 18

  1. 18 divided by 12 leaves a remainder of 6 (since 18 = 1×12 + 6).
  2. 12 divided by 6 leaves a remainder of 0 (since 12 = 2×6 + 0).
  3. The last non-zero remainder is 6, so GCD(12, 18) = 6.
  4. The LCM follows from the formula: LCM = (12 × 18) ÷ 6 = 216 ÷ 6 = 36.

Prime factorization confirms the same result: 12 = 2²×3, 18 = 2×3². The GCD takes the lowest power of each shared factor: 2¹×3¹ = 6. The LCM takes the highest power of each factor appearing in either number: 2²×3² = 36. Both methods agree — the Euclidean algorithm is just faster, especially for large numbers, where factoring gets expensive.

GCD and LCM of three or more numbers

With more than two numbers, the calculator reduces them pairwise: it finds the GCD (or LCM) of the first two, combines that with the next number, and so on — the order doesn’t affect the final answer.

For 12, 18, and 30:

  1. GCD(12, 18) = 6 (see the example above).
  2. GCD(6, 30) = 6 (since 30 = 5×6 + 0).
  3. GCD(12, 18, 30) = 6.
  4. LCM(12, 18) = 36 (see the example above).
  5. LCM(36, 30): GCD(36, 30) = 6, so LCM = (36 ÷ 6) × 30 = 6 × 30 = 180.
  6. LCM(12, 18, 30) = 180.

Coprime numbers: when GCD equals 1

For 8 and 9: 9 = 1×8 + 1, then 8 = 8×1 + 0 → GCD(8, 9) = 1. Numbers like this are called coprime (or relatively prime) — they share no common divisor other than 1. When that happens, the LCM always equals the product of the numbers, since the divisor in the formula is 1: LCM = 8 × 9 = 72.

What GCD and LCM are used for: fractions

GCD simplifies fractions. To reduce a fraction to its lowest terms, divide the numerator and denominator by their GCD. For the fraction 12/18: GCD(12, 18) = 6, so 12÷6 = 2 and 18÷6 = 3 — the fraction 12/18 simplifies to 2/3, and it can’t be reduced any further.

LCM gives you a common denominator. To add or subtract fractions with different denominators, you convert them to a common denominator equal to the LCM of those denominators. For fractions with denominators 12 and 18, the common denominator is LCM(12, 18) = 36 — the smallest one possible, which keeps the numbers in the calculation as small as they can be. For three fractions with denominators 12, 18, and 30, the common denominator is the LCM of all three, which is 180.

Zero and negative numbers

The sign of a number doesn’t change its GCD or LCM — the calculator works with absolute values. GCD(−12, 18) gives exactly the same result as GCD(12, 18), which is 6, and the LCM is 36.

Zero is a special case. Zero is divisible by every number, so GCD(0, n) is always the absolute value of the other number: GCD(0, 5) = 5. But the only common multiple of zero and any number is zero itself, so LCM(0, 5) = 0. When both numbers are zero, the accepted convention is GCD(0, 0) = 0 — the calculator shows a short note explaining this isn’t an error.

Frequently asked questions

What’s the difference between GCD and LCM?

The GCD (greatest common divisor, also called GCF or HCF) is the largest number that divides both numbers with no remainder; the LCM (least common multiple) is the smallest number that both numbers divide into evenly. For 12 and 18: GCD = 6, LCM = 36 — two different answers to two different questions about the same pair of numbers.

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

Yes to both — GCD, GCF, and HCF are three names for the exact same calculation. GCF (greatest common factor) is the term commonly used in the US; HCF (highest common factor) is the term commonly used in the UK, India, and other Commonwealth countries; GCD is the international and computing-standard term. Whichever term your textbook uses, the number and the method behind it are identical.

What is GCD (also called GCF or HCF) used for?

GCD is used most often to simplify fractions to their lowest terms — you divide the numerator and denominator by their GCD. It’s also used to split a set of items into the largest possible equal groups, or to find the biggest shared “unit” between two quantities, such as cutting material into equal-length pieces with no leftover.

What is LCM (least common multiple) used for?

LCM is used most often to bring fractions with different denominators to a common denominator before adding or subtracting them. It’s also useful for scheduling problems — figuring out after how many days two events that repeat on different cycles will next coincide — and in computing, for synchronizing events with different periods.

How do you find the GCD of two numbers step by step (Euclidean algorithm)?

Divide the larger number by the smaller one and keep the remainder, then repeat the division using the smaller number and that remainder — until the remainder reaches 0. The last non-zero remainder is the GCD. For 12 and 18: 18 = 1×12+6, then 12 = 2×6+0 → GCD = 6. This method is called the Euclidean algorithm, one of the oldest known procedures in mathematics.

How do you find the LCM of three or more numbers?

You calculate the LCM pairwise: first the LCM of the first two numbers, then the LCM of that result with the third number, and so on — the order doesn’t change the final answer. For 12, 18, and 30: LCM(12,18) = 36, then LCM(36, 30) = 180, so the LCM of all three numbers is 180.

How does GCD help simplify fractions?

To simplify a fraction, divide the numerator and denominator by their GCD — the resulting fraction is equivalent to the original but in its lowest terms. For the fraction 12/18: GCD(12, 18) = 6, so 12÷6 / 18÷6 = 2/3, which is already fully reduced, since the GCD of the new numerator and denominator is 1.

How does LCM help add fractions with different denominators?

The common denominator for several fractions is the LCM of their denominators — the smallest number all of them convert into evenly. For denominators 12 and 18, the common denominator is LCM(12, 18) = 36, which lets you add or subtract those fractions by converting each one to a denominator of 36.

Can the GCD be greater than the LCM?

No — the GCD is never greater than the LCM for the same pair of numbers. The GCD is always less than or equal to each input number, and the LCM is always greater than or equal to each of them, so by definition GCD ≤ the numbers ≤ LCM. The only case where GCD and LCM are equal is when both numbers are identical (e.g. GCD(7,7) = LCM(7,7) = 7).

Is there a formula linking GCD and LCM?

Yes — for two numbers a and b: GCD(a, b) × LCM(a, b) = |a × b|. For 12 and 18: GCD = 6, LCM = 36, and 6 × 36 = 216 — exactly the product of 12 × 18. This formula lets you calculate the LCM straight away once you already know the GCD, without working it out from scratch.

Sources