Skip to content

GCD

Returns the greatest common divisor: the largest whole number that divides all the numbers you give it exactly.

Syntax

=GCD(, [number2], …)

Math and trigonometry

All versions of Excel.

Try it

Edit the formula in C2 or change the inputs. The sheet recalculates as you type.

C2
A
B
C
1
First
Second
GCD
2
12
18
6
3

C2 =GCD(A2,B2) returns 6

How GCD works

GCD finds the biggest whole number that goes into all of the numbers you supply with nothing left over. =GCD(12, 18) is 6, because 6 divides both and nothing larger does.

Simplifying ratios and fractions

The most practical use is reducing a ratio to its simplest form. For a room measuring 360 by 240, the GCD is 120, so the ratio is 3 : 2. Divide each side by the GCD:

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

This returns the text "3:2". The same approach reduces fractions: divide the numerator and the denominator by their GCD.

Largest square tile or equal split

The GCD of two lengths is the side of the largest square that tiles a rectangle exactly. A 360 cm by 240 cm floor takes 120 cm tiles, three across and two deep. It is also the largest group size into which several unequal batches can be split with none left over.

Several numbers at once

GCD accepts a list or a range: =GCD(24, 36, 60) and =GCD(B2:B4) both return 12. Putting a range in is the easiest way to include many values.

How GCD handles unusual input

  • Decimals are truncated: =GCD(7.9, 14) uses 7 and returns 7.
  • Zero is allowed: =GCD(0, 5) is 5, and =GCD(0, 0) is 0.
  • Negative numbers return #NUM!. Use ABS to strip the sign first.
  • Text returns #VALUE!.

GCD and LCM

LCM is the companion function. For two numbers, GCD times LCM equals the product of the two numbers: =GCD(12, 18) * LCM(12, 18) is 216, which is 12 times 18. That is a handy cross-check, and it means =A2*B2/GCD(A2, B2) is another way to write LCM.

Compared with other approaches

There is no other single Excel function for common divisors. Without GCD, you would test every candidate with MOD. MOD is the building block: the GCD is the largest number for which MOD of every input is 0.

Arguments

number1
The first number or range, such as B2:B4. Negative numbers return #NUM!.
number2, …optional
More numbers or ranges, up to 255 arguments. Decimals are cut off to whole numbers.

Examples

Each example is a live sheet. Change the inputs or the formula and watch the result.

Example 1

GCD of two numbers

C2 =GCD(A2,B2)

Result: 6

6 is the largest number that divides both 12 and 18 exactly.

C2
A
B
C
1
First
Second
GCD
2
12
18
6
3

C2 =GCD(A2,B2) returns 6

Example 2

GCD of a range

C2 =GCD(A2:A4)

Result: 12

The three batches can each be split into groups of 12 with nothing left over.

C2
A
B
C
1
Batch size
GCD
2
24
12
3
36
4
60
5

C2 =GCD(A2:A4) returns 12

Example 3

Simplify a ratio

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

Result: 3:2

The GCD is 120, so 360 : 240 reduces to 3 : 2.

C2
A
B
C
D
1
Length (cm)
Width (cm)
Ratio
2
360
240
3:2
3

C2 =A2/GCD(A2,B2)&":"&B2/GCD(A2,B2) returns 3:2

Example 4

Zero is allowed

C2 =GCD(A2,B2)

Result: 5

Every number divides 0, so the GCD of 0 and 5 is 5.

C2
A
B
C
1
First
Second
GCD
2
0
5
5
3

C2 =GCD(A2,B2) returns 5

Example 5

Negative numbers give #NUM!

C2 =GCD(A2,B2)

Result: #NUM!

Wrap each argument in ABS if negatives can occur: GCD(ABS(A2), ABS(B2)).

C2
A
B
C
1
First
Second
GCD
2
-4
6
#NUM!
3

C2 =GCD(A2,B2) returns #NUM!

Your turn.

Solve it in the sheet. Every answer is checked, with hints if you need them.

Task 1 of 2

In D2, return the side of the largest square tile that fits the length in B2 and the width in C2 exactly. Fill it down to D6.

Answer in D2, then it fills down to D6.

D2
A
B
C
D
E
F
1
Room
Length (cm)
Width (cm)
Tile size
Ratio
2
Hall
360
240
3
Office
450
375
4
Store
270
180
5
Lab
500
400
6
Annexe
210
150
7

Common mistakes

  • Negative numbers return #NUM!. Take ABS of each argument if signs can vary.
  • Decimals are truncated, not rounded, so GCD(7.9, 14) works on 7. Check that your inputs are whole numbers.
  • The GCD of numbers with nothing in common is 1, which can look like a failed result. It means they are co-prime.
  • In the ratio formula, call GCD twice or put it in a helper cell. Dividing only one side gives a mismatched ratio.
  • Text such as "12 cm" returns #VALUE!. Keep units out of the number cell.

Questions people ask

What does GCD do in Excel?

It returns the greatest common divisor of the numbers you give it: the largest whole number that divides each of them exactly. GCD(12, 18) is 6.

How do I simplify a ratio or fraction in Excel?

Divide each part by the GCD. For a ratio of 360 to 240, `=A2/GCD(A2,B2)` is 3 and `=B2/GCD(A2,B2)` is 2. Join them with `&":"&` to show 3:2.

Can GCD take more than two numbers?

Yes, up to 255. `=GCD(24, 36, 60)` is 12, and `=GCD(A2:A9)` works on a range.

What is the relationship between GCD and LCM?

For two numbers, GCD times LCM equals their product. GCD(12, 18) is 6 and LCM(12, 18) is 36, and 6 x 36 is 216, which is 12 x 18.

Why does GCD return #NUM!?

One of the numbers is negative. Use ABS to remove the sign first.

Learn GCD in a real sheet.

Tracks take you from the basics to modelling, one graded exercise at a time.