GCD returns the largest whole number that divides all the numbers you give it without leaving a remainder. Use it to simplify fractions, split items into equal groups, or find repeating intervals.
=GCD(number1, [number2], …)What does GCD do?
The GCD function in Excel calculates the greatest common divisor of two or more numbers. In plain terms, it finds the biggest number that can divide every number in your list exactly, with nothing left over. For example, the GCD of 12 and 18 is 6, because 6 is the largest number that divides both 12 and 18 evenly.
This matters because many everyday office tasks involve ratios, grouping, or scheduling. Simplifying a ratio like 24:36 to 2:3 is quick when you divide both sides by their GCD. Splitting 48 pens and 36 notebooks into identical gift packs needs the GCD to find the largest possible number of packs. And if two machines run on 8-minute and 12-minute cycles, their next simultaneous start is after 24 minutes, which is the least common multiple built from the GCD.
GCD is part of Excel's Math & trigonometry category and works in every modern version of Excel, including Excel 365, 2019, 2016, and Excel for Mac. It accepts up to 255 arguments, which can be numbers, cell references, or ranges. The function is simple to use, but a few quirks around decimals and text are worth knowing before you rely on it.
When to use GCD
- Simplifying fractions or ratios to their lowest terms
- Splitting stock into the largest number of identical packs
- Finding the largest tile size that fits a rectangular area exactly
- Working out when two repeating schedules line up
- Reducing recipe or mixture proportions
- Checking whether two quantities share a common factor
GCD syntax
=GCD(number1, [number2], …)| Argument | Required? | What to enter |
|---|---|---|
number1 | Required | The first number or range of numbers. Must be zero or a positive whole number. Example: 12 or A2:A5. |
number2 | Optional | Additional numbers or ranges, up to 255 in total. Each must be zero or a positive whole number. Example: 18 or B2. |
What it returns: A whole number: the largest positive integer that divides every supplied number without a remainder. If any number is 0, GCD returns the other number; if all numbers are 0, it returns 0.
GCD examples
1 Example 1: GCD of two simple numbers
This example finds the greatest common divisor of 12 and 18. The formula =GCD(B2,C2) looks at the two values in row 2 and returns the largest number that divides both. Because 6 divides 12 and 18 exactly, the result is 6. This is the simplest way to see GCD in action.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Item | Number 1 | Number 2 | |||
| 2 | Pair | 12 | 18 | 6 | ||
| 3 |
2 Example 2: GCD across a range of numbers
Here we have four numbers in a range and want their shared divisor. The formula =GCD(B2:B5) passes the whole range to GCD, which checks all four values. The largest number that divides 24, 36, 48, and 60 is 12. Using a range keeps the formula short even when the list grows.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Label | Value | |||
| 2 | N1 | 24 | 12 | ||
| 3 | N2 | 36 | |||
| 4 | N3 | 48 | |||
| 5 | N4 | 60 | |||
| 6 |
3 Example 3: Simplifying a ratio
A common office task is reducing a ratio such as 45:60 to its simplest form. First, =GCD(B2,C2) finds the divisor, which is 15. Then dividing both parts by 15 gives 3:4. The GCD formula in the target cell returns 15, the number you would use to simplify the ratio.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Ratio Part | Value | ||||
| 2 | Left | 45 | 15 | |||
| 3 | Right | 60 | ||||
| 4 |
4 Example 4: Splitting stock into identical packs
You have 84 pencils, 56 erasers, and 42 rulers to pack into identical gift bags with no leftovers. The formula =GCD(B2:B4) finds the largest number of bags possible. Since 14 divides all three quantities, you can make 14 identical bags. Each bag gets 6 pencils, 4 erasers, and 3 rulers.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Item | Quantity | |||
| 2 | Pencils | 84 | 14 | ||
| 3 | Erasers | 56 | |||
| 4 | Rulers | 42 | |||
| 5 |
5 Example 5: Finding when two schedules align
Two machines start together, then repeat every 18 and 24 minutes. To find the next time they start together, you need the least common multiple, which is 18 × 24 ÷ GCD(18,24). The formula =GCD(B2,C2) returns 6, so the LCM is 432 ÷ 6 = 72 minutes. That tells you the machines align every 72 minutes.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Machine | Cycle (min) | ||||
| 2 | Machine A | 18 | 6 | |||
| 3 | Machine B | 24 | ||||
| 4 |
Common GCD errors and how to fix them
| Error | Why it happens | How to fix it |
|---|---|---|
| #NUM! | One or more arguments are negative numbers, or the result would be too large for Excel to display. | Make sure every number is zero or positive. If you need to work with negatives, take the absolute value first with ABS. |
| #VALUE! | An argument is text that cannot be read as a number, or a range contains text. | Check that cells contain numbers only. Remove stray spaces or labels, or wrap the range in a function that ignores text, such as GCD(IF(ISNUMBER(B2:B5),B2:B5)) entered as an array formula in older Excel versions. |
| #NAME? | The function name is misspelled, or you are using a very old Excel version that lacks GCD. | Type =GCD( and let Excel suggest the name. GCD is available in Excel 2007 and later; for older versions, use the Analysis ToolPak add-in. |
| Wrong result with decimals | GCD truncates decimal numbers to integers before calculating, so 12.9 is treated as 12. | Round or truncate your numbers deliberately first, for example with INT or ROUND, so the result matches your intention. |
Tips for using GCD
- Use a range like
B2:B10instead of listing each cell to keep formulas short and easy to update. - Remember that GCD ignores the decimal part of numbers; if decimals matter, convert to whole units first (for example, pence instead of pounds).
- To simplify a ratio, divide each part by
GCD(part1, part2)and display the results as text with a colon. - The least common multiple can be calculated as
a*b/GCD(a,b), which is useful for scheduling and repeating events. - If a range contains text, GCD returns
#VALUE!; clean the data or use a helper column withISNUMBERto filter. - GCD of a single number returns that number, and GCD with 0 returns the other number, which can be handy as a fallback.
Frequently asked questions
What is the difference between GCD and LCM?
GCD finds the largest number that divides a set of numbers, while LCM finds the smallest number that all the numbers divide into. They are related: for two numbers a and b, LCM = a × b ÷ GCD.
Can GCD handle more than two numbers?
Yes. GCD accepts up to 255 arguments, and each argument can be a number, a cell reference, or a range. For example, =GCD(A1:A10) works with ten numbers at once.
Why does GCD return a wrong answer for decimals?
GCD truncates decimal values to whole numbers before calculating. If you enter 12.9 and 18.9, it treats them as 12 and 18 and returns 6. Convert to whole units first if you need precision.
Does GCD work with negative numbers?
No. Negative arguments cause a #NUM! error. Use ABS to convert negatives to positives before passing them to GCD.
Related functions
Every example on this page was recalculated by SheetSkill’s spreadsheet engine. GCD reference