Greatest Common Divisor & Least Common Multiple

Excel Formulas › Math

All versionsGCDLCM

GCD finds the largest number that divides into several values evenly; LCM finds the smallest number they all divide into. They’re the tools for simplifying ratios and lining up repeating cycles.


Quick formula: for the greatest common divisor and least common multiple of two numbers:
=GCD(A2, B2) // largest shared divisor =LCM(A2, B2) // smallest shared multiple
Both accept several numbers. GCD of 12 and 18 is 6; LCM is 36.

Functions used (tap for the full reference guide):

The example

GCD and LCM of pairs of numbers.

ABCD
1abGCDLCM
21218636
3812424

The formula

GCD and LCM:

=GCD(12, 18) → 6 =LCM(12, 18) → 36

How it works

Two complementary divisibility tools:

  1. GCD(a, b) returns the greatest common divisor — the biggest number that divides both evenly (6 for 12 and 18).
  2. LCM(a, b) returns the least common multiple — the smallest number both divide into (36).
  3. Both take more than two arguments: GCD(12, 18, 24) works.
  4. A key use: simplify a ratio by dividing both parts by their GCD — 12:18 becomes 2:3.

Simplify a ratio in one shot: =A2/GCD(A2,B2) & ":" & B2/GCD(A2,B2) turns 12 and 18 into the text 2:3 — handy for aspect ratios and recipe scaling.

Try it: interactive demo

Live demo

Enter two numbers.

GCD:   LCM:   Ratio:

Variations

Simplify a ratio

Divide both by the GCD:

=A2/GCD(A2,B2) & ":" & B2/GCD(A2,B2)

GCD of several numbers

Pass a range:

=GCD(A2:A10)

When do two cycles align?

LCM of the periods:

=LCM(A2, B2)

Pitfalls & errors

Whole numbers only. GCD and LCM truncate decimals to integers. Scale up first if you’re working with fractions.

#NUM! on negatives. Both expect non-negative values; negative inputs error. Use ABS if signs may vary.

LCM can get huge fast. The LCM of several large coprime numbers explodes — and may exceed Excel’s number precision.

Practice workbook

📊
Download the free Greatest Common Divisor & Least Common Multiple practice workbook
Number pairs with live GCD/LCM, the simplify-ratio and multi-number variants, plus 4 challenges with answers. No sign-up required.

Frequently asked questions

How do I find the greatest common divisor in Excel?
Use =GCD(a, b), e.g. =GCD(12, 18) returns 6. It accepts several numbers or a range and gives the largest value that divides them all evenly.
How do I simplify a ratio in Excel?
Divide both numbers by their GCD: =A2/GCD(A2,B2) & ":" & B2/GCD(A2,B2) turns 12 and 18 into 2:3.
What is LCM used for?
LCM (=LCM(a, b)) gives the smallest number both values divide into, useful for finding when repeating cycles align or for common denominators.

Stop fighting formulas. Learn them in a day.

This recipe is one of hundreds of real-world formulas we teach. Our Excel Formulas & Functions class covers lookups, logic, text, and dynamic arrays hands-on — live in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.

See the Formulas & Functions Class

Related formulas: Remainders & cycles (MOD) · Combinations & permutations · Roman numerals

Function references: GCD · LCM