Finding the greatest common divisor with the GCD function in Google Sheets

Lesson on How to find the greatest common divisor in Google Sheets by using the GCD function top image by SpreadsheetClass.com

Have you ever needed to find the highest number that would divide into two (or more) given numbers in your spreadsheet? Google Sheets has a formula that will allow you to do exactly that, very easily. In this lesson I will show you how to use the greatest common divisor function (GCD), to find the greatest number that will divide into the given numbers.

"Greatest common divisor" is also referred to as "highest common factor", and "greatest common factor".

The Greatest Common Divisor, is the largest positive integer that divides two or more numbers without leaving a remainder. For example, consider the numbers 12 and 18.

The divisors of 12 are the following:
1, 2, 3, 4, 6, 12…

The divisors of 18 are the following:
1, 2, 3, 6, 9, 18…

The greatest number that appears in both lists is 6, which means that the Greatest Common Divisor of 12 and 18 is equal to 6.

To find the greatest common divisor (GCD) in Google Sheets, follow these steps:

  1. Type =GCD( to begin the formula
  2. Type the first number, or the address of the cell that contains the first number
  3. Type a comma, and then type the second number or the cell that contains the second number
  4. If more than two numbers are being used, then repeat the previous step as many times as needed
  5. Press "Enter" on the keyboard. The final formula will look like this: =GCD(18,12). The formula will look like this when using cell references: =GCD(A1,A2)

After following these steps, the formula will display the highest number that and divide into both / all of the given numbers.

Finding the greatest common divisor of numbers

Let's start with a basic example of using the GCD function, where we will enter the numbers that we want to find the greatest common divisor of, directly into the formula.

In this example, we want to find the greatest common divisor of the numbers 18 and 12, which means that we want to find the greatest number that will divide evenly into both 18 and 12.

We will type these numbers directly into the criteria for the GCD function, by typing the first number, then typing a comma, and then typing the second number, as shown in the formula below.

=GCD(18,12)

Example of Finding the greatest common divisor in Google Sheets by using the GCD function

As you can see in the image above, cell A1 displays the number "6", which is the greatest common divisor of the numbers 12 and 18. In other words, the number "6" is the greatest number that will evenly divide into both 12 and 18.

Finding the greatest common divisor by using cell references

If you want, you can use cell references to specify the numbers in the GCD function. This makes it easy to change the values that the formula is calculating, where you can simply change the numbers in the cells rather than having to change the numbers in the formula itself.

In this example, we want to find the greatest common divisor of the numbers 18 and 12, but in this case we are entering the numbers into cells instead of directly into the formula. The number 18 is entered into cell B1, and the number 12 is entered into cell B2. The formula in cell B3 finds the greatest common divisor of the numbers in cells B1 and B2.

To use cell references when using the GCD function, simply type the address of the cell that contains the first number, type a comma, and then type the address of the cell that contains the second number, as shown in the formula below.

=GCD(B1,B2)

Example of New Finding the greatest common divisor in Google Sheets by using cell references with the GCD function

As you can see in the image above, cell B3 displays the number "6", which is the greatest common divisor of the numbers that are entered into cells B1 (18) and B2 (12).

Finding the greatest common divisor of more than two numbers

If you want, you can use the GCD function to find the greatest common divisor of more than two numbers.

In this example, we will find the greatest common divisor of three numbers (18, 12, and 9). This means that we will find the greatest number that can divide into all three of these numbers.

To do this we will follow the same steps as in the previous example, except we will enter more criteria / another number by typing another comma, and entering the third number, as shown in the formula below.

=GCD(18,12,9)

Example of Finding the greatest common divisor of more than two numbers in Google Sheets by using the GCD function

As you can see in the image above, cell A1 displays the number "3", which is the greatest common divisor of the numbers 18, 12, and 9. In other words, the number "3" is the greatest number that will divide into all three numbers.