Bootstrap
  E.E.A. .com
It doesn't have to be difficult if someone just explains it right.

Modular Multiplicative Inverse

Calculating the modular multiplicative inverse of a number modulo n, using the Extended Euclidean Algorithm.

Before you read this page

Make sure to read these pages (or watch the videos) first, otherwise this page is confusing:

Here are some things vaguely described, such that you get an idea of what these notations mean.

$\mathbb{Z}$ is the set of all integers. So:
$$\mathbb{Z} = \{..., -3, -2, -1, 0, 1, 2, 3, ...\}$$


$\mathbb{Z}_n$ is that same set, but then with $\mod n$ applied to all numbers.
If you remove all the duplicates in a set after applying $\mod n$ to the numbers, you'll see that it is a finite set, with
$$\mathbb{Z}_n = \{0, 1, 2, ..., n−1\}$$
If we choose $n=6$ for example, we have $$\mathbb{Z}_6 = \{0, 1, 2, 3, 4, 5\}$$ And with $n=15$, we get $$\mathbb{Z}_{15} = \{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14\}$$


Operations are things like $+$ and $\times$. You can use them on elements in these sets.


If you have a set and such a operation, then you can call that a group if they satisfy some requirements together. One of those requirements is that if you use the operation on two elements in the set, the result of that operation is another element that's also part of that set. To be more precise, the requirements are: associativity, inverse, identity, closure, commutativity and stuff like that. Look it up if you want to know more about it.


Table of contents:


What is an inverse?

The inverse of a number depends on the operation that is used.
Here are two examples:


How to calculate the modular multiplicative inverse of an integer?

We can do this using the Extended Euclidean Algorithm.
But, a cool thing is that we don't need the s-columns (s1, s2, s3) from the algorithm to find the answer, so we can use less columns.

Remember, in the Extended Euclidean algorithm, we're trying to find $s$ and $t$ such that: $$s \times a + t \times b = gcd(a, b)$$ Right now, we're using the algorithm to calculate a multiplicative inverse. In the context of modulos, it makes more sense to rename our variable $a$ to $n$. So we get: $$s \times n + t \times b = gcd(n, b)$$ BUT, this formula only works if we actually have a multiplicative inverse / if $n$ and $b$ are coprime. In other words, if $gcd(n, b)==1$: $$(s \times n) + (b \times t) = 1$$ In equations, you can always apply the same thing to the left hand side and the right hand side at the same time and then the equation still holds.
So let's apply $\pmod{n}$ to both sides, because why not: $$(s \times n) + (b \times t) \pmod{n} \equiv 1 \pmod{n}$$ This is the same as: $$(s \times n) \pmod{n} + (b \times t) \pmod{n} \equiv 1 \pmod{n}$$ $s \times n$ is divisible by $n$ (since you multiply $s$ by $n$), so $s \times n \pmod{n} \equiv 0 \pmod{n}$: $$0 \pmod{n} + (b \times t) \pmod{n} \equiv 1 \pmod{n}$$ This is the same as $$(b \times t) \pmod{n} \equiv 1 \pmod{n}$$ So $t$ is the multiplicative inverse of $b$ in $\mathbb{Z}_{n}$. This value will be in the t-columns, hence we do not need the s-columns

Our goal

To calculate a multiplicative inverse of a number $t \pmod{n}$, we want to find a $t$ such that: $$t \times b \equiv 1 \pmod{n}$$

(Remember that in the Extended Euclidean algorithm we wanted to find an $s$ and $t$ such that $s \times a + t \times b = gcd(a, b)$. When using the Extended Euclidean Algorithm to find a multiplicative inverse, we're basically on a lite version of this quest. So we can now use a simpler version of this formula. See the spoiler above to understand more about this).

General way of doing it

If you have to find the inverse of an integer $b$ in $\mathbb{Z}_n$ (or of an integer $b$ modulo $n$), then:

Once you are done with creating the table:


Example

Find the modular multiplicative inverse of 11 in $\mathbb{Z}_{26}$.

Answer:
So $b=11$ and $n=26$.
Now we use the Extended Euclidean Algorithm with $a=n=26$.
This means that instead of using $a$ as the first column (like we normally do in the Extended Euclidean Algorithm), we use $n$.
The second column is still $b$, starting with $b=11$.

nbqr t1t2t3
26112401-2
114231-25
4311-25-7
31305-726

Column $b$ on the last row has the value $1$, so $gcd(n, b) = 1$.
This is exactly what we want, because now we know that $11$ has a multiplicative inverse modulo $26$.
(If this value of $b$ on the last row would be any other number than $1$, we would just stop here and say "11 has no multiplicative inverse modulo 26". But that's not the case, so let's continue)
So we need the value of column $t2$ on the last row. Let's also refer to this value as $t2$. As you can see in the table, the value of the column $t2$ in the last row is $-7$, so we just say $t2=-7$.
Our final answer $t$ is that number with $\pmod{n}$ applied to it. Let's do that:: $$t \equiv t2 \pmod{n} \equiv (-7) \pmod{26} \equiv 19$$ This is our answer: the multiplicative inverse of $11$ modulo $26$ is $19$.


Verification

We can check that we found the right answer by verifying that $t \times b \equiv 1 \pmod{n}$:
So $b=11$, $n=26$ and $t=19$.
Then \[ \begin{aligned} t \times b \pmod{n} &\equiv \\ 19 \times 11 \pmod{26} &\equiv \\ 209 \pmod{26} &\equiv 1 \pmod{26} \\ &\equiv 1 \pmod{n} \\ \end{aligned} \] So yes, $t \times b \equiv 1 \pmod{n}$, meaning that the answer is correct.


More examples? Check the calculator!

And of course our cool modular multiplicative inverse calculator can do this entire process for you!
Enter the numbers you want and the calculator will calculate the multiplicative inverse of b modulo n using the Extended Euclidean Algorithm.
It will also show you the verification!