Greatest Common Divisor (GCD) Calculator

Calculate the GCD using the Euclidean algorithm and prime factorization. See Bézout identity, coprimality check, factor Venn diagram, and step-by-step solutions.

GCD
12
Greatest Common Divisor of 48 and 36
LCM
144
Least Common Multiple — GCD × LCM = 48 × 36
Coprime?
No
Shared factors up to 12
Bézout Identity
1·48 + -1·36 = 12
48 + -36 = 12
A / GCD
4
48 ÷ 12
B / GCD
3
36 ÷ 12
Factorization of A
2^4 × 3
48 = 2^4 × 3
Factorization of B
2^2 × 3^2
36 = 2^2 × 3^2

Euclidean Algorithm Steps

StepEquationQuotientRemainder
148 = 36 × 1 + 12112
236 = 12 × 3 + 030

Prime Factor Comparison

Prime4836Min (GCD)Max (LCM)
24224
31212

Factor Venn Diagram

Only in 48
8162448
Common (GCD divides all)
1234612
Only in 36
91836

Divisor Count Comparison

48 divisors (10)
36 divisors (9)
Common divisors (6)
Planning notes, formulas, and examples

About the Greatest Common Divisor (GCD) Calculator

The Greatest Common Divisor (GCD) — also known as the Highest Common Factor (HCF) or Greatest Common Factor (GCF) — is the largest positive integer that divides two numbers without leaving a remainder. It's one of the most fundamental concepts in number theory and has applications ranging from simplifying fractions to cryptography.

This calculator computes the GCD using two classic methods. The Euclidean algorithm repeatedly divides the larger number by the smaller and takes the remainder until it reaches zero — the last non-zero remainder is the GCD. It's fast and elegant, running in O(log(min(a,b))) time. The prime factorization method breaks each number into prime powers and takes the minimum exponent of each shared prime — this gives a deeper structural understanding.

Beyond the GCD itself, the calculator shows the Bézout identity (integers x and y such that ax + by = GCD), the LCM (via the identity GCD × LCM = a × b), whether the numbers are coprime, and a complete Venn-style diagram of all divisors with common ones highlighted. The visual bars let you quickly compare divisor counts.

GCD underpins the RSA cryptosystem, the extended Euclidean algorithm for modular inverses, fraction simplification, and the construction of least common multiples. Whether you're studying elementary number theory or implementing algorithms, the page keeps the Euclidean steps, factor structure, and derived identities visible.

When This Page Helps

The Euclidean algorithm is simple in concept but easy to slip up on when the numbers are large — one wrong remainder and the whole chain is off. This calculator runs both the Euclidean and prime-factorization methods side by side, so you can cross-check results and see exactly where the GCD comes from. It also displays every divisor of each input, colour-coded to highlight the common ones, making the abstract concept concrete. Cryptography and competitive-programming students use it to verify Bézout coefficients and modular inverses.

How to Use the Inputs

  1. Enter two positive integers or click a preset pair.
  2. Choose which method(s) to display: Euclidean, prime factorization, or both.
  3. Toggle "Show All Divisors" to see every divisor and the Venn diagram.
  4. Read the GCD, LCM, and Bézout identity from the output cards.
  5. Study the Euclidean algorithm table to follow each division step.
  6. Examine the prime factor table to see how min/max exponents yield GCD/LCM.
Formula used
Euclidean: GCD(a,b) = GCD(b, a mod b), base case GCD(a,0) = a. Factorization: GCD = ∏(p^min(eₐ,eᵦ)). Bézout: ∃ x,y ∈ ℤ such that ax + by = GCD(a,b).

Example Calculation

Result: GCD = 12

Euclidean: 48 = 36×1 + 12, then 36 = 12×3 + 0. GCD = 12. Also: 48 = 2⁴×3, 36 = 2²×3². Min exponents: 2²×3¹ = 12.

Tips & Best Practices

  • The Euclidean algorithm is extremely efficient — it handles numbers with hundreds of digits.
  • If GCD = 1, the numbers are coprime and the Bézout coefficients give a modular inverse.
  • GCD × LCM = a × b is a quick way to find LCM once you know the GCD.
  • Toggle divisor view to visually see shared factors — the GCD is always the largest green number.

The Euclidean Algorithm Step by Step

The Euclidean algorithm computes GCD(a, b) by repeatedly replacing the larger value with the remainder: GCD(48, 36) → GCD(36, 12) → GCD(12, 0) = 12. Each step reduces the problem size by at least half, so the algorithm terminates in O(log(min(a, b))) steps — making it efficient even for very large numbers. This calculator shows every intermediate step so you can trace the algorithm from start to finish.

Bézout's Identity and the Extended Algorithm

The extended Euclidean algorithm not only finds GCD(a, b) but also integers x and y satisfying ax + by = GCD(a, b). For 48 and 36: 48(1) + 36(−1) = 12. These Bézout coefficients are essential in cryptography — computing the modular inverse of e mod φ(n) in RSA is exactly this problem. If GCD(a, b) = 1, then x is the modular inverse of a mod b.

GCD in Practice — From Fractions to Cryptography

Simplifying fractions is the most familiar GCD application: divide numerator and denominator by their GCD to get lowest terms. In programming, GCD appears in reducing aspect ratios (1920 × 1080 → 16: 9), synchronising gear trains, scheduling periodic events, and computing hash-table sizes. The GCD × LCM = a × b identity provides a fast path to the LCM once the GCD is known, avoiding potentially large intermediate products.

Sources & Methodology

Last updated:

Frequently Asked Questions

  • The Greatest Common Divisor of two integers is the largest positive integer that divides both of them evenly. For example, GCD(48, 36) = 12.