Modular Inverse

The Problem

In regular math, every number has an inverse:

5×15=15 \times \frac{1}{5} = 1

The inverse of 5 is 15\frac{1}{5}. Multiply them, you get 1.


But in modular arithmetic, there are no fractions. Everything is whole numbers.

So how do we “undo” multiplication?


The Modular Inverse

The modular inverse of aa (mod nn) is a number bb such that:

(a×b)modn=1(a \times b) \mod n = 1

Multiply aa and bb, take mod nn, get 1.


Finding an Inverse

Example: What’s the inverse of 3 mod 7?

We need a number that, when multiplied by 3, gives remainder 1.

Let’s try them all:

TryCalculationResult mod 7Is it 1?
3×13 \times 13333
3×23 \times 26666
3×33 \times 39922
3×43 \times 4121255
3×53 \times 5151511

Found it. The inverse of 3 mod 7 is 5.


We write this as:

315(mod7)3^{-1} \equiv 5 \pmod{7}

Check: 3×5=153 \times 5 = 15, and 15mod7=115 \mod 7 = 1. ✓


Why Do We Care?

In regular math, division is just multiplying by the inverse:

a÷b=a×1ba \div b = a \times \frac{1}{b}

Same in modular arithmetic. To “divide” by bb, multiply by bb’s inverse.


In RSA encryption, the private key dd is the modular inverse of the public exponent ee.

Finding that inverse is how you generate the key pair.