GCD

Find the greatest common divisor of two or more integers with Excel's GCD function

Math & Trigonometry
|
Excel All versions
|
Google Sheets Supported

Spreadsheet editor

Syntax

=GCD(Number1, Number2, ...) Returns: Number

Arguments

Argument Required Description
Number1 Yes The first number or list of numbers for which you want to find the greatest common divisor.
Number2 Yes The second number, or subsequent numbers, for which you want to find the greatest common divisor.

About

GCD finds the largest number that divides evenly into all your numbers. Use it when you need to simplify fractions to their lowest terms or find common factors between values.

This function comes in handy when working with ratios, scaling measurements, or dividing quantities into equal parts. For example, if you're splitting resources evenly across teams or reducing recipe proportions while maintaining the same ratios, GCD helps you find the largest unit that works for all values. For finding the smallest common multiple instead, check out LCM.

GCD accepts up to 255 numbers and automatically truncates decimals to integers. If you need to check remainders after division, try MOD.

Examples

GCD with zero values

See how GCD handles zero in this edge case. When one value is zero, GCD returns the non-zero number. Try changing the zero to any number and watch the result update.

Spreadsheet editor

Decimal truncation pitfall

Watch how GCD truncates decimals to integers before calculating. GCD treats 5.9 and 3.9 as 5 and 3. Change 5.9 to 6.0 and see the result jump from 1 to 2.

Spreadsheet editor

Combining GCD with ABS for negative values

Use ABS to handle negative numbers in this budget tracker. GCD returns #NUM! errors for negative values, but wrapping them with ABS solves this. Try removing ABS to see the error.

Spreadsheet editor

Watch out for

Negative numbers return errors

GCD returns a #NUM! error if any number is negative, even though mathematically the greatest common divisor exists for negative integers.

Wrap negative values with the ABS function to convert them to positive numbers: =GCD(ABS(-24), ABS(-36)).

Decimal values get truncated

GCD automatically removes decimal portions without rounding. Using GCD(5.9, 3.9) treats the values as 5 and 3, which might not be what you expect.

If you need to preserve decimal precision, multiply your numbers by a power of 10 first, find the GCD, then divide the result by the same amount.

Large numbers cause errors

Numbers larger than 2^53 (about 9 quadrillion) return a #NUM! error because Excel can't process them accurately.

Keep your values below this limit. For most practical applications like measurements and counting, this limit is rarely an issue.

Tips & notes

GCD works only with positive integers. Negative values return errors, and decimals are automatically truncated (not rounded). You can provide up to 255 numbers to GCD. The function finds the largest integer that divides evenly into all of them. When GCD returns 1, it means the numbers have no common factors other than 1 (they are coprime or relatively prime).

Common questions

What happens when I use GCD with just one number?

GCD returns the number itself. Any number's greatest common divisor with itself is the number. For example, =GCD(15) returns 15.

Can I use GCD to find aspect ratios?

Yes. Find the GCD of your width and height, then divide both dimensions by the GCD. For example, 1920x1080 has a GCD of 120, giving you an aspect ratio of 16:9 (1920/120 = 16, 1080/120 = 9).

Why does GCD(5, 0) return 5 instead of an error?

Mathematically, any number divides evenly into zero. The GCD of any number with zero is that number itself. This behavior is technically correct, though it might seem surprising at first.

How is GCD different from LCM?

GCD finds the largest number that divides evenly into your values, while LCM finds the smallest number that all your values divide evenly into. They're inverse concepts, both useful for working with fractions and ratios.