Modular inverse calculator

The modular inverse is the number x that makes a × x leave remainder 1 when divided by m. It exists only when a and m are coprime.

Loading the tool…

Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.

How to use it

  1. Enter number a and modulus m.
  2. The result appears straight away and updates as you edit.
  3. Copy the result, or copy a link that keeps the same values to share it.

How it is calculated

The extended Euclidean algorithm finds x and y with a × x + m × y = gcd(a, m). If the gcd is 1, then a⁻¹ = x mod m.

Example

Inputs: Number a = 3, Modulus m = 11. Result: Inverse a⁻¹ mod m: 4.

Limits and caveats

  • a runs from -10^15 to 10^15 and the modulus from 2 to 10^15.
  • Shows the smallest inverse from 0 to m - 1; adding any multiple of m gives another inverse.

Questions about this tool

What is the inverse of 3 mod 11?

4, because 3 × 4 = 12, which leaves remainder 1 when divided by 11.

Why does 6 have no inverse mod 9?

Because gcd(6, 9) = 3, so every multiple of 6 leaves a remainder that is a multiple of 3 and can never be 1.

Where is it used in cryptography?

In RSA the private key d is the inverse of e modulo φ(n), for example 17⁻¹ mod 3120 = 2753.