Enter a number a and a modulus m to find x such that a × x ≡ 1 (mod m). The calculator checks that the inverse exists (gcd(a, m) = 1), shows every step of the extended Euclidean algorithm and works with integers hundreds of digits long.
Last updated:
Whole number, can be negative or huge. Expressions like 2^64+1 work.
Whole number ≥ 2
Enter your values to see the result.
Advertisement
Advertisement
How to use the Modular Inverse Calculator
Enter a, the number you want to invert.
Enter the modulus m (2 or more). Powers like 2^61-1 are accepted.
Press Calculate inverse to get a⁻¹ mod m.
Read the steps: the Euclidean divisions and the back-substitution.
Copy the result or download the algorithm table as CSV.
Extended Euclidean algorithm: worked example
Find 17⁻¹ mod 3120. Divide repeatedly, keeping track of how each remainder is built from 3120 and 17:
Division
Remainder
As s·3120 + t·17
3120 = 183 × 17 + 9
9
1·3120 − 183·17
17 = 1 × 9 + 8
8
−1·3120 + 184·17
9 = 1 × 8 + 1
1
2·3120 − 367·17
The gcd is 1, so the inverse exists, and 2·3120 − 367·17 = 1. Reducing mod 3120 gives t = −367 ≡ 3120 − 367 = 2753. Check: 17 × 2753 = 46,801 = 15 × 3120 + 1 ✓.
Small inverse table (mod 11)
Because 11 is prime, every number from 1 to 10 has an inverse modulo 11. Notice that 1 and 10 (≡ −1) are their own inverses.
a
1
2
3
4
5
6
7
8
9
10
a⁻¹ mod 11
1
6
4
3
9
2
8
7
5
10
Tips
To solve a linear congruence a·x ≡ b (mod m) with gcd(a, m) = 1, multiply both sides by the inverse: x ≡ b · a⁻¹ (mod m).
The inverse is unique modulo m: there is exactly one answer between 0 and m − 1.
For modulus 26 (the alphabet), only the 12 numbers coprime to 26 (1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25) have inverses, which is why affine ciphers restrict their key.
Frequently asked questions
What is a modular inverse?
The modular (multiplicative) inverse of a modulo m is the number x between 0 and m − 1 with a × x ≡ 1 (mod m). For example 3⁻¹ mod 11 = 4, because 3 × 4 = 12 = 11 + 1. It plays the role of division in modular arithmetic.
When does a modular inverse exist?
Exactly when a and m are coprime, i.e. gcd(a, m) = 1. If they share a factor g > 1, every multiple of a leaves a remainder that is a multiple of g, so it can never be 1. For example 6 has no inverse mod 9 because gcd(6, 9) = 3. If m is prime, every a not divisible by m has an inverse.
How does the extended Euclidean algorithm find the inverse?
It runs the ordinary Euclidean algorithm for gcd(a, m) while tracking coefficients s and t so that every remainder equals s·m + t·a. When the remainder reaches gcd = 1 you have s·m + t·a = 1, and reducing this mod m leaves t·a ≡ 1, so t mod m is the inverse.
How is the modular inverse used in RSA?
The private exponent d is the inverse of the public exponent e modulo φ(n) (or λ(n)). In the classic textbook example e = 17 and φ(n) = 3120 give d = 17⁻¹ mod 3120 = 2753, because 17 × 2753 = 46,801 = 15 × 3120 + 1.
Can I use Fermat's little theorem instead?
Yes, when m is prime: a⁻¹ ≡ a^(m − 2) (mod m). For 3 mod 11 that is 3⁹ mod 11 = 4. The extended Euclidean algorithm is faster and also works when m is not prime, which is why this calculator uses it.
What about negative numbers?
A negative a is first reduced to the range 0 to m − 1 (−7 mod 26 = 19), then inverted. The answer is given as the smallest positive inverse; any value that differs by a multiple of m, such as the negative representative shown, is also an inverse.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.