Modular Inverse Calculator
Find x with a times x mod m equals 1 for coprime pairs.
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
- Type a as a whole number from 1 to 1e9.
- Type m as a whole modulus from 2 to 1e9.
- Read Inverse as x in 0 to m-1.
- Read Check as 1 for valid inverses.
- Ifgcd is not 1 the tool reports no inverse.
- Test small pairs first to learn the pattern.
Formula
- 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.
- Check gcd(3,11) = 1, so inverse exists.
- Euclid: 11 = 3x3 + 2; 3 = 2x1 + 1.
- Back substitute to 1 = 4x3 minus 1x11.
- Mod 11, x = 4.
- Check: 3x4 = 12, 12 mod 11 = 1.
- Tool shows 4, check 1, gcd 1.
Reference table
| a mod m | Inverse | Check |
|---|---|---|
| 3 mod 11 | 4 | 1 |
| 7 mod 26 | 15 | 1 |
| 5 mod 12 | 5 | 1 |
| 6 mod 12 | none | gcd 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.