Calculators
GCD & LCM Calculator
Calculate GCD and LCM for two whole numbers.
GCD & LCM Calculator tool
Loading tool…
Jump to a section
About This Tool
Find two closely related number properties in one calculation. The greatest common divisor (GCD), also called the greatest common factor (GCF) or highest common factor (HCF), is the largest positive integer that divides both values without a remainder. The least common multiple (LCM) is the smallest non-negative multiple shared by both values. These results are useful for simplifying fractions and ratios, comparing factor relationships, grouping items evenly, coordinating repeating schedules, and checking number-theory homework.
How To Use It
- Enter two whole numbers. Positive, negative, and zero values are supported.
- Read the GCD and LCM results calculated from the absolute values of the inputs.
- Copy either result when you need it in another calculation.
- Use the GCD when you want the largest shared factor, such as reducing a fraction. Use the LCM when you want the first shared multiple, such as aligning repeating intervals.
- If you enter negative values, interpret the result by magnitude. The calculator reports non-negative GCD and LCM values.
Examples
48 and 18
The GCD is 6 because 6 is the largest integer dividing both numbers. Their LCM is 144.
8 and 15
These numbers are coprime, so their GCD is 1. Their LCM is 120.
24 and 0
Using the standard integer convention, gcd(24, 0) is 24 and lcm(24, 0) is 0.
36 and 60
The GCD is 12, which can reduce 36/60 to 3/5. The LCM is 180, the first positive multiple both numbers share.
-21 and 6
Signs do not change the factor relationship. The calculator uses absolute values, so the GCD is 3 and the LCM is 42.
Useful Notes
How the GCD is found
The calculator uses the Euclidean algorithm: repeatedly replace the larger pair with the divisor and remainder until the remainder becomes zero. The last non-zero divisor is the GCD.
Prime-factor view
You can also understand GCD and LCM through prime factors. The GCD uses the shared prime factors with the smallest powers present in both numbers, while the LCM uses every prime factor with the largest power needed by either number.
How the LCM is found
For non-zero integers a and b, LCM = |a / GCD(a,b) × b|. Dividing before multiplying reduces unnecessary intermediate growth. If either input is zero, the LCM is defined here as zero.
Using GCD to simplify fractions
To reduce a fraction, divide the numerator and denominator by their GCD. For example, gcd(36,60) = 12, so 36/60 becomes 3/5 after both parts are divided by 12.
Using LCM for common denominators
The LCM of two denominators gives the least common denominator for adding or subtracting fractions by hand. Smaller common denominators make manual arithmetic easier while preserving exactness.
Signs and exact integer limits
GCD and LCM are reported as non-negative values, so negative inputs are treated by absolute value. Inputs and the resulting LCM must remain within JavaScript's safe-integer range so the tool does not present rounded integers as exact.
GCD, GCF, and HCF
Greatest common divisor, greatest common factor, and highest common factor are common names for the same integer concept. This page keeps them together instead of creating separate keyword-variant tools.
FAQ
What is the difference between GCD and LCM?
GCD looks for the largest integer that divides both numbers. LCM looks for the smallest non-negative number that is a multiple of both.
What if the GCD is 1?
The two integers are coprime: they have no positive common divisor larger than 1.
Are GCD, GCF, and HCF the same thing?
Yes. Greatest common divisor, greatest common factor, and highest common factor are different names for the same value.
Can I enter negative numbers?
Yes. Divisibility for GCD and LCM depends on magnitude, so the calculator uses absolute values and returns non-negative results.
Can I use decimals or fractions as inputs?
No. This calculator is for whole numbers. Convert decimals or fraction expressions to the whole-number values you want to compare before using it.
What happens when both numbers are zero?
This calculator uses gcd(0,0) = 0 and lcm(0,0) = 0 as a practical computational convention, and shows the zero behavior explicitly rather than dividing by zero.