Intermediate

Modular Inverse Calculator — (a × x) ≡ 1 (mod m)

Find the integer x such that (a × x) ≡ 1 (mod m) — the modular multiplicative inverse of a. An inverse exists if and only if gcd(a, m) = 1.
The integer whose modular inverse you want
Must be ≥ 2 and coprime with a
Modular inverse x
5

The unique x in [0, m−1] such that (a × x) mod m = 1

a (normalised)
3
m (modulus)
7
gcd(a, m)
1
Verification: (a × x) mod m
1 ✓
00.91.82.63.54.45.36.170351Residues mod m — a and its inverse x multiply to 1 (mod m)
Results are estimates for general information only and are not professional advice — always verify important results independently before relying on them. Read the full disclaimer.
Quick answer

How does this calculator work?

The modular inverse x satisfies (a × x) mod m = 1 and exists only when gcd(a, m) = 1. It is found using the extended Euclidean algorithm, which solves a·x + m·y = 1 for x, then reduces x to [0, m − 1]. Enter a and m to get the unique inverse or a "no inverse" message.

Formula
(a × x) ≡ 1 (mod m) solved via the extended Euclidean algorithm: a·x + m·y = gcd(a, m)
How this is calculated

The modular multiplicative inverse of a integer a with respect to modulus m is the integer x in [0, m − 1] such that (a × x) ≡ 1 (mod m) — meaning a × x leaves remainder 1 when divided by m. This is the modular analogue of the ordinary multiplicative inverse (reciprocal) in regular arithmetic.

An inverse exists if and only if a and m are coprime, i.e. their greatest common divisor gcd(a, m) = 1. If gcd(a, m) > 1, no such x exists and the calculator reports this. The extended Euclidean algorithm finds integers x and y satisfying Bézout's identity a·x + m·y = gcd(a, m). When gcd = 1, x is the modular inverse, which is then reduced to the canonical range [0, m − 1] by computing ((x mod m) + m) mod m.

Modular inverses are fundamental in number theory and modern cryptography. RSA key generation relies on modular inverses to compute the private-key exponent; they also appear in the Chinese Remainder Theorem, Montgomery multiplication and discrete-logarithm algorithms. The result is always unique within [0, m − 1] when it exists.

Frequently asked questions

When a and m share a common factor greater than 1 (gcd(a, m) > 1). For example, 2 has no inverse mod 4 because gcd(2, 4) = 2. If m is prime, every non-zero a has an inverse, which is why primes are favoured in cryptographic applications.

In modular arithmetic you cannot divide directly. Instead, multiplying by the inverse of a achieves the same effect: a/b ≡ a × b⁻¹ (mod m). This lets you solve linear congruences and compute fractions within modular systems.

Yes — within [0, m − 1] the inverse is unique when it exists. All other solutions differ by multiples of m, so x + k·m is also a solution for any integer k, but only one value falls in the canonical range.

Also known as

modular multiplicative inverse
modular inverse calculator
inverse mod calculator
extended euclidean algorithm
find x such that ax mod m equals 1
modular arithmetic inverse
coprime inverse calculator

APA

TG we-Calculate Editorial Team. (2026). Modular Inverse Calculator — (a × x) ≡ 1 (mod m) [Online calculator]. TG we-Calculate. https://we-calculate.com/calculator/inverse-modulo-calculator

Chicago

TG we-Calculate Editorial Team. "Modular Inverse Calculator — (a × x) ≡ 1 (mod m)." TG we-Calculate. 2026. https://we-calculate.com/calculator/inverse-modulo-calculator.

IEEE

TG we-Calculate Editorial Team, "Modular Inverse Calculator — (a × x) ≡ 1 (mod m)," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/calculator/inverse-modulo-calculator

BibTeX

@misc{wecalculate_inverse_modulo_calculator, title = {Modular Inverse Calculator — (a × x) ≡ 1 (mod m)}, author = {{TG we-Calculate Editorial Team}}, howpublished = {\url{https://we-calculate.com/calculator/inverse-modulo-calculator}}, year = {2026}, note = {TG we-Calculate} }

Did this calculator help you?