Math and trigonometry functions

GCD

Matches all 7,972 recorded answers

Recorded: 7,966 in the answer bank and 6 workbook cells. How we measure this · See the Rust code

Local names in 40 languages
LanguageName in Excel
ArabicGCD
BulgarianGCD
CzechGCD
DanishSTØRSTE.FÆLLES.DIVISOR
GermanGCD
GreekGCD
English (Australia)GCD
English (United Kingdom)GCD
English (United States)GCD
SpanishM.C.D
EstonianGCD
FinnishSUURIN.YHT.TEKIJÄ
FrenchPGCD
HebrewGCD
CroatianGCD
HungarianLKO
IndonesianGCD
ItalianGCD
JapaneseGCD
KoreanGCD
LithuanianGCD
LatvianGCD
NorwegianGCD
DutchGGD
PolishNAJW.WSP.DZIEL
Portuguese (Brazil)GCD
Portuguese (Portugal)MDC
RomanianGCD
RussianНОД
SlovakGCD
SlovenianGCD
Serbian (Latin)GCD
SwedishSGD
ThaiGCD
TurkishOBEB işlevi
UkrainianGCD
VietnameseGCD
Chinese (Simplified)GCD
Chinese (Hong Kong)GCD
Chinese (Traditional)GCD

Names from Microsoft's support site.

What it does

GCD(number1, [number2], ...)

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

ArgumentMeaningRequired
number1The first value.Yes
number2, …Further values.No

Two properties of the truncation rule deserve emphasis.

  1. 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.
  2. 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

Input cells (optional)

Example: {"B2": 3, "B3": 4}. A1 holds the formula. Other cells need values before a formula can read them.

Enter a formula, then calculate.

Runs locally in your browser with OneCalc. Its answer may differ from Excel. Use English function names and commas between arguments.

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:

ErrorDocumented 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!.

FormulaExcelMathematical value
GCD(9007199254740992, 1)
Excel 16.0 build 20430, Windows 64-bit, CPU not recorded in this capture
Inputs 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 capture
Inputs 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 capture
Inputs and reference value

Number supplied through a cell.

number1: 9007199254740994
0x4340000000000001

number2: 0
0x0000000000000000

#NUM!—

Inputs, build details and evidence

How to implement

Numerical notes

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.

GCD · 4 lines · calc-func/src/catalogue/math.rs on GitHub
38 gcd "GCD" (1, 255) [R "number1", R "number2"] |s, a, sv| {
    let items = integer_groups(s, a, sv)?;
    s.number(k::gcd_fn::gcd_kernel(&items))
}
gcd_kernel · 3 lines · calc-func/src/ported/gcd_fn.rs on GitHub
pub fn gcd_kernel(items: &[i64]) -> f64 {
    items.iter().copied().fold(0, gcd_int) as f64
}

Kernels shared with other functions

Argument and result plumbing

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 buildPlatform and CPUCaptured inputs
20430Windows, 64-bit, CPU not recorded7,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.

Recorded environments and comparison details.

Excel 16.0 build 20430

Windows 64-bit, CPU not recorded in this capture

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.

Observed formulas and results
  • GCD(9007199254740992, 1) → 1
    0x3ff0000000000000 (cell-value2)
  • GCD(9007199254740994, 0) → #NUM! (cell-value2)

Excel 16.0 build 20430

Windows, 64-bit, CPU not recorded

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.

Named variants

No named variants are recorded yet.

Suggest a correction or contribute an implementation · For agents