GCD(number1, [number2], ...) returns the greatest common divisor of its arguments after each
has been truncated to an integer.
The mathematics is the oldest algorithm in the book. For integers a, b not both zero,
gcd(a, b) is the largest positive integer dividing both. The definition extends to any
number of arguments by associativity:
gcd(a, b, c) = gcd(gcd(a, b), c)
so the n-argument function is a left fold of the binary one, in any order — gcd is
commutative and associative, which is why Excel can accept up to 255 arguments without
declaring an evaluation order.
The structural facts worth carrying:
gcd(a, 0) = a, and gcd(0, 0) = 0. Zero is the identity element: every integer
divides zero, so zero contributes nothing to the meet. This is not a special case bolted on;
it is what makes gcd a well-defined operation on the whole of the non-negative integers.
gcd(a, 1) = 1. Microsoft's page states the same fact in its own words — "One divides any
value evenly" — and notes that "A prime number has only itself and one as even divisors."
gcd and lcm are dual. Under divisibility, the non-negative integers form a lattice in
which gcd is the meet and lcm the join. For exactly two arguments,
gcd(a, b) · lcm(a, b) = a · b. That identity does not extend to three or more
arguments, and readers who assume it does are the main source of wrong LCM formulas.
Bézout. gcd(a, b) is the smallest positive integer expressible as ax + by. Excel
exposes no function that returns the Bézout coefficients, so the extended algorithm is not
reachable from the worksheet.
Domain: non-negative integers after truncation. Range: non-negative integers.
Arguments
Argument
Meaning
Required
number1
The first value.
Yes
number2, …
Further values.
No
Two properties of the truncation rule deserve emphasis.
Truncation happens before the arithmetic, not after.GCD(2.5, 5) is the gcd of 2 and
5, not a rounding of some fractional gcd. Fractional arguments are silently reinterpreted;
there is no warning.
The documented rule says "truncated", not "rounded". For non-negative inputs — the only
ones GCD accepts — truncation toward zero and floor agree, so the two readings cannot be
distinguished on the admissible domain. The distinction that bites elsewhere in the math
category (see INT) is invisible here.
Argument slots are numeric and subject to ordinary to-number coercion; see
coercion and lifting. Range arguments are scanned rather
than lifted — GCD is declared with a custom coercion profile rather than the scalar-lift
profile used by single-argument math functions.
Try it
Quirks
Result and edge cases
Returns Number — a non-negative integer value.
Zero alone yields zero, consistent with the identity-element reading above.
A logical argument is accepted and converted; numeric text is accepted and then
truncated. Neither case is covered by Microsoft's page, which speaks only of "nonnumeric".
An inline array argument is consumed as a set of values and reduced to one result, not
lifted elementwise. This is the aggregate shape, not the scalar-kernel shape.
An empty range produces #VALUE! rather than the zero that the identity element would
suggest.
A subnormal magnitude truncates to zero and therefore contributes nothing.
Errors
As documented on Microsoft's GCD page:
Error
Documented condition
#VALUE!
"If any argument is nonnumeric, GCD returns the #VALUE! error value."
#NUM!
"If any argument is less than zero, GCD returns the #NUM! error value."
#NUM!
"If a parameter to GCD is >=2^53, GCD returns the #NUM! error value."
Error values in any argument propagate under the shared coercion discipline.
GCD and LCM accept 2^53 itself, not only values below it
GCD accepts an operand equal to 2^53, and LCM accepts an operand or a result equal to 2^53. Only values above 2^53 give #NUM!.
Formula
Excel
Mathematical value
GCD(9007199254740992, 1) Excel 16.0 build 20430, Windows 64-bit, CPU not recorded in this captureInputs and reference value
Number supplied through a cell.
number1: 9007199254740992 0x4340000000000000
number2: 1 0x3ff0000000000000
1 0x3ff0000000000000
—
LCM(9007199254740992, 2) Excel 16.0 build 20430, Windows 64-bit, CPU not recorded in this captureInputs and reference value
Number supplied through a cell.
number1: 9007199254740992 0x4340000000000000
number2: 2 0x4000000000000000
9007199254740992 0x4340000000000000
—
GCD(9007199254740994, 0) Excel 16.0 build 20430, Windows 64-bit, CPU not recorded in this captureInputs and reference value
GCD is one of the few functions in the math category with no floating-point error at all
in its intended domain — every intermediate value is an exact integer — and yet it has a
genuine numerical hazard, which is the representation boundary rather than rounding.
The 2^53 wall. Arguments arrive as binary64. Below 2^53 every integer is exactly
representable and truncation recovers exactly the integer the user typed. At or above 2^53 the
doubles are spaced two or more apart, so the value that arrives is not necessarily the integer
that was written, and a gcd computed from it is the gcd of a rounded neighbour. Microsoft's
documented #NUM! at 2^53 is precisely a refusal to answer a question that can no longer be
asked. An implementation that instead converts to a 64-bit integer inherits a different
boundary at 2^63, and above that the conversion saturates or wraps — which is how a function
with no rounding error still produces a wrong answer.
Algorithm choice. Euclid's algorithm with remainder (Knuth, TAOCP volume 2, section 4.5.2)
runs in O(log min(a, b)) divisions; the binary GCD of Stein replaces division with shifts
and subtraction and is usually faster on hardware without a fast integer divide. Both are exact,
so the choice is performance-only — unusually for this category, there is no accuracy trade-off
to weigh. The variadic fold benefits from an early exit: once the running gcd reaches 1 no later
argument can change it, and the remaining arguments need only be validated, not divided.
What a careful implementation does about the boundary, in order of decreasing preference:
guard the documented domain explicitly and return #NUM!; or, if a wider domain is wanted,
carry the reduction in a type wide enough to hold every finite double's integer part and state
the widened domain as a deliberate, documented departure. What it must not do is convert to a
fixed-width integer and let the conversion decide.
Rust code
Show the CalcFunc source of this function
Quoted from the public repository DnaCalc/DnaCalc, crates calc-func and calc-fml, at commit 9e1884369a67. Comments are the source's own. A kernel shared with other functions appears once, on its module page.
No implementation has been published with a Handbook test suite for this function.
Version differences
The recorded environments below distinguish a reading from a same-input comparison. Counts describe captured inputs in each environment; overlapping captures and comparisons are not totals of unique worksheet calls.
Excel 16.0 build
Platform and CPU
Captured inputs
20430
Windows, 64-bit, CPU not recorded
7,966
The record contains no same-input comparison between these environments. Reading different inputs on different builds does not establish either a version change or cross-build agreement.
GCD(9007199254740992, 1) returned 1 (0x3ff0000000000000). GCD(9007199254740994, 0) returned #NUM!. Inputs were supplied through cells using Value2. These are controls from this environment, not a same-input comparison with another build.
7,966 captured inputs are indexed for this environment. Capture dates: 2026-09-29 to 2026-09-29. This is a reading count, not a comparison with another build.
Alternatives
Relationships
MOD — the primitive the Euclidean algorithm is built from. GCD is what
repeated MOD converges to.
QUOTIENT and INT — the other truncating integer
operations; each truncates by a different rule, and only INT floors.
MULTINOMIAL — the other variadic integer-combinatorial function in
this category, and one that shares GCD's group structural evidence record.
Readers reach for GCD most often to reduce a fraction: n/GCD(n,d) over d/GCD(n,d). That
usage never approaches the documented 2^53 ceiling, which is why the ceiling is so rarely
noticed.