GCD Calculator

Calculate the Greatest Common Divisor (GCD) of two or more numbers using the Euclidean algorithm. Also known as GCF or HCF.

Positive integer
Positive integer
GCD
6
Greatest Common Divisor of 48 and 18
LCM
144
Least Common Multiple = |a*b| / GCD
Coprime?
No
Share factor(s) including 6
Bezout Coefficients
x=-1, y=3
48(-1) + 18(3) = 6
Common Divisors
4
1, 2, 3, 6
Product a * b
864
GCD * LCM = 864 (should equal a*b)
GCD as Proportion of Each Number
A = 48
12.5%
B = 18
33.3%
Euclidean Algorithm Steps
Stepaba = q * b + rRemainder
1481848 = 2 * 18 + 1212
2181218 = 1 * 12 + 66
312612 = 2 * 6 + 00 done
Prime Factorization Comparison
PrimeIn 48In 18min (GCD)max (LCM)
24114
31212
GCD = product of primes raised to min powers. LCM = product of primes raised to max powers.
Fraction Simplifier (uses GCD)
12/18 / 6 = 2/3
All Common Divisors of 48 and 18
1236
Highlighted = GCD (largest common divisor)
Planning notes, formulas, and examples

About the GCD Calculator

The GCD Calculator finds the Greatest Common Divisor of two numbers using the efficient Euclidean algorithm. The GCD (also called GCF or HCF) is the largest positive integer that divides both numbers without a remainder.

The Euclidean algorithm works by repeatedly dividing the larger number by the smaller and taking the remainder, until the remainder is zero. The last non-zero remainder is the GCD. For example, GCD(48, 18): 48 = 2ร—18 + 12, then 18 = 1ร—12 + 6, then 12 = 2ร—6 + 0. So GCD = 6.

The GCD is fundamental in mathematics: simplifying fractions, finding common denominators, solving Diophantine equations, and in cryptography (RSA algorithm). This calculator also shows the step-by-step Euclidean algorithm process.

When This Page Helps

Finding the GCD by listing factors is slow for large numbers. The Euclidean algorithm is fast even for very large values, and this calculator applies it directly.

How to Use the Inputs

  1. Enter the first number.
  2. Enter the second number.
  3. The GCD is calculated using the Euclidean algorithm.
  4. View the result and the step-by-step process.
  5. Use the GCD to simplify fractions or find the LCM.
Formula used
GCD(a, b) = GCD(b, a mod b), with GCD(a, 0) = a The Euclidean algorithm repeatedly applies this rule until the remainder is 0.

Example Calculation

Result: 6

GCD(48, 18): 48 mod 18 = 12 โ†’ GCD(18, 12): 18 mod 12 = 6 โ†’ GCD(12, 6): 12 mod 6 = 0. GCD = 6. Both 48 and 18 are divisible by 6.

Tips & Best Practices

  • GCD(a, 0) = a and GCD(0, 0) is undefined.
  • If GCD(a, b) = 1, then a and b are coprime (no common factors).
  • GCD is used to simplify fractions: 12/18 โ†’ GCD=6 โ†’ 2/3.
  • The LCM can be computed from the GCD: LCM(a,b) = |aร—b| / GCD(a,b).
  • The Euclidean algorithm is over 2,300 years old โ€” one of the oldest algorithms still in use.

The Euclidean Algorithm

Dating back to 300 BCE in Euclid's Elements, this algorithm is remarkably efficient. For numbers with hundreds of digits, it finds the GCD in milliseconds. Its time complexity is O(log(min(a,b))), making it practical for cryptographic applications.

Applications in Number Theory

The GCD is central to modular arithmetic, continued fractions, and the Fundamental Theorem of Arithmetic. It is used to solve linear Diophantine equations of the form ax + by = c, which have solutions only when GCD(a,b) divides c.

Extended Euclidean Algorithm

The extended version also finds integers x and y such that ax + by = GCD(a,b). This is crucial for computing modular inverses in cryptography and for solving systems of congruences.

Sources & Methodology

Last updated:

Frequently Asked Questions

  • The Greatest Common Divisor is the largest positive integer that divides two numbers evenly. For 12 and 8, the GCD is 4 because 4 is the largest number that divides both.