Chinese Remainder Theorem Calculator

Solve two simultaneous congruences with coprime moduli and get the unique answer modulo their product.

Math and PercentUpdated 2026-11-192 min read
Chinese Remainder Theorem Calculator
The first congruence is x congruent to a1 modulo m1.
A whole number modulus of at least 2.
The second congruence is x congruent to a2 modulo m2.
Must be coprime with m1.
Smallest nonnegative solution
...
Combined modulus...
Solution modulo m1...
Solution modulo m2...
System solved...

What it does

The Chinese remainder theorem solves systems of congruences with different moduli. For two congruences with coprime moduli, it guarantees exactly one solution modulo the product of the moduli.

This tool takes two remainders and their moduli. It checks that the moduli are coprime, finds one solution using Bezout coefficients, and reduces it to the smallest nonnegative representative.

The page opens with x congruent to 6 modulo 9 and x congruent to 4 modulo 11. The solution is 15 modulo 99, because 15 leaves remainder 6 on division by 9 and remainder 4 on division by 11.

The construction writes the second congruence in terms of the first and uses the modular inverse of the first modulus relative to the second. That is why the extended Euclidean algorithm appears in the background.

If the moduli share a common factor, a solution may not exist or may not be unique in the same way. This two congruence tool rejects such inputs instead of returning a misleading answer.

How to use

  1. Enter the first remainder and modulus.
  2. Enter the second remainder and modulus.
  3. Confirm the two moduli are coprime.
  4. Read the smallest nonnegative solution as the main result.
  5. Check the combined modulus, which is the product of the two moduli.
  6. Use the two check rows to verify the remainders.

Formula

Solve x = a1 mod m1 and x = a2 mod m2; the solution is unique modulo m1 times m2 when gcd(m1, m2) = 1
a1, a2
The target remainders of the two congruences.
m1, m2
Coprime moduli.
solution
The smallest nonnegative x satisfying both congruences.

Writing x equals a1 plus m1 times y reduces the second congruence to m1 times y congruent to a2 minus a1 modulo m2. Multiplying by the inverse of m1 modulo m2 gives y, and hence x. The solution is then reduced into the range zero to m1 times m2 minus one.

Worked example

Example: mod 9 and mod 11

The page opens with x = 6 mod 9 and x = 4 mod 11.

  1. Check that 9 and 11 are coprime, so a unique solution exists modulo 99.
  2. Write x as 6 plus 9y.
  3. The second congruence requires 6 plus 9y congruent to 4 modulo 11.
  4. So 9y is congruent to minus 2, or 9, modulo 11.
  5. The inverse of 9 modulo 11 is 5, so y is congruent to 5 times 9, which is 45, or 1 modulo 11.
  6. Taking y = 1 gives x = 15, which the tool reports with combined modulus 99.

Reference table

Sample congruence systems
SystemSmallest solutionCombined modulus
x = 6 mod 9, x = 4 mod 111599
x = 2 mod 3, x = 3 mod 5815

Limits

  • Handles exactly two congruences.
  • Moduli must be coprime whole numbers from 2 to 1,000,000,000.
  • Returns the smallest nonnegative representative only.
  • All solutions differ by multiples of the combined modulus.

Common mistakes

  • Using moduli that share a common factor.
  • Forgetting that the solution is unique only modulo the product.
  • Reporting a negative representative when a nonnegative one exists.
  • Mixing up which remainder belongs to which modulus.
  • Assuming every pair of congruences has a solution.

Try it yourself

Quick checks. Answers sit tucked under each question.

x = 2 mod 3 and x = 3 mod 5. Smallest solution?

8, with combined modulus 15.

What is the combined modulus in the default example?

99, the product of 9 and 11.

What if the moduli are not coprime?

The tool reports an error because the two congruence version requires coprime moduli.

Questions

What does the theorem guarantee?

A unique solution modulo the product when the moduli are pairwise coprime.

Why must the moduli be coprime?

Otherwise the modular inverse needed in the construction may not exist.

How is the solution found?

By substituting one congruence into the other and using a modular inverse from the extended Euclidean algorithm.

Are there other solutions?

Yes. Adding any multiple of the product of the moduli gives another solution.

Can there be more than two congruences?

Yes, but this tool handles two. The general case needs all moduli pairwise coprime.

Where is this used?

It appears in cryptography, hashing and efficient computation with large integers.

Sources

How this page was checked. The formula above was matched against the cited sources, and the worked example was run through the tool on this page before publishing. If you spot an error, contact us so we can fix it and note the correction.