GCD Calculator

The greatest common divisor (GCD) of two integers is the largest positive integer that divides both numbers exactly. It is a fundamental concept in number theory with practical uses in simplifying fractions, solving Diophantine equations, and cryptographic algorithms such as RSA. This calculator uses the classic Euclidean algorithm, which works by repeatedly taking the remainder of successive divisions until the remainder is zero. The last non-zero remainder is the GCD. Enter any two positive integers to see the result instantly, along with a step-by-step breakdown of the algorithm.

Enter a positive integer
Enter a positive integer
6.00
n/a

GCD formula (Euclidean algorithm)

GCD(a, b) = GCD(b, a mod b) until b = 0; then GCD = a

Repeatedly replace (a, b) with (b, a mod b). When b reaches zero, the value of a at that point is the GCD. The algorithm is guaranteed to terminate because the remainder strictly decreases at each step.

Understanding GCD

  • GCD is always a positive integer. GCD(a, b) divides both a and b with no remainder.
  • If GCD(a, b) = 1, the numbers are coprime (share no common factors other than 1).
  • To simplify a fraction a/b, divide both by GCD(a, b): the result is the fraction in lowest terms.
  • GCD is commutative: GCD(a, b) = GCD(b, a).
  • The Euclidean algorithm runs in O(log(min(a, b))) steps, making it efficient for very large numbers.

GCD calculator: frequently asked questions

What is the greatest common divisor?

The greatest common divisor (GCD) of two integers is the largest positive integer that divides both numbers without a remainder. For example, GCD(12, 18) = 6 because 6 is the largest number that divides both 12 and 18 evenly.

How does the Euclidean algorithm work?

The Euclidean algorithm repeatedly applies the rule GCD(a, b) = GCD(b, a mod b) until the remainder is zero. The last non-zero remainder is the GCD. For example: GCD(48, 18) = GCD(18, 12) = GCD(12, 6) = GCD(6, 0) = 6.

What is GCD(0, n)?

By convention, GCD(0, n) = n for any positive integer n. Zero is divisible by every integer, so the largest divisor common to both 0 and n is n itself.

Can GCD be used for fractions?

Yes. To simplify a fraction a/b to lowest terms, divide both the numerator and denominator by GCD(a, b). For example, 12/18 simplifies to 12/6 divided by 18/6 = 2/3.

What is the relationship between GCD and LCM?

For any two positive integers a and b, the product of their GCD and LCM equals the product of the numbers: GCD(a, b) times LCM(a, b) = a times b. This lets you compute LCM quickly once you know the GCD.

Official sources

Reviewed by the CalculatorHub team, edited by James Graham, 15 June 2026. See our methodology.