Multiplicative Inverse Modulo Calculator
Find the modular multiplicative inverse of a number: enter a value a and a modulus n, and the calculator solves a·x ≡ 1 (mod n) using the Extended Euclidean Algorithm, with a verification of the result.
Find Modular Multiplicative Inverse of a Number
Modular Inverse Formula
Where:
- \(a\) — the number whose inverse you want
- \(x\) — the modular multiplicative inverse of \(a\)
- \(n\) — the modulus (must be greater than 1)
- \(y\) — an auxiliary integer from the Extended Euclidean Algorithm
- \(\gcd(a, n)\) — the greatest common divisor of \(a\) and \(n\)
The inverse \(x\) exists if and only if \(\gcd(a, n) = 1\), i.e. when \(a\) and \(n\) are coprime. The Extended Euclidean Algorithm finds coefficients \(x\) and \(y\) satisfying the second equation, and \(x\) taken modulo \(n\) is the answer.
Modular Inverse – Calculation Example
Example: find the multiplicative inverse of 3 modulo 11 (the calculator's default values).
Apply the Extended Euclidean Algorithm to \(a = 3\) and \(n = 11\):
\[ 11 = 3 \cdot 3 + 2 \]
\[ 3 = 1 \cdot 2 + 1 \]
Back-substitute:
\[ 1 = 3 - 2 = 3 - (11 - 3 \cdot 3) = 4 \cdot 3 - 1 \cdot 11 \]
So \(3 \cdot 4 + 11 \cdot (-1) = 1\), which means \(3 \cdot 4 \equiv 1 \pmod{11}\).
Result: the multiplicative inverse of 3 mod 11 is 4, and the check confirms \(3 \times 4 \equiv 1 \pmod{11}\).
How to Use the Calculator
- Enter the number \(a\) in the Number (a) field — the value you want the inverse for.
- Enter the modulus in the Modulo (n) field. It must be greater than 1.
- Read the Multiplicative Inverse result — the value \(x\) with \(a \cdot x \equiv 1 \pmod{n}\).
- Check the Check line, which shows the verification \(a \times x \equiv 1 \bmod n\).
If \(a\) and \(n\) share a common factor greater than 1, the calculator reports that the inverse does not exist, because no multiple of \(a\) can ever be congruent to 1 modulo \(n\).
What Is a Modular Multiplicative Inverse?
In ordinary arithmetic, the inverse of a number is its reciprocal: the inverse of 3 is \(1/3\), because \(3 \cdot 1/3 = 1\). Modular arithmetic has no fractions, so the multiplicative inverse is defined differently. The inverse of \(a\) modulo \(n\) is an integer \(x\) such that
\[ a \cdot x \equiv 1 \pmod{n} \]
In other words, when you multiply \(a\) by \(x\) and divide by \(n\), the remainder is exactly 1. For example, \(3 \times 4 = 12\), and 12 leaves a remainder of 1 when divided by 11, so 4 is the inverse of 3 modulo 11. Every number coprime with the modulus has exactly one inverse in the range \(0\) to \(n-1\).
This concept matters because modular "division" is really multiplication by the inverse. To solve \(a \cdot x \equiv b \pmod{n}\), you multiply both sides by the inverse of \(a\) — the same move as dividing both sides of an ordinary equation, but done in a way that stays within integers.
Modular inverses are also central to cryptography. RSA key generation computes the private exponent as the inverse of the public exponent modulo \(\varphi(n)\); Diffie–Hellman and elliptic-curve schemes rely on inverses in finite fields. Beyond cryptography, inverses appear in error-correcting codes, hashing, and number-theoretic problems solved with tools like the Chinese Remainder Theorem.
When the Inverse Exists (and When It Doesn't)
An inverse of \(a\) modulo \(n\) exists if and only if \(\gcd(a, n) = 1\). Two numbers with a gcd of 1 are called coprime or relatively prime. The reason is visible in the Extended Euclidean identity: it can only produce \(a \cdot x + n \cdot y = 1\) when 1 is a combination of \(a\) and \(n\), which happens precisely when their gcd is 1.
For example, 6 has no inverse modulo 9, because \(\gcd(6, 9) = 3\): every multiple of 6 is divisible by 3, so it can never leave a remainder of 1. But 6 does have an inverse modulo 11, since \(\gcd(6, 11) = 1\).
A useful shortcut: when the modulus \(n\) is a prime, every \(a\) from 1 to \(n-1\) has an inverse, because no number smaller than a prime shares a factor with it. In that special case the inverse can also be computed with Fermat's Little Theorem as \(a^{n-2} \bmod n\); for composite moduli, Euler's Theorem gives the analogous result \(a^{\varphi(n)-1}\)
Limitations and Practical Notes
- The calculator requires \(n > 1\); modulo 1 every number is congruent to 0 and an inverse is meaningless.
- Enter a positive \(a\). If you need the inverse of a negative number, reduce it first: the inverse of \(-a\) equals the inverse of \(n - a\).
- The result is always returned in the range \(0 \le x < n\), which is the standard representative of the solution.
- For very large numbers (hundreds of digits, as in real cryptographic work), browser-based computation reaches its limits; this calculator is intended for everyday and educational use.
- The Extended Euclidean Algorithm runs in logarithmic time, so even large hand-scale inputs are handled instantly — there is no need to test candidate values one by one.
Frequently Asked Questions
How do I find a modular inverse by hand without a calculator?
Use the Extended Euclidean Algorithm. Run the ordinary Euclidean Algorithm on \(a\) and \(n\), then back-substitute each remainder until you express 1 as \(a \cdot x + n \cdot y\). The coefficient \(x\), reduced into the range \(0\) to \(n-1\), is the inverse. As a sanity check, multiply \(a\) by \(x\) and confirm the remainder after division by \(n\) is exactly 1.
Is there a shortcut when the modulus is prime?
Yes. If \(n\) is prime, every \(a\) from 1 to \(n-1\) is coprime with \(n\), so the inverse always exists. By Fermat's Little Theorem you can compute it as \(a^{n-2} \bmod n\). For example, the inverse of 3 modulo 7 is \(3^5 = 243 \equiv 5 \pmod{7}\), and indeed \(3 \times 5 = 15 \equiv 1\). For composite moduli, Euler's Theorem gives \(a^{\varphi(n)-1}\) instead.
Why does the inverse not exist for some numbers?
An inverse exists only when \(\gcd(a, n) = 1\). If \(a\) and \(n\) share a factor \(d > 1\), then every multiple of \(a\) is also divisible by \(d\), so it can never leave a remainder of 1 when divided by \(n\). For instance, 4 has no inverse modulo 6 because both are divisible by 2. Testing coprimality first is the quickest way to know whether an answer exists at all.
Is the modular inverse unique? Can it be negative?
There are infinitely many integers satisfying the congruence, but exactly one in the standard range \(0 \le x < n\), and that is the value reported here. If a manual calculation gives a negative or oversized result, add or subtract multiples of \(n\): if \(x = -2\) modulo 11, the representative is \(11 - 2 = 9\). Both \(-2\) and \(9\) are correct answers, just written differently.
How do I find the inverse of a negative number or a number larger than the modulus?
Reduce the number modulo \(n\) first, then find the inverse of that remainder. For a negative number, add \(n\) until it is positive: the inverse of \(-3\) modulo 11 equals the inverse of \(8\), which is 7. For a number bigger than \(n\), take the remainder after division by \(n\). The calculator expects a positive input, so this reduction step is up to you.
How is modular inverse used to solve equations like 3x ≡ 5 (mod 7)?
Modular "division" is multiplication by the inverse. Find the inverse of the coefficient — for 3 modulo 7 it is 5, since \(3 \times 5 = 15 \equiv 1\) — then multiply both sides: \(x \equiv 5 \cdot 5 \equiv 25 \equiv 4 \pmod{7}\). Verify by substitution: \(3 \times 4 = 12 \equiv 5 \pmod{7}\). This works only when the coefficient is coprime with the modulus.
What is the difference between a modular inverse and a reciprocal?
A reciprocal is a fraction: the inverse of 3 in ordinary arithmetic is \(1/3\). Modular arithmetic works only with integers, so the inverse of \(a\) modulo \(n\) is defined as an integer \(x\) with \(a \cdot x \equiv 1 \pmod{n}\). The two notions share the same purpose — undoing multiplication — but a modular inverse always exists as a whole number (when the gcd condition holds), while a reciprocal does not.