GCD Calculator

Calculate the Greatest Common Divisor (GCD) of two or more numbers using the Euclidean algorithm.

Enter Numbers

You can enter 2 or more numbers

Quick Examples:

GCD (Greatest Common Divisor), also known as GCF (Greatest Common Factor) or HCF (Highest Common Factor), is the largest positive integer that divides all given numbers without a remainder.

GCD of 24, 36

12

🎯GCD
12
🔢LCM
72
📊Numbers
2
Coprime
No

Prime Factorizations:

24 = 2^3 × 3
36 = 2^2 × 3^2

Euclidean Algorithm Steps:

24 = 0 × 36 + 24
36 = 1 × 24 + 12
24 = 2 × 12 + 0
GCD = 12 (last non-zero remainder)

Divisibility:

24 ÷ 12 = 2, 36 ÷ 12 = 3

The Euclidean Algorithm

The Euclidean algorithm is an efficient method for computing the GCD of two numbers. It works by repeatedly dividing the larger number by the smaller one and taking the remainder until the remainder is zero. The last non-zero remainder is the GCD.

GCD(a, b) = GCD(b, a mod b), where a mod b is the remainder when a is divided by b

Applications of GCD

Simplifying Fractions

Divide numerator and denominator by their GCD

Music Theory

Finding beat patterns and time signatures

Cryptography

RSA encryption uses GCD calculations

Gear Ratios

Calculating optimal gear combinations

What is the Greatest Common Divisor (GCD)?

The Greatest Common Divisor (GCD), also known as the Greatest Common Factor (GCF) or Highest Common Factor (HCF), is the largest positive integer that divides two or more numbers without leaving a remainder. Understanding GCD is fundamental to number theory and has practical applications in simplifying fractions, solving problems, and working with ratios.

Key Terminology:

  • GCD (Greatest Common Divisor) - Most common term in mathematics
  • GCF (Greatest Common Factor) - Common in elementary education
  • HCF (Highest Common Factor) - Common in British English

Basic Properties of GCD:

  • GCD(a, b) = GCD(b, a) - Commutative property
  • GCD(a, 0) = |a| for any integer a
  • GCD(a, 1) = 1 for any integer a
  • GCD(a, a) = |a| for any integer a
  • If GCD(a, b) = 1, then a and b are coprime (relatively prime)

Simple Examples:

  • GCD(12, 18) = 6 (6 is the largest number dividing both)
  • GCD(15, 25) = 5
  • GCD(17, 23) = 1 (both are prime, so they're coprime)
  • GCD(48, 36, 24) = 12

The Euclidean Algorithm

The Euclidean Algorithm is the most efficient method for finding the GCD, dating back over 2,300 years to the ancient Greek mathematician Euclid. It's based on the principle that the GCD of two numbers also divides their difference.

How It Works:

  1. Divide the larger number by the smaller number
  2. Take the remainder from step 1
  3. Replace the larger number with the smaller, and smaller with remainder
  4. Repeat until the remainder is 0
  5. The last non-zero remainder is the GCD

Euclidean Algorithm

GCD(a, b) = GCD(b, a mod b) Repeat until remainder = 0 The last non-zero remainder is the GCD Example: GCD(48, 18) 48 = 18 × 2 + 12 18 = 12 × 1 + 6 12 = 6 × 2 + 0 GCD = 6

Where:

  • a, b= The two numbers to find GCD of (a ≥ b)
  • mod= Modulo operation (remainder after division)
  • GCD= Greatest Common Divisor result

Methods for Finding GCD

There are several approaches to find the GCD, each with its own advantages:

Method Process Best For Example
Euclidean Algorithm Repeated division with remainders Large numbers, efficiency GCD(252, 105) → 21
Prime Factorization Find common prime factors Understanding, small numbers 36 = 2²×3², 48 = 2⁴×3 → GCD = 2²×3 = 12
Listing Divisors List all divisors, find largest common Small numbers, teaching 12: {1,2,3,4,6,12}, 18: {1,2,3,6,9,18} → GCD = 6
Subtraction Method Repeatedly subtract smaller from larger Manual calculation, understanding GCD(48,18): 48-18=30, 30-18=12, 18-12=6...

Prime Factorization Method:

  1. Find the prime factorization of each number
  2. Identify common prime factors
  3. Take the lowest power of each common prime
  4. Multiply these together to get the GCD

GCD and LCM Relationship

The GCD and LCM (Least Common Multiple) have a fundamental mathematical relationship:

GCD-LCM Relationship

GCD(a, b) × LCM(a, b) = a × b Therefore: LCM(a, b) = (a × b) / GCD(a, b) GCD(a, b) = (a × b) / LCM(a, b) Example: a = 12, b = 18 GCD(12, 18) = 6 LCM(12, 18) = (12 × 18) / 6 = 216 / 6 = 36 Verify: 6 × 36 = 216 = 12 × 18 ✓

Where:

  • GCD= Greatest Common Divisor
  • LCM= Least Common Multiple
  • a, b= The two numbers

How to Use This GCD Calculator

Our GCD calculator finds the greatest common divisor quickly and shows the steps:

  1. Enter Numbers: Input two or more integers (positive or negative)
  2. Click Calculate: The calculator finds the GCD
  3. View Results:
    • GCD value
    • Step-by-step Euclidean algorithm
    • Prime factorizations
    • Related LCM value

Features:

  • Calculate GCD of 2, 3, or more numbers
  • Works with negative numbers (returns positive GCD)
  • Shows detailed solution steps
  • Displays prime factorization
  • Automatically calculates related LCM

Tips:

  • For negative numbers, GCD uses absolute values
  • GCD(0, n) = n for any non-zero n
  • If result is 1, the numbers are coprime

Real-World Applications of GCD

The GCD has many practical applications:

Simplifying Fractions:

  • To reduce a fraction, divide both numerator and denominator by their GCD
  • Example: 24/36 → GCD(24,36) = 12 → 24÷12 / 36÷12 = 2/3
  • A fraction is fully reduced when GCD of numerator and denominator is 1

Solving Problems:

  • Tiling: Finding the largest square tile for a rectangular floor
  • Distribution: Dividing items equally into groups
  • Music: Finding rhythmic patterns and time signatures
  • Computer Science: RSA encryption, hash functions

Cryptography:

  • RSA encryption uses GCD to find coprime numbers
  • Extended Euclidean algorithm finds modular inverses
  • Essential for secure key generation

Engineering:

  • Gear ratio calculations
  • Signal processing
  • Computer graphics (pixel aspect ratios)

Finding GCD of Multiple Numbers

To find the GCD of more than two numbers, apply the GCD function iteratively:

Method:

  • GCD(a, b, c) = GCD(GCD(a, b), c)
  • GCD(a, b, c, d) = GCD(GCD(GCD(a, b), c), d)
  • Continue this pattern for any number of values

Example: GCD(24, 36, 48)

  1. First find GCD(24, 36) = 12
  2. Then find GCD(12, 48) = 12
  3. Therefore, GCD(24, 36, 48) = 12

Prime Factorization Method for Multiple Numbers:

  • 24 = 2³ × 3
  • 36 = 2² × 3²
  • 48 = 2⁴ × 3
  • GCD = 2² × 3 = 12 (lowest power of each common prime)

Worked Examples

Euclidean Algorithm Example

Problem:

Find GCD(252, 105) using the Euclidean Algorithm

Solution Steps:

  1. 1Start with a = 252, b = 105
  2. 2252 = 105 × 2 + 42 (remainder is 42)
  3. 3105 = 42 × 2 + 21 (remainder is 21)
  4. 442 = 21 × 2 + 0 (remainder is 0)
  5. 5The last non-zero remainder is 21
  6. 6Verify: 252 ÷ 21 = 12 ✓, 105 ÷ 21 = 5 ✓

Result:

GCD(252, 105) = 21

Prime Factorization Method

Problem:

Find GCD(180, 252) using prime factorization

Solution Steps:

  1. 1Factor 180: 180 = 2² × 3² × 5
  2. 2Factor 252: 252 = 2² × 3² × 7
  3. 3Identify common primes: 2 and 3
  4. 4Take lowest powers: 2² and 3²
  5. 5Multiply: 2² × 3² = 4 × 9 = 36
  6. 6Verify: 180 ÷ 36 = 5 ✓, 252 ÷ 36 = 7 ✓

Result:

GCD(180, 252) = 36

Simplifying a Fraction

Problem:

Simplify the fraction 84/126

Solution Steps:

  1. 1Find GCD(84, 126) using Euclidean algorithm
  2. 2126 = 84 × 1 + 42
  3. 384 = 42 × 2 + 0
  4. 4GCD(84, 126) = 42
  5. 5Divide both by GCD: 84÷42 / 126÷42
  6. 6Result: 2/3

Result:

84/126 = 2/3 (simplified)

Tips & Best Practices

  • Use the Euclidean Algorithm for large numbers - it's much faster than listing divisors
  • GCD helps simplify fractions: divide numerator and denominator by their GCD
  • For multiple numbers: GCD(a, b, c) = GCD(GCD(a, b), c)
  • If GCD = 1, the numbers are coprime (no common factors)
  • Remember: GCD(a, b) × LCM(a, b) = a × b - useful for finding LCM quickly
  • GCD of any number and 0 is the number itself: GCD(n, 0) = n
  • Prime numbers are coprime with all numbers they don't divide

Frequently Asked Questions

They are all the same thing with different names. GCD (Greatest Common Divisor) is the standard mathematical term. GCF (Greatest Common Factor) is commonly used in American schools. HCF (Highest Common Factor) is commonly used in British English and some other countries. All three refer to the largest positive integer that divides all the given numbers without a remainder.
The Euclidean Algorithm is efficient because the remainder decreases rapidly with each step. Mathematically, it can be proven that the number of steps is at most about 5 times the number of digits in the smaller number. This makes it logarithmic in complexity O(log n), far more efficient than listing all divisors for large numbers.
When GCD(a, b) = 1, the numbers a and b are called 'coprime' or 'relatively prime.' This means they share no common factors other than 1. Examples include consecutive integers (like 14 and 15), or any prime number with a number it doesn't divide. Coprime numbers are important in cryptography and number theory.
The GCD of negative numbers is defined using their absolute values. So GCD(-12, 18) = GCD(12, 18) = 6. By convention, the GCD is always a positive number (or zero if all inputs are zero). The sign doesn't affect divisibility, so we focus on magnitudes.
The Extended Euclidean Algorithm not only finds GCD(a, b) but also finds integers x and y such that ax + by = GCD(a, b). This is called Bézout's identity. It's crucial in cryptography for finding modular multiplicative inverses, which are essential for RSA encryption and decryption.
No, the GCD can never be larger than the smaller of the two numbers (assuming both are non-zero). By definition, the GCD must divide both numbers, and a divisor cannot exceed the number it divides. The GCD equals the smaller number only when the smaller number divides the larger one perfectly.

Sources & References

Last updated: 2026-01-22