Math

GCD and LCM Calculator

Find the greatest common divisor and least common multiple of two whole numbers.

Exact method explained belowEditable inputs
Calculation notebook
Calculation notebook

The formula and worked example below explain the calculation.

See the method

Enter your values

Runs on your device

Your answer

Your result

Let’s calculate.

Use the Calculate button to see your result.

Review the method below for assumptions and conventions.

How to use this tool

  1. Enter first number, second number.
  2. Select Calculate to view the result.
  3. Check the method and assumptions below before using the result.

Input reference and sample values

Use the units and choices shown for each field. Sample values are provided for practice, not as recommendations.

InputFormat and unitsSample
First numberNumeric value. Zero or positive.18
Second numberNumeric value. Zero or positive.24

Result for these sample inputs

6
Least common multiple (LCM)
72

Select Try the example in the form to load these values and calculate them again. This replaces the current form inputs. Compare the result with the method and worked explanation below.

The method, explained

The Euclidean algorithm repeatedly replaces (a, b) with (b, a mod b) until the remainder is zero. LCM = a ÷ GCD × b. Integer arithmetic keeps both results exact.

A WORKED EXAMPLE

For 18 and 24, the greatest common divisor is 6 and the least common multiple is 72.

What to keep in mind

Inputs must be nonnegative whole numbers. At least one must be positive. For a positive number paired with zero, the GCD is the positive number and the LCM is zero.

Common questions

Is GCD the same as HCF?

Yes. Highest common factor and greatest common divisor refer to the same positive common factor.

How does LCM help with fractions?

The least common multiple of denominators gives the smallest shared denominator for combining fractions.

Methodology maintained by ClarityKit. How these tools are built and checked.