🔢
Math

GCD and LCM Calculator

Find the greatest common divisor and least common multiple instantly.

JM
James Mitchell
Content Editor
5 min read
Updated

Inputs

Enter a positive integer

Enter a positive integer

Leave blank or enter 0 to skip

Results

Greatest Common Divisor (GCD)
Largest number that divides all inputs evenly
Least Common Multiple (LCM)
Prime Factors (First Number)
Prime Factors (Second Number)
Formula
GCD(a,b) = Euclidean Algorithm; LCM(a,b) = (a × b) / GCD(a,b)
Request plugin

The GCD and LCM Calculator is your go-to tool for finding the Greatest Common Divisor and Least Common Multiple of any set of numbers. Whether you're working on math homework, solving real-world problems, or preparing for standardized tests, this calculator delivers instant, accurate results. GCD represents the largest number that divides your inputs without remainder, while LCM is the smallest number divisible by all your inputs. These concepts are fundamental in number theory, fraction simplification, and solving problems involving common multiples. Our calculator handles two or more numbers and shows prime factorizations for deeper understanding.

How it works

The GCD and LCM Calculator uses the Euclidean Algorithm to compute the Greatest Common Divisor efficiently. This ancient algorithm works by repeatedly replacing the larger number with the remainder of division until reaching zero. The final non-zero remainder is your GCD. Once GCD is determined, LCM is calculated using the mathematical relationship: LCM(a,b) = (a × b) / GCD(a,b). For three or more numbers, the calculator applies these formulas iteratively, finding GCD of the first two numbers, then using that result with the third number, and so on. The calculator also displays prime factorizations, showing the building blocks of each number. This helps you visualize why certain numbers have specific GCD and LCM values. Understanding prime factors makes it easier to grasp the underlying mathematical relationships and verify results independently.

Formula
GCD(a,b) = Euclidean Algorithm; LCM(a,b) = (a × b) / GCD(a,b)
The Euclidean algorithm finds GCD by repeatedly replacing the larger number with the remainder until reaching zero; LCM is calculated using the inverse relationship with GCD.
💡

Worked example

Consider finding the GCD and LCM of 48 and 18. Using the Euclidean Algorithm: 48 = 18 × 2 + 12, then 18 = 12 × 1 + 6, then 12 = 6 × 2 + 0. The GCD is 6. For LCM: (48 × 18) / 6 = 864 / 6 = 144. So 6 is the largest number dividing both evenly, and 144 is the smallest number both divide into. Prime factors: 48 = 2^4 × 3, and 18 = 2 × 3^2, which confirms our results.

What is the Greatest Common Divisor?

The Greatest Common Divisor (GCD), also called the Highest Common Factor or HCF, is the largest positive integer that divides all given numbers without leaving a remainder. For example, the GCD of 12 and 8 is 4 because 4 divides both numbers evenly (12 ÷ 4 = 3 and 8 ÷ 4 = 2), but no number larger than 4 does. GCD is useful for simplifying fractions, finding common denominators, and solving problems involving equal grouping. In everyday applications, GCD helps when you need to divide items into equal groups, create equally-sized packages, or find the largest unit of measurement that fits into multiple quantities.

What is the Least Common Multiple?

The Least Common Multiple (LCM), sometimes called the Lowest Common Multiple, is the smallest positive integer that is divisible by all given numbers. For instance, the LCM of 4 and 6 is 12 because 12 is the smallest number that both 4 and 6 divide into evenly (12 ÷ 4 = 3 and 12 ÷ 6 = 2). LCM is essential for adding and subtracting fractions with different denominators, solving scheduling problems, and finding common cycles. Practical applications include coordinating recurring events, such as determining when two periodic tasks will coincide again or finding the smallest container size needed to measure multiple quantities.

The Euclidean Algorithm Explained

The Euclidean Algorithm is an efficient method for computing GCD dating back to ancient Greece. The algorithm works on the principle that the GCD of two numbers is the same as the GCD of the smaller number and the remainder when the larger is divided by the smaller. By repeatedly applying this process, we eventually reach a remainder of zero; the last non-zero remainder is the GCD. This algorithm is remarkably fast, even for very large numbers, because the remainder decreases rapidly with each step. It forms the foundation of many modern cryptographic systems and is taught in virtually every number theory course worldwide.

Relationship Between GCD and LCM

GCD and LCM are inversely related through a fundamental mathematical formula: GCD(a,b) × LCM(a,b) = a × b. This relationship holds for any two positive integers and provides an elegant way to verify your calculations. If you know the GCD, you can immediately compute LCM by rearranging the formula: LCM(a,b) = (a × b) / GCD(a,b). This connection also reveals that numbers with a larger GCD typically have a smaller LCM relative to their product. For coprime numbers (numbers whose GCD is 1), the LCM equals the product of the numbers themselves.

Prime Factorization and GCD/LCM

Prime factorization provides another perspective on GCD and LCM. When you factor each number into its prime components, the GCD is found by taking the lowest power of each common prime factor. The LCM is found by taking the highest power of each prime factor that appears in any of the numbers. For example, 24 = 2^3 × 3 and 36 = 2^2 × 3^2. The GCD takes the minimum powers: 2^2 × 3 = 12. The LCM takes the maximum powers: 2^3 × 3^2 = 72. This method is particularly useful for understanding the structure of numbers and verifying results.

Real-World Applications

GCD and LCM calculations appear frequently in real-world scenarios. In construction, LCM helps determine optimal tile sizes to cover floors without cutting tiles. In scheduling, GCD helps find the longest time interval for events that align perfectly. In music, LCM determines when rhythmic patterns repeat. In manufacturing, GCD optimizes batch processing for multiple product lines. In fractions and ratios, GCD simplifies expressions to lowest terms. In astronomy and physics, these concepts help describe orbital mechanics and wave interference patterns. Understanding GCD and LCM extends beyond pure mathematics into practical problem-solving across numerous industries.

Frequently asked questions

What's the difference between GCD and LCM?
GCD is the largest number that divides all inputs evenly, while LCM is the smallest number divisible by all inputs. GCD makes things smaller (useful for simplifying), while LCM makes things larger (useful for finding common denominators).
Can GCD and LCM be calculated for more than two numbers?
Yes. For multiple numbers, calculate GCD and LCM iteratively. Find the GCD of the first two numbers, then use that result with the third number, continuing until all numbers are processed.
What does it mean if GCD equals 1?
When GCD equals 1, the numbers are coprime or relatively prime, meaning they share no common factors other than 1. Examples include any two consecutive integers or 17 and 19.
How is LCM related to the product of two numbers?
The product of GCD and LCM equals the product of the original numbers: GCD × LCM = a × b. This relationship allows you to calculate LCM if you know GCD: LCM = (a × b) / GCD.
Why is the Euclidean Algorithm so efficient?
The Euclidean Algorithm is efficient because remainders decrease exponentially, not linearly. Even with very large numbers, it typically requires only a handful of steps, making it suitable for computational applications.
Can this calculator handle zero or negative numbers?
This calculator accepts positive integers only. Zero and negative numbers are excluded because GCD and LCM are defined specifically for positive integers. The calculator validates all inputs automatically.
How do I use GCD to simplify fractions?
To simplify a fraction, calculate the GCD of the numerator and denominator, then divide both by the GCD. For example, 48/18 has GCD 6, so it simplifies to 8/3.