Modular Inverse Calculator

Find the modular inverse used in RSA and modular arithmetic.

How it is calculated

The modular inverse of a modulo m is the number x such that a × x ≡ 1 (mod m). It exists only when gcd(a, m) = 1, that is, when a and m share no common factor. The tool reduces a into the range 0 to m − 1 (a negative a is wrapped around), then runs the extended Euclidean algorithm, which finds the gcd and the coefficients of a·x + m·y = gcd. If the gcd is 1, x taken modulo m is the inverse. Otherwise it reports that no inverse exists and shows the gcd. The modulus must be 2 or more, and a and m are treated as whole numbers.

Worked example

Find 7⁻¹ mod 26. Euclid: 26 = 3×7 + 5, 7 = 1×5 + 2, 5 = 2×2 + 1, so the gcd is 1. Back-substituting: 1 = 3×26 − 11×7. So x = −11, and −11 + 26 = 15. Check: 7 × 15 = 105 = 4×26 + 1, which leaves remainder 1.

Try this example →

Common mistakes

  • Looking for an inverse when a and m share a factor, such as 6 mod 26 (gcd 2). None exists, and the tool says so.
  • Confusing the modular inverse with the ordinary reciprocal 1 ÷ a. Here the answer is a whole number.
  • Giving a modulus of 1 or less, which has no meaningful inverse.
  • Forgetting to reduce a negative result. Inverses are quoted between 0 and m − 1, so −11 becomes 15.
  • Typing a decimal value for a or m. Only whole numbers make sense here.

About this calculator

This calculator finds the modular multiplicative inverse of a number a modulo m — the value x such that a·x ≡ 1 (mod m) — using the extended Euclidean algorithm. An inverse exists only when gcd(a, m) = 1, i.e. a and m are coprime.

Cryptography engineers and computer science students use modular inverses constantly in RSA key generation (finding the private exponent d from the public exponent e), Diffie–Hellman variants, and other modular-arithmetic algorithms; they're also a standard topic in number theory courses.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    A classic use is the private exponent in a textbook RSA example: with e equal to 7 and a totient of 40, the inverse is 23, and 7 times 23 is 161, one more than 4 times 40. The tool works with ordinary integers, so it suits teaching-sized numbers; real keys run to hundreds of digits and need big-integer software. Are you checking homework, or following a cryptography walk-through?

Popular calculators

All Calculators