Skip to main content
Calculator Fractions

Greatest Common Divisor Calculator

Calculate the GCD of numbers.

Factors & Denominators

Use the Greatest Common Divisor Calculator

Result
—

How Greatest Common Divisor Calculator Works?

The Greatest Common Divisor Calculator works in 5 steps: it reads 2 integers, takes absolute values, runs the Euclidean algorithm, stops at a zero remainder, and returns the greatest common divisor (GCD). The output line reads GCF = n, as GCD and GCF name the same value.

  1. Enter the 2 integers

    Type the integers in the 2 numerator fields, for example 252 and 105. Keep both denominators non-zero.

  2. Drop the signs

    The calculator converts each input to its absolute value, so GCD(−252, 105) equals GCD(252, 105).

  3. Divide and keep the remainder

    The first division is 252 = 2 × 105 + 42. The pair (252, 105) becomes (105, 42).

  4. Repeat until the remainder is 0

    105 = 2 × 42 + 21, then 42 = 2 × 21 + 0. The algorithm stops after 3 divisions.

  5. Return the GCD

    The last non-zero remainder is 21, so the result panel prints GCF = 21. 252 ÷ 21 = 12 and 105 ÷ 21 = 5.

Greatest Common Divisor Calculator Formula

The greatest common divisor formula is gcd(a, b) = gcd(b, a mod b), with gcd(a, 0) = |a|. Euclid described this division method around 300 BC.

Euclidean algorithm

gcd(a, b) = gcd(b, a mod b)

Replace the pair with the smaller number and the remainder. The remainder shrinks at every step, so the loop always ends.

Base case

gcd(a, 0) = |a|

Every integer divides 0, so the GCD of a number and 0 is the absolute value of that number.

Bézout identity

gcd(a, b) = a·x + b·y

Integers x and y exist for every pair. For 252 and 105, 21 = 252 × (−2) + 105 × 5.

Binary GCD rule

gcd(2a, 2b) = 2 · gcd(a, b)

Computers halve even inputs with bit shifts. gcd(270, 192) = 2 × gcd(135, 96) = 2 × 3 = 6.

Worked example: gcd(1071, 462)

  1. Divide: 1071 = 2 × 462 + 147.
  2. Divide: 462 = 3 × 147 + 21.
  3. Divide: 147 = 7 × 21 + 0.
  4. The remainder is 0, so the GCD is the last divisor: 21.
  5. Check: 1071 = 21 × 51 and 462 = 21 × 22, and gcd(51, 22) = 1.

Greatest Common Divisor Calculator Conversion Table

The greatest common divisor conversion table lists 12 integer pairs with the first Euclidean division, the number of divisions, the GCD, and the coprime status.

Integer PairFirst Division StepDivision StepsGCDCoprime?
270, 192270 = 1 × 192 + 7846No
662, 414662 = 1 × 414 + 24852No
1001, 1431001 = 7 × 143 + 01143No
210, 45210 = 4 × 45 + 30315No
391, 299391 = 1 × 299 + 92323No
546, 390546 = 1 × 390 + 156378No
987, 610987 = 1 × 610 + 377141Yes
1980, 12601980 = 1 × 1260 + 7204180No
437, 323437 = 1 × 323 + 114419No
144, 89144 = 1 × 89 + 55101Yes
2024, 15182024 = 1 × 1518 + 5062506No
858, 330858 = 2 × 330 + 198466No

What is Greatest Common Divisor Calculator?

A Greatest Common Divisor Calculator is a tool that returns the largest positive integer that divides 2 integers exactly, computed with the Euclidean algorithm. The greatest common divisor (GCD) of 391 and 299 is 23.

The term GCD comes from number theory and computer science. Programming languages ship a built-in GCD function, for example math.gcd in Python and std::gcd in C++. Both functions use the same remainder loop as the calculator.

The Euclidean algorithm is fast for large inputs. The worst case happens with consecutive Fibonacci numbers: gcd(987, 610) takes 14 divisions and ends at 1. A pair whose smaller number has 6 digits needs at most 30 divisions.

What are the uses of Greatest Common Divisor Calculator?

The Greatest Common Divisor Calculator has 6 main uses, including fraction reduction, cryptography practice, and code testing.

  • Fraction reduction

    Dividing 546/390 by the GCD 78 returns 7/5.

  • Cryptography practice

    Students confirm that an RSA public exponent and φ(n) are coprime, for example gcd(17, 3120) = 1.

  • Code testing

    Programmers compare the output of a custom GCD function against known pairs such as gcd(2024, 1518) = 506.

  • Linear congruences

    The congruence 6x ≡ 4 (mod 10) has solutions: gcd(6, 10) = 2 divides 4. A congruence a·x ≡ b (mod m) has no solution, if gcd(a, m) does not divide b.

  • Screen aspect ratios

    A 1920 × 1080 display has gcd(1920, 1080) = 120, which gives the aspect ratio 16:9.

  • Number theory proofs

    Students test Bézout coefficients and coprime pairs such as 144 and 89 before writing formal proofs.

Related Factors & Denominators Tools

View all 270 tools →