Inverse Modulo Calculator

Whole numbers of any size, m โ‰ฅ 2. Negative a is reduced automatically.

Result
Inverse exists
17โปยน mod 43
38
Check
17 ร— 38 = 646 โ‰ก 1 (mod 43)
gcd(a, m)
1
Bรฉzout identity
โˆ’15ยท43 + 38ยท17 = 1
All solutions
x = 38 + 43k
Copy answer
38
Modular Clock

Watch a, 2a, 3a, โ€ฆ wrap around a clock with m positions until the jumps land on 1. That jump count is the inverse.

Extended Euclidean Table

Each row satisfies r = sยทm + tยทa. The row where r = 1 gives the inverse in the t column.

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).

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:

  1. Existence: aโˆ’1 mod m exists exactly when gcd(a, m) = 1.
  2. Uniqueness: when it exists, there is only one inverse in the range 0 to m โˆ’ 1; all others differ by multiples of m.
  3. Symmetry: if x is the inverse of a, then a is the inverse of x.
  4. Self-inverse values: 1 and m โˆ’ 1 are always their own inverses, since (m โˆ’ 1)ยฒ = mยฒ โˆ’ 2m + 1 โ‰ก 1.
Interactive: Multiplication Table mod m

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.

Hover a cell to see the product.

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.

  1. Divide repeatedly. Write m = qโ‚ยทa + rโ‚, then a = qโ‚‚ยทrโ‚ + rโ‚‚, and continue until the remainder is 0.
  2. Check the last non-zero remainder. That is gcd(a, m). If it is not 1, stop: no inverse exists.
  3. Track coefficients. Alongside each remainder keep t with the update tnew = told โˆ’ qยทt, starting from 0 and 1.
  4. 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.

Interactive: Step-by-Step Divisions

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:

1
Modular inverse

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.

2
Linear congruence

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.
Interactive: Which Numbers Are Invertible?

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.

Interactive: Square-and-Multiply Inverse

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.

amaโปยน mod mCheck aยทaโปยน
311412 = 1ยท11 + 1
37515 = 2ยท7 + 1
72615105 = 4ยท26 + 1
52621105 = 4ยท26 + 1
926327 = 1ยท26 + 1
112619209 = 8ยท26 + 1
172623391 = 15ยท26 + 1
252625625 = 24ยท26 + 1
101712120 = 7ยท17 + 1
173120275346801 = 15ยท3120 + 1
6553710โน + 7743534192โ‰ก 1 (mod 10โน + 7)
46nonegcd(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.
Interactive: Mini RSA Key Builder

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.

Inverse Laplace Calculator

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
Inverse Normal 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
Inverse Square Calculator

Solves Iโ‚dโ‚ยฒ = Iโ‚‚dโ‚‚ยฒ for light, sound, gravity, and radiation, plus the reciprocal 1/xยฒ.

2ร— distance โ†’ 1/4 intensity Open calculator
Inverse Function 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
Inverse Matrix Calculator

Inverts 2ร—2 to 6ร—6 matrices by Gauss-Jordan elimination with exact fractions and every row step.

A ยท Aโปยน = I Open calculator
Inverse Logarithm 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
Inverse Variation 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
Inverse Poisson 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.