terican

Last verified · v1.0

Calculator · math

Multiplicative Inverse Modulo Calculator

Find the multiplicative inverse of a modulo m. Returns the unique x in [0, m-1] satisfying a·x ≡ 1 (mod m), or -1 if no inverse exists.

FreeInstantNo signupOpen source

Inputs

Multiplicative Inverse (x)

Explain my result

0/3 free

Get a plain-English breakdown of your result with practical next steps.

Multiplicative Inverse (x)

The formula

How the
result is
computed.

What Is the Multiplicative Inverse Modulo?

The multiplicative inverse modulo calculator finds the unique integer x that satisfies the congruence a · x ≡ 1 (mod m), where a is any integer and m is the chosen modulus. This value, written a-1 mod m, is the modular analogue of an arithmetic reciprocal: multiplying a by its inverse always yields a remainder of 1 when divided by m. The result is always the unique integer in the range [0, m − 1].

Existence Condition

An inverse exists if and only if gcd(a, m) = 1. When a and m share a common factor greater than 1, no integer x can satisfy the congruence, and the calculator returns −1. For example, gcd(4, 6) = 2 ≠ 1, so 4 has no inverse modulo 6. When m is prime, every nonzero residue from 1 to m − 1 is guaranteed to have an inverse, which is why prime moduli dominate cryptographic design.

The Extended Euclidean Algorithm

The most efficient method for computing a modular inverse is the Extended Euclidean Algorithm. It generalizes the classical Euclidean algorithm to express gcd(a, m) as an integer linear combination:

gcd(a, m) = a · s + m · t

When gcd(a, m) = 1, the coefficient s satisfies a · s ≡ 1 (mod m). Reducing s into the range [0, m − 1] yields the inverse. According to Wichita State University's Discrete Mathematics reference on multiplicative inverses, this algorithm runs in O(log min(a, m)) steps, making it practical even for very large integers used in cryptography. The University of Washington CSE 311 course notes on Bézout's Theorem formally prove that such coefficients always exist and are computable by back-substitution through the Euclidean remainder chain.

Worked Example 1: 3-1 mod 7

  • Euclidean step: 7 = 2 · 3 + 1
  • Back-substitute: 1 = 7 − 2 · 3
  • So 3 · (−2) ≡ 1 (mod 7)
  • Reduce: −2 mod 7 = 5, giving 3-1 mod 7 = 5
  • Verify: 3 × 5 = 15, and 15 mod 7 = 1 ✓

Worked Example 2: 7-1 mod 11

  • Euclidean chain: 11 = 1 · 7 + 4; 7 = 1 · 4 + 3; 4 = 1 · 3 + 1
  • Back-substitute: 1 = 4 − 3 = 4 − (7 − 4) = 2 · 4 − 7 = 2(11 − 7) − 7 = 2 · 11 − 3 · 7
  • So 7 · (−3) ≡ 1 (mod 11)
  • Reduce: −3 mod 11 = 8, giving 7-1 mod 11 = 8
  • Verify: 7 × 8 = 56, and 56 mod 11 = 1 ✓

Variables Explained

  • Integer a: The number whose modular inverse is sought. Accepts any integer; negative values are automatically reduced modulo m before processing. The inverse exists only when gcd(a, m) = 1.
  • Modulus m: Must be an integer ≥ 2. Prime values of m guarantee that every nonzero element in [1, m − 1] has an inverse. Composite moduli may leave some residues without inverses.

Uniqueness of the Result

When it exists, the inverse is unique within [0, m − 1]. If both x and y satisfy a · x ≡ a · y ≡ 1 (mod m), subtraction gives a · (x − y) ≡ 0 (mod m). Because gcd(a, m) = 1, it follows that x ≡ y (mod m), confirming exactly one canonical representative exists in the specified range.

Practical Applications

  • RSA Cryptography: The private exponent d satisfies e · d ≡ 1 (mod φ(n)), computed as a modular inverse of the public exponent e.
  • Chinese Remainder Theorem: Reconstructing solutions to simultaneous congruences requires inverses of partial moduli, as detailed in Carnegie Mellon's Math 127 notes on the Chinese Remainder Theorem.
  • Competitive Programming: Modular division of a value by k equals multiplication by k-1 mod p, commonly applied with the prime modulus 109 + 7 to keep intermediate results bounded.
  • Elliptic Curve Cryptography: Point doubling and addition on finite-field elliptic curves require modular inverses for coordinate arithmetic.

Reference

Frequently asked questions

What is a multiplicative inverse modulo m?
The multiplicative inverse of integer a modulo m is the unique integer x in [0, m-1] such that (a times x) mod m equals 1, written a^(-1) mod m. For example, the inverse of 3 modulo 7 is 5, because 3 times 5 equals 15 and 15 mod 7 equals 1. This mirrors a reciprocal in ordinary arithmetic but stays entirely within the integers, with no fractions involved.
When does a multiplicative inverse modulo m exist?
A multiplicative inverse of a modulo m exists if and only if gcd(a, m) = 1, meaning a and m share no common factor greater than 1. For instance, 3 has an inverse modulo 7 because gcd(3, 7) = 1, but 4 has no inverse modulo 6 because gcd(4, 6) = 2. When m is a prime number, every nonzero residue from 1 to m minus 1 is guaranteed to have an inverse, which is why cryptographic systems heavily favor prime moduli.
How do you calculate the multiplicative inverse modulo by hand?
Apply the Extended Euclidean Algorithm to express 1 as a linear combination of a and m. For 4^(-1) mod 11: the Euclidean steps give 11 = 2 times 4 + 3, then 4 = 1 times 3 + 1. Back-substituting yields 1 = 4 minus 1 times 3 = 4 minus (11 minus 2 times 4) = 3 times 4 minus 11, so 4 times 3 ≡ 1 (mod 11) and the inverse is 3. Verify: 4 times 3 equals 12, and 12 mod 11 equals 1.
What is the difference between a modular inverse and a regular reciprocal?
A regular reciprocal of a is the real number 1/a, which is typically a non-integer fraction. A modular inverse is always a whole number within [0, m-1] satisfying a times x ≡ 1 (mod m). For example, the reciprocal of 3 is approximately 0.3333, but the modular inverse of 3 modulo 7 is the integer 5. Modular inverses make exact integer division possible inside modular arithmetic, eliminating any need for floating-point approximation.
What happens when no multiplicative inverse exists?
When gcd(a, m) is greater than 1, no integer x can satisfy a times x ≡ 1 (mod m), and the calculator returns -1 to signal this condition. For example, gcd(6, 9) = 3, so 6 has no inverse modulo 9. Checking all residues 0 through 8 confirms that none produces a product of 6 times x that is congruent to 1 modulo 9. In cryptographic contexts, non-invertibility often indicates an invalid key parameter that must be rejected.
What are the real-world applications of the multiplicative inverse modulo?
Multiplicative inverses modulo n appear across cryptography, computing, and mathematics. RSA encryption computes the private exponent d as e^(-1) mod phi(n). The Chinese Remainder Theorem uses modular inverses to reconstruct unique solutions from simultaneous congruences. Competitive programmers apply inverses modulo 10^9 + 7 to perform division without floating-point error. Elliptic curve cryptography relies on modular inverses for point doubling and addition over finite fields, which underpin TLS and digital signature schemes.