Skip to content

Modular Inverses

In ordinary arithmetic, division by a nonzero number means multiplication by its reciprocal. Modular arithmetic is more delicate. A residue class may or may not have a...

Division in Modular Arithmetic

In ordinary arithmetic, division by a nonzero number means multiplication by its reciprocal. Modular arithmetic is more delicate. A residue class may or may not have a multiplicative inverse.

Let aa and nn be integers with n2n\ge2. A modular inverse of aa modulo nn is an integer bb satisfying

ab1(modn). ab\equiv1\pmod n.

When such a bb exists, we write

ba1(modn). b\equiv a^{-1}\pmod n.

This means that multiplication by aa can be undone modulo nn.

Existence Criterion

An integer aa has a multiplicative inverse modulo nn if and only if

gcd(a,n)=1. \gcd(a,n)=1.

Indeed, the congruence

ab1(modn) ab\equiv1\pmod n

means that

ab1=ny ab-1=ny

for some integer yy. Equivalently,

abny=1. ab-ny=1.

Thus 11 is an integer linear combination of aa and nn. By Bezout’s criterion, this happens exactly when

gcd(a,n)=1. \gcd(a,n)=1.

So invertibility modulo nn is exactly the same as coprimality with nn.

Example

Find the inverse of 77 modulo 2626.

Since

gcd(7,26)=1, \gcd(7,26)=1,

an inverse exists.

Use the Euclidean algorithm:

26=73+5, 26=7\cdot3+5, 7=51+2, 7=5\cdot1+2, 5=22+1. 5=2\cdot2+1.

Now work backward:

1=522. 1=5-2\cdot2.

Since

2=75, 2=7-5,

we get

1=52(75)=3527. 1=5-2(7-5)=3\cdot5-2\cdot7.

Since

5=2637, 5=26-3\cdot7,

we obtain

1=3(2637)27=326117. 1=3(26-3\cdot7)-2\cdot7 =3\cdot26-11\cdot7.

Thus

1171(mod26). -11\cdot7\equiv1\pmod{26}.

Therefore

711115(mod26). 7^{-1}\equiv -11\equiv15\pmod{26}.

Indeed,

715=1051(mod26). 7\cdot15=105\equiv1\pmod{26}.

Uniqueness of Inverses

If an inverse exists, it is unique modulo nn.

Suppose

ab1(modn) ab\equiv1\pmod n

and

ac1(modn). ac\equiv1\pmod n.

Then

abac(modn). ab\equiv ac\pmod n.

Since gcd(a,n)=1\gcd(a,n)=1, cancellation is valid modulo nn, so

bc(modn). b\equiv c\pmod n.

Thus all inverses of aa modulo nn lie in one residue class.

Units Modulo nn

A residue class [a]n[a]_n is called a unit if it has a multiplicative inverse in Z/nZ\mathbb{Z}/n\mathbb{Z}.

The set of all units modulo nn is denoted by

(Z/nZ)×. (\mathbb{Z}/n\mathbb{Z})^\times.

It consists exactly of the classes

[a]n [a]_n

such that

gcd(a,n)=1. \gcd(a,n)=1.

For example, modulo 1010, the units are

[1]10,[3]10,[7]10,[9]10. [1]_{10},[3]_{10},[7]_{10},[9]_{10}.

The classes [2]10[2]_{10}, [4]10[4]_{10}, [5]10[5]_{10}, [6]10[6]_{10}, and [8]10[8]_{10} are not units because each has a common divisor greater than 11 with 1010.

Prime Moduli

If pp is prime, then every nonzero residue class modulo pp is invertible.

Indeed, if

1ap1, 1\le a\le p-1,

then pap\nmid a, so

gcd(a,p)=1. \gcd(a,p)=1.

Therefore [a]p[a]_p has an inverse.

Thus

Z/pZ \mathbb{Z}/p\mathbb{Z}

is a field. This means that addition, subtraction, multiplication, and division by nonzero classes are all possible.

For example, modulo 77,

315(mod7), 3^{-1}\equiv5\pmod7,

because

35=151(mod7). 3\cdot5=15\equiv1\pmod7.

Composite Moduli

If nn is composite, not every nonzero class modulo nn is invertible.

For example, modulo 1212, the class [5]12[5]_{12} is a unit because

gcd(5,12)=1. \gcd(5,12)=1.

Its inverse is itself:

55=251(mod12). 5\cdot5=25\equiv1\pmod{12}.

But [4]12[4]_{12} is not a unit because

gcd(4,12)=4. \gcd(4,12)=4.

There is no integer bb such that

4b1(mod12). 4b\equiv1\pmod{12}.

The obstruction is common divisibility.

Solving Congruences by Inverses

When

gcd(a,n)=1, \gcd(a,n)=1,

the linear congruence

axb(modn) ax\equiv b\pmod n

can be solved by multiplying both sides by a1a^{-1}:

xa1b(modn). x\equiv a^{-1}b\pmod n.

For example, solve

4x3(mod11). 4x\equiv3\pmod{11}.

Since

43=121(mod11), 4\cdot3=12\equiv1\pmod{11},

we have

413(mod11). 4^{-1}\equiv3\pmod{11}.

Therefore

x33=9(mod11). x\equiv3\cdot3=9\pmod{11}.

Inverses and the Extended Euclidean Algorithm

The extended Euclidean algorithm is the standard method for finding modular inverses.

To find a1(modn)a^{-1}\pmod n, compute integers xx and yy such that

ax+ny=gcd(a,n). ax+ny=\gcd(a,n).

If

gcd(a,n)=1, \gcd(a,n)=1,

then

ax+ny=1. ax+ny=1.

Reducing modulo nn, we obtain

ax1(modn). ax\equiv1\pmod n.

Hence

xa1(modn). x\equiv a^{-1}\pmod n.

This gives an efficient and constructive procedure.

Role in Number Theory

Modular inverses make division possible in modular arithmetic, but only for classes coprime to the modulus.

They are essential in solving linear congruences, proving Euler’s theorem, constructing the Chinese remainder theorem, and building cryptographic systems.

The main principle is that modular division is not governed by whether a0a\ne0, but by whether

gcd(a,n)=1. \gcd(a,n)=1.

Coprimality replaces nonzero-ness as the correct condition for invertibility modulo nn.