Modular Inverse Calculator

Find x with a times x mod m equals 1 for coprime pairs.

Math and PercentUpdated 2026-10-162 min read
Modular Inverse Calculator
Inverse of a mod m
...
Check a*x mod m...
GCD...

What it does

Modular inverses undo multiplication in clock math. Working mod 11, multiplying by 3 then by 4 returns to start, since 3 times 4 is 12 which is 1 mod 11. That 4 is the inverse of 3.

The tool above takes a and m and returns inverse, check value 1, and gcd. The defaults 3 and 11 match the worked example, so the page opens showing 4. Type new integers to update all three results.

Inverses exist only for coprime pairs with gcd 1. The extended Euclidean algorithm finds coefficients with ax + my = 1, then x mod m is the inverse. Non coprime pairs like 6 mod 12 share factor 2 and never reach 1.

Cryptography leans on this heavily. RSA keys, Diffie Hellman shares, and elliptic curve math all divide via inverses instead of fractions. Checksums and calendars use smaller mod cases.

This page shows the method, one full hand checked example at 3 mod 11, a reference table, and practice checks that run through the tool.

How to use

  1. Type a as a whole number from 1 to 1e9.
  2. Type m as a whole modulus from 2 to 1e9.
  3. Read Inverse as x in 0 to m-1.
  4. Read Check as 1 for valid inverses.
  5. Ifgcd is not 1 the tool reports no inverse.
  6. Test small pairs first to learn the pattern.

Formula

Find x with (a*x) mod m = 1, needs gcd(a,m)=1 via extended Euclid.
a
Number to invert.
m
Modulus above 1.
x
Inverse in 0 to m-1.

Reduce a mod m first inside. Negative intermediates wrap by adding m. Loop is capped for safety and Euclid always finishes fast.

Worked example

Example: a=3, m=11

Find inverse of 3 modulo 11.

  1. Check gcd(3,11) = 1, so inverse exists.
  2. Euclid: 11 = 3x3 + 2; 3 = 2x1 + 1.
  3. Back substitute to 1 = 4x3 minus 1x11.
  4. Mod 11, x = 4.
  5. Check: 3x4 = 12, 12 mod 11 = 1.
  6. Tool shows 4, check 1, gcd 1.

Reference table

Inverses for sample pairs
a mod mInverseCheck
3 mod 1141
7 mod 26151
5 mod 1251
6 mod 12nonegcd 6

Limits

  • Coprime only. Shared factors give no inverse.
  • Whole numbers 1 to 1e9 here.
  • One inverse in 0 to m-1 returned, others add multiples of m.
  • Clock math only. Fractions need other tools.

Common mistakes

  • Asking for inverse when gcd tops 1.
  • Forgetting to reduce a mod m first.
  • Reading negative intermediate as final without wrapping.
  • Mixing mod inverse with division.
  • Allowing m = 1, where everything is 0.

Try it yourself

Quick checks. Answers sit tucked under each question.

Inverse of 7 mod 26?

15, since 7x15=105 mod 26 is 1.

Inverse of 5 mod 12?

5, since 25 mod 12 is 1.

Questions

What is modular inverse?

x with a*x mod m = 1.

3 mod 11?

4.

Always exists?

No, only when gcd is 1.

Check?

Multiply and mod. Here 12 mod 11 is 1.

Negative?

Wrapped to 0 to m-1 here.

Use?

Crypto division, codes, calendars.

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.