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 =GCD(A2,B2) returns 6
Returns the greatest common divisor: the largest whole number that divides all the numbers you give it exactly.
Syntax
=GCD(, [number2], …)
All versions of Excel.
Try it
Edit the formula in C2 or change the inputs. The sheet recalculates as you type.
C2 =GCD(A2,B2) returns 6
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.
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.
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.
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.
=GCD(7.9, 14) uses 7 and returns 7.=GCD(0, 5) is 5, and =GCD(0, 0) is 0.#NUM!. Use ABS to strip the sign first.#VALUE!.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.
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.
B2:B4. Negative numbers return #NUM!.Each example is a live sheet. Change the inputs or the formula and watch the result.
Example 1
C2 =GCD(A2,B2)
Result: 6
6 is the largest number that divides both 12 and 18 exactly.
C2 =GCD(A2,B2) returns 6
Example 2
C2 =GCD(A2:A4)
Result: 12
The three batches can each be split into groups of 12 with nothing left over.
C2 =GCD(A2:A4) returns 12
Example 3
C2 =A2/GCD(A2,B2)&":"&B2/GCD(A2,B2)
Result: 3:2
The GCD is 120, so 360 : 240 reduces to 3 : 2.
C2 =A2/GCD(A2,B2)&":"&B2/GCD(A2,B2) returns 3:2
Example 4
C2 =GCD(A2,B2)
Result: 5
Every number divides 0, so the GCD of 0 and 5 is 5.
C2 =GCD(A2,B2) returns 5
Example 5
C2 =GCD(A2,B2)
Result: #NUM!
Wrap each argument in ABS if negatives can occur: GCD(ABS(A2), ABS(B2)).
C2 =GCD(A2,B2) returns #NUM!
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.
#NUM!. Take ABS of each argument if signs can vary.GCD(7.9, 14) works on 7. Check that your inputs are whole numbers.#VALUE!. Keep units out of the number cell.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.
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.
Yes, up to 255. `=GCD(24, 36, 60)` is 12, and `=GCD(A2:A9)` works on a range.
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.
One of the numbers is negative. Use ABS to remove the sign first.
Tracks take you from the basics to modelling, one graded exercise at a time.