Connect via MCP →

Enter Calculation

Formula

Advertisement

Results

Modular Inverse
4
x such that (a·x) mod m = 1
Inverse exists Yes
gcd(a, m) 1

What is a modular inverse?

The modular multiplicative inverse of an integer a modulo m is an integer x such that \((a \cdot x) \bmod m = 1\). It is the "division" operation of modular arithmetic and is central to number theory, the RSA cryptosystem, and many coding-theory algorithms. This calculator finds x using the extended Euclidean algorithm.

Number line wrapping around a circular clock-like modulus ring showing a times x landing on 1
A modular inverse x maps a back to 1 when multiplied, wrapping around the modulus m.

How to use this calculator

Enter the number a and the modulus m (with m ≥ 2). The tool returns the smallest non-negative inverse x in the range 0 ≤ x < m, confirms whether an inverse exists, and shows gcd(a, m). If gcd(a, m) ≠ 1, no inverse exists and the result is reported as "None".

The formula explained

An inverse exists only when \(\gcd(a, m) = 1\), i.e. a and m are coprime. The extended Euclidean algorithm finds integers x and y satisfying \(a \cdot x + m \cdot y = \gcd(a, m)\). When the gcd is 1, reducing x modulo m gives the inverse:

$$\text{a} \cdot x \equiv 1 \pmod{\text{m}} \quad\Longrightarrow\quad x = \text{a}^{-1} \bmod \text{m}$$

The result is normalized to a positive value by adding m if it is negative.

Advertisement
Flat flowchart of the extended Euclidean algorithm steps producing gcd and coefficients
The extended Euclidean algorithm yields coefficients that give the inverse when gcd(a, m) = 1.

Worked example

Find the inverse of 3 modulo 11. We need x with \(3x \equiv 1 \pmod{11}\). Testing, \(3 \times 4 = 12 = 11 + 1\), so \(12 \bmod 11 = 1\). Therefore \(x = 4\). The extended Euclidean algorithm returns the same value, and \(\gcd(3, 11) = 1\), confirming the inverse exists.

FAQ

When does no inverse exist? When a and m share a common factor greater than 1 — for example 4 modulo 6 (gcd = 2) has no inverse.

Does m have to be prime? No. m can be any integer ≥ 2; only coprimality of a and m matters.

What range is the answer in? The inverse is given as the smallest non-negative residue, between 0 and m − 1.

Last updated: