Beginner

Greatest Common Divisor Calculator — GCD & Euclidean Algorithm

Enter two whole numbers and the calculator finds their greatest common divisor (GCD) — the largest integer that divides both without remainder — using the Euclidean algorithm, with every division step shown. It also computes the least common multiple (LCM) from GCD automatically.
Enter a positive whole number
Enter a positive whole number
Greatest common divisor (GCD)
12

Largest positive integer that divides both A and B without remainder

GCD
12
LCM (least common multiple)
72
A / GCD
4
B / GCD
1.5
Euclidean algorithm — step by step
1

Step 1: 48 ÷ 18

48 = 2 × 18 + 12
2

Step 2: 18 ÷ 12

18 = 1 × 12 + 6
3

Step 3: 12 ÷ 6

12 = 2 × 6 + 0
=

Remainder = 0 → previous remainder is the GCD

GCD(48, 18) = 12
Results are estimates for general information only and are not professional advice — always verify important results independently before relying on them. Read the full disclaimer.
Quick answer

How does this calculator work?

GCD is found by the Euclidean algorithm: repeatedly divide the larger by the smaller and replace the pair with (divisor, remainder) until the remainder is 0 — the last non-zero remainder is the GCD. Then LCM = A × B / GCD. For GCD(48, 18): 48 = 2×18+12, 18 = 1×12+6, 12 = 2×6+0, so GCD = 6, LCM = 144.

Formula
Euclidean algorithm: GCD(a, b) = GCD(b, a mod b) • LCM(a, b) = a × b / GCD(a, b)
How this is calculated

The Euclidean algorithm is an ancient and highly efficient method for computing GCD. Starting with the larger number (a) and the smaller (b), it repeatedly replaces the pair with (b, a mod b) — i.e., the divisor becomes the new dividend and the remainder becomes the new divisor — until the remainder is zero. The last non-zero remainder is the GCD.

The algorithm is efficient because each step reduces the numbers significantly. In the worst case (consecutive Fibonacci numbers) it takes O(log(min(a, b))) steps. The maximum number of steps for two n-digit numbers is roughly 4.8 × n, so even six-digit inputs finish in a few dozen steps.

The least common multiple (LCM) follows directly from the GCD via LCM(a, b) = a × b / GCD(a, b). This relationship is useful for fraction arithmetic (the LCD of two denominators equals their LCM). The GCD also tells you the simplified form of the fraction a/b: divide both numerator and denominator by GCD(a, b).

Frequently asked questions

The GCD (greatest common divisor) is the largest number that divides both integers without remainder — it makes fractions simpler. The LCM (least common multiple) is the smallest number that both integers divide into — it is used as the common denominator when adding fractions. They are related by GCD(a, b) × LCM(a, b) = a × b.

When GCD(a, b) = 1, the two numbers share no common factors other than 1 — they are called coprime or relatively prime. The fraction a/b is already in its simplest form, and LCM(a, b) = a × b.

Each step computes a = q × b + r, then replaces (a, b) with (b, r). The GCD of a pair equals the GCD of the next pair because any common divisor of (a, b) also divides r = a − q × b, and vice versa. When r = 0, b is the GCD because it divides itself and everything in the chain back to the original inputs.

Also known as

greatest common divisor calculator
gcd calculator
greatest common factor calculator
hcf calculator
euclidean algorithm calculator
gcd step by step
least common multiple from gcd

APA

TG we-Calculate Editorial Team. (2026). Greatest Common Divisor Calculator — GCD & Euclidean Algorithm [Online calculator]. TG we-Calculate. https://we-calculate.com/calculator/greatest-common-divisor-calculator

Chicago

TG we-Calculate Editorial Team. "Greatest Common Divisor Calculator — GCD & Euclidean Algorithm." TG we-Calculate. 2026. https://we-calculate.com/calculator/greatest-common-divisor-calculator.

IEEE

TG we-Calculate Editorial Team, "Greatest Common Divisor Calculator — GCD & Euclidean Algorithm," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/calculator/greatest-common-divisor-calculator

BibTeX

@misc{wecalculate_greatest_common_divisor_calculator, title = {Greatest Common Divisor Calculator — GCD & Euclidean Algorithm}, author = {{TG we-Calculate Editorial Team}}, howpublished = {\url{https://we-calculate.com/calculator/greatest-common-divisor-calculator}}, year = {2026}, note = {TG we-Calculate} }

Did this calculator help you?