The inverse modulo calculator finds the modular multiplicative inverse of a number: the integer x that makes aยทx โก 1 (mod m). Enter a and the modulus m, and the calculator runs the extended Euclidean algorithm, checks that the inverse exists, shows every quotient and remainder, and gives the Bรฉzout identity behind the answer. It handles numbers with hundreds of digits, so it works for RSA key generation, affine and Hill ciphers, hashing, and number theory homework. A second mode solves general linear congruences aยทx โก b (mod m).
Inverse Modulo Calculator
Whole numbers of any size, m โฅ 2. Negative a is reduced automatically.
Watch a, 2a, 3a, โฆ wrap around a clock with m positions until the jumps land on 1. That jump count is the inverse.
Each row satisfies r = sยทm + tยทa. The row where r = 1 gives the inverse in the t column.
What is Inverse Modulo?
The inverse modulo m of a number a is the integer x between 0 and m โ 1 for which aยทx leaves a remainder of 1 when divided by m. It is written aโ1 mod m and is also called the modular multiplicative inverse.
In ordinary arithmetic the inverse of 5 is 1/5, because 5 ร 1/5 = 1. Modular arithmetic only has whole numbers, so "dividing by a" has to be replaced by "multiplying by aโ1". For example, 3 ร 5 = 15 = 2ยท7 + 1, so 3โ1 โก 5 (mod 7).
Key facts about the modular inverse:
- Existence: aโ1 mod m exists exactly when gcd(a, m) = 1.
- Uniqueness: when it exists, there is only one inverse in the range 0 to m โ 1; all others differ by multiples of m.
- Symmetry: if x is the inverse of a, then a is the inverse of x.
- Self-inverse values: 1 and m โ 1 are always their own inverses, since (m โ 1)ยฒ = mยฒ โ 2m + 1 โก 1.
Every green cell is a pair whose product is 1 mod m, so those two numbers are inverses. Rows with no green cell have no inverse.
How to Calculate Inverse Modulo with the Extended Euclidean Algorithm?
To find aโ1 mod m, run the Euclidean algorithm on m and a, then work backwards to write 1 as sยทm + tยทa; the coefficient t, reduced mod m, is the inverse.
- Divide repeatedly. Write m = qโยทa + rโ, then a = qโยทrโ + rโ, and continue until the remainder is 0.
- Check the last non-zero remainder. That is gcd(a, m). If it is not 1, stop: no inverse exists.
- Track coefficients. Alongside each remainder keep t with the update tnew = told โ qยทt, starting from 0 and 1.
- Read the answer. When the remainder reaches 1, the t on that row satisfies tยทa โก 1 (mod m). Add m if t is negative.
The method needs at most about 2.08ยทln(m) + 1.67 division steps (Lamรฉ's theorem), which is why it finds inverses of 300-digit RSA numbers instantly.
Change a or m. Each division and the back-substitution update as you type.
How to Use This Inverse Modulo Calculator?
Enter the number a and the modulus m, then press "Calculate aโปยน mod m." The calculator supports two modes:
Returns x with aยทx โก 1 (mod m), the gcd, the Bรฉzout coefficients, and the family x + kยทm of all inverses. If gcd(a, m) > 1 it explains why no inverse exists.
Solves aยทx โก b (mod m). There are either no solutions or exactly gcd(a, m) solutions below m, and the calculator lists them.
Inputs are processed with arbitrary-precision integers, so values such as 65537 mod a 2048-bit totient give exact answers. Use the copy button to paste the result into Python, a CAS, or a spreadsheet.
When Does a Modular Inverse Exist?
A modular inverse of a exists if and only if a and m are coprime, meaning gcd(a, m) = 1. Bรฉzout's identity guarantees integers s and t with sยทm + tยทa = gcd(a, m). When the gcd is 1, reducing that equation mod m leaves tยทa โก 1, so t is the inverse.
If the gcd is some d > 1, every product aยทx is a multiple of d, and so is every value it can reduce to mod m. The number 1 is never a multiple of d, so no inverse can exist.
- Prime modulus: every a from 1 to p โ 1 has an inverse, which is why finite fields use prime moduli.
- Composite modulus: only the ฯ(m) numbers coprime to m are invertible. For m = 26, that is 12 of the 25 non-zero letters, which limits the keys of an affine cipher.
Green squares are coprime to m and have an inverse. Click any square to see its inverse or the shared factor that blocks it.
Finding the Inverse with Fermat's Little Theorem and Euler's Theorem
When m is prime, the inverse can also be computed as amโ2 mod m. Fermat's little theorem says apโ1 โก 1 (mod p) for a prime p not dividing a, so a ยท apโ2 โก 1.
Euler's theorem generalises this to any modulus: aฯ(m) โก 1 (mod m) when gcd(a, m) = 1, so aโ1 โก aฯ(m)โ1 (mod m). The catch is that you need ฯ(m), which requires factoring m.
The power is evaluated with square-and-multiply: write the exponent in binary, square at every bit, and multiply by a whenever the bit is 1. This takes about logโ(m) multiplications, the same order of work as the extended Euclidean algorithm, and it is the method used inside many cryptographic libraries for prime fields.
Enter a and m. The tool finds ฯ(m), then raises a to ฯ(m) โ 1 one binary digit at a time.
Modular Inverse Table
Common inverses from cryptography and textbooks, including the 12 valid affine-cipher keys mod 26. Click any row to calculate it.
| a | m | aโปยน mod m | Check aยทaโปยน |
|---|---|---|---|
| 3 | 11 | 4 | 12 = 1ยท11 + 1 |
| 3 | 7 | 5 | 15 = 2ยท7 + 1 |
| 7 | 26 | 15 | 105 = 4ยท26 + 1 |
| 5 | 26 | 21 | 105 = 4ยท26 + 1 |
| 9 | 26 | 3 | 27 = 1ยท26 + 1 |
| 11 | 26 | 19 | 209 = 8ยท26 + 1 |
| 17 | 26 | 23 | 391 = 15ยท26 + 1 |
| 25 | 26 | 25 | 625 = 24ยท26 + 1 |
| 10 | 17 | 12 | 120 = 7ยท17 + 1 |
| 17 | 3120 | 2753 | 46801 = 15ยท3120 + 1 |
| 65537 | 10โน + 7 | 743534192 | โก 1 (mod 10โน + 7) |
| 4 | 6 | none | gcd(4, 6) = 2 |
Modular Inverse in RSA and Cryptography
RSA's private key is a modular inverse: d = eโ1 mod ฯ(n). Choose two primes p and q, set n = pยทq and ฯ(n) = (p โ 1)(q โ 1), and pick a public exponent e coprime to ฯ(n). The private exponent d is the inverse of e modulo ฯ(n).
Encryption computes c = Me mod n and decryption computes M = cd mod n. Because eยทd = 1 + kยทฯ(n), Euler's theorem makes the two exponents cancel and returns the original message.
Modular inverses appear across cryptography and computing:
- Affine and Hill ciphers decrypt by multiplying with the inverse key mod 26.
- Elliptic-curve cryptography divides by a coordinate difference in every point addition, which is a modular inverse.
- The Chinese remainder theorem combines residues using inverses of the moduli.
- Competitive programming computes n choose k mod 109 + 7 with inverse factorials.
Pick two small primes and an exponent. The private key d is found with the same inverse-modulo routine as the calculator.
Other Inverse Calculators
Related tools that solve problems in reverse.
Turns F(s) back into f(t) with partial fractions, a pole-zero map, and a live time-response graph.
(3s+5)/(sยฒ+3s+2) โ 2eโปแต + eโปยฒแต Open calculator Returns the x value or z-score for any area under a normal curve, with left, right, and central tails.
invNorm(0.975) = 1.9600 Open calculator Solves Iโdโยฒ = Iโdโยฒ for light, sound, gravity, and radiation, plus the reciprocal 1/xยฒ.
2ร distance โ 1/4 intensity Open calculator Finds fโปยน(x) by swapping x and y and solving, with the y = x mirror graph and a domain check.
f(x) = 2x + 3 โ (x โ 3)/2 Open calculator Inverts 2ร2 to 6ร6 matrices by Gauss-Jordan elimination with exact fractions and every row step.
A ยท Aโปยน = I Open calculator Takes the antilog in base 10, e, 2, or any base, with characteristic, mantissa, and a log ruler.
antilog(2.5) = 316.23 Open calculator Solves y = k/x, k/xยฒ, and k/xโฟ problems, finds k, and shows the constant-product curve.
x ร y = k = 24 Open calculator Finds the count k for a target probability, or the rate ฮป, with PMF bars and a CDF staircase.
qpois(0.95, 10) = 15 Open calculator Frequently Asked Questions
Answers to common questions about modular multiplicative inverses
The inverse of 3 mod 11 is 4. Multiplying gives 3 ร 4 = 12, and 12 leaves a remainder of 1 when divided by 11, so 3 ยท 4 โก 1 (mod 11). Any number of the form 4 + 11k, such as 15 or โ7, is also an inverse.
Because 4 and 6 share the factor 2, so gcd(4, 6) = 2 instead of 1. Every multiple of 4 is even, and every even number stays even after reducing mod 6, so the product can never equal 1. A modular inverse exists only when a and m are coprime.
No. The modular inverse is a whole number x with aยทx โก 1 (mod m), not the fraction 1/a. For example, 1/3 โ 0.333, but the inverse of 3 mod 7 is 5, because 3 ร 5 = 15 = 2 ร 7 + 1. It plays the role of division inside modular arithmetic.
Use pow(a, -1, m) in Python 3.8 or later. For example, pow(3, -1, 11) returns 4. It raises a ValueError when the inverse does not exist. In JavaScript you need your own extended Euclidean function, and with BigInt it handles numbers of any size.
Reduce the negative number into the range 0 to m โ 1 first, then find the inverse as usual. For โ3 mod 11, add 11 to get 8. The inverse of 8 mod 11 is 7, because 8 ร 7 = 56 = 5 ร 11 + 1. The calculator does this reduction automatically.
The RSA private key d is the modular inverse of the public exponent e modulo ฯ(n). With p = 61 and q = 53, ฯ(n) = 3120, and for e = 17 the private key is d = 17โ1 mod 3120 = 2753. Decryption works because eยทd โก 1 (mod ฯ(n)).
Exactly ฯ(m) numbers between 1 and m โ 1 have an inverse, where ฯ is Euler's totient function. For a prime modulus p, every number from 1 to p โ 1 is invertible, so there are p โ 1 of them. For m = 12, only 1, 5, 7, and 11 are invertible, so ฯ(12) = 4.