How do you find the modular inverse of $5\pmod{\!11}$ I need to find out the modular inverse of 5(mod 11), I know the answer is 9 and got the following so far and don't understand how to than get the answer. I know how to get the answer for a larger one such as 27(mod 392) but am stuck because they are both low numbers.
11=5 (2)+1
5=1 (5)
 A: In finding a modular inverse, you are trying to solve the modular equation
$$
ax\equiv 1\pmod n.
$$
Ordinarily, you use the Extended Euclidean Algorithm for this to solve the equation $ax+ny=1$. If the numbers $a$, and $n$ are small, then simple trial and error is probably just as fast or faster.
For your example, we have $a=5$ and $n=11$, which means would could just use trial and error.
\begin{align}
1\cdot 5 &\equiv 5\\
2\cdot 5 &\equiv 10\\
3\cdot 5 &\equiv 15\equiv 4 \\
4\cdot 5 &\equiv 20\equiv -2\\
5\cdot 5 &\equiv 25\equiv 3 \\
6\cdot 5 &\equiv 30\equiv -3 \\
7\cdot 5 &\equiv 35\equiv 2 \\
8\cdot 5 &\equiv 40\equiv -4 \\
9\cdot 5 &\equiv 45\equiv 1 \\
10\cdot 5 &\equiv 50\equiv -5 \\
\end{align}
Since $9\cdot 5 \equiv 1$ then we have found the modular inverse to be 9.
When looking at those numbers on the far right side, keep in mind that any multiple of 11 made be added or subtracted to the modulus and it is still equivalent. That is, $-3\equiv 30\equiv 8$ since $-3+3(11)=30$ and $8+2(11)=30$.
A: Hint  $\ $[Easy Inverse] $\,\bmod n = ab\!+\!1\!:\,\, ab \equiv -1 \,\Rightarrow\, a(-b) \equiv 1.\,\ $ OP is $\,a,b = 5,2.$
So the inverse is computable by a $\rm\color{#c00}{single\ division}$ $\,a^{-1}\equiv -b\equiv (n\!-\!1)/a\,$ if $\,n\equiv 1\pmod{\!a},\,$ and similarly  $\bmod n = ab\!-\!1\!:\,\ ab\,\equiv\, 1\ \Rightarrow\ $ $\,a^{-1}\equiv b\equiv (n\!+\!1)/a\,\pmod{\!n}$
Generally we can use the Extended Euclidean Algorithm or Gauss's algorithm to compute modular inverses and fractions, e.g. see here and here. The above easy inverse formula is an optimization of the case when the algorithms terminate in a $\rm\color{#c00}{single\ step}$). The analogous double step  optimization is inverse reciprocity. Both prove convenient in manual calculations.
A: You can use your work to get $1=11-5(2)=11+5(-2)$, 
so an inverse of 5 (mod 11) is given by $-2\equiv9\pmod {11}$.
A: Here is a piece of C code that you might find useful:
int Inverse(int n,int a)
{
    int x1 = 1;
    int x2 = 0;
    int y1 = 0;
    int y2 = 1;
    int r1 = n;
    int r2 = a;

    while (r2 != 0)
    {
        int r3 = r1%r2;
        int q3 = r1/r2;
        int x3 = x1-q3*x2;
        int y3 = y1-q3*y2;

        x1 = x2;
        x2 = x3;
        y1 = y2;
        y2 = y3;
        r1 = r2;
        r2 = r3;
    }

    return y1>0? y1:y1+n;
}


Calling Inverse(11,5) returns 9.
Calling Inverse(392,27) returns 363.
