Skip to main content

Modular Inverse Calculator

Find a−1 mod m with the extended Euclidean algorithm — full step table, coprimality check, and automatic verification that a·x ≡ 1 (mod m).

Big integers supported — arithmetic is exact (BigInt), no floating-point rounding.

Try these

3−1 mod 11 = 4 — because 3 × 4 = 12 ≡ 1 (mod 11).
7−1 mod 26 = 15 — affine-cipher decryption key: 7 × 15 = 105 ≡ 1 (mod 26).
6 mod 9 has no inverse — gcd(6, 9) = 3 ≠ 1, so no x satisfies 6x ≡ 1 (mod 9).
RSA: e = 17, φ(n) = 3120 → d = 17−1 mod 3120 = 2753.

Where modular inverses are used

RSA key generation — the private exponent is d = e−1 mod φ(n).
Affine cipher — decryption needs a−1 mod 26 for the key a.
Linear congruences — solve a·x ≡ b (mod m) via x ≡ b·a−1 (mod m).
Modular division — a ÷ b (mod m) means a · b−1 (mod m).

Frequently asked questions

What is a modular inverse?

The modular inverse of a modulo m is the number x such that a·x ≡ 1 (mod m). It only exists when a and m are coprime, i.e. gcd(a, m) = 1. It is written a⁻¹ mod m.

What is 3⁻¹ mod 11?

4, because 3 × 4 = 12 ≡ 1 (mod 11). You can verify: 12 − 11 = 1.

What is 7⁻¹ mod 26?

15, because 7 × 15 = 105 ≡ 1 (mod 26), since 105 − 4×26 = 1. This is the value used to decode the affine cipher with key a = 7.

When does a modular inverse NOT exist?

When gcd(a, m) ≠ 1. For example, 6 has no inverse mod 9 because gcd(6, 9) = 3, and 13 has no inverse mod 26 because gcd(13, 26) = 13. This calculator shows the gcd so you can see exactly why.

How does the extended Euclidean algorithm find the inverse?

It runs Euclid's algorithm on (a, m) while tracking coefficients x and y with a·x + m·y = r at every step. When the last non-zero remainder is 1, the x from that row is the inverse (reduced mod m). The step table below the result shows every q, r, x, y row.

How is this used in RSA?

RSA computes the private exponent d as the inverse of e modulo φ(n). For example, with e = 17 and φ(n) = 3120, d = 17⁻¹ mod 3120 = 2753, because 17 × 2753 = 46801 = 15×3120 + 1.

Can a be negative?

Yes. The calculator first reduces a modulo m. For example, −3 mod 11 ≡ 8, and 8⁻¹ mod 11 = 7, so (−3)⁻¹ mod 11 = 7. Check: 8 × 7 = 56 ≡ 1 (mod 11).

What is the inverse of 1 mod m?

Always 1, because 1 × 1 = 1 ≡ 1 (mod m) for any m.

What happens when m = 1?

Every integer is congruent to 0 mod 1, so the inverse is 0 — the trivial ring. The calculator reports 0 for any a mod 1.

How do I divide modulo m?

There is no direct division; instead multiply by the inverse: a ÷ b (mod m) = a · b⁻¹ (mod m). For example, 5 ÷ 7 mod 11 = 5 × 8 = 40 ≡ 7 (mod 11), since 7⁻¹ mod 11 = 8.

Does this calculator handle very large numbers?

Yes. All arithmetic uses BigInt, so values far beyond 2⁵³ are exact. For example, 999999937⁻¹ mod 1000000007 is computed exactly, not with floating-point rounding.

What are the main applications of modular inverses?

RSA key generation (private exponent d = e⁻¹ mod φ(n)), the affine cipher (decryption needs a⁻¹ mod 26), solving linear congruences a·x ≡ b (mod m), and modular division in cryptography and competitive programming.

Free tool by NRTechStudio