Category: FUNCTION | Updated: 2026-11-22

How to Use the GCD Function | Find the Greatest Common Divisor

How to Use the GCD Function

The GCD (Greatest Common Divisor) function returns the greatest common divisor of two or more integers. It is useful for simplifying fractions or finding common allocation units.

Syntax

=GCD(value1, [value2, ...])
  • value1: The first number or cell range for which to find the greatest common divisor (required).
  • value2, …: Additional numbers or cell ranges (optional, up to 30 arguments).

Example Table

Here are the calculation results when numbers are entered in Columns A and B.

Col A (Value 1) Col B (Value 2) Formula Result Explanation
12 18 =GCD(A2, B2) 6 Greatest common divisor of 12 and 18 is 6
24 36 =GCD(A3:B3) 12 Ranges can also be specified
7 13 =GCD(A4, B4) 1 Coprime numbers (only common divisor is 1)
15.8 20.2 =GCD(A5, B5) 5 Decimals are truncated to 15 and 20

Common Errors and Caveats

  • #NUM! error: Occurs if any argument is negative or if a value is too large.
  • #VALUE! error: Occurs if a non-numeric text string is passed as an argument.
  • When 0 is included: If the arguments include 0 and a positive integer, that positive integer is returned (e.g., =GCD(0, 5) returns 5). If all arguments are 0, it returns 0.

Frequently Asked Questions

Q. What happens if you pass decimals to the GCD function?

A. The decimal portion is truncated, and the greatest common divisor is calculated using only the integer part.

Q. How does GCD behave if you pass a negative number?

A. Passing a negative number returns a #NUM! error. Be sure to specify numbers greater than or equal to 0.