The general algorithm is the Extended Euclidean algorithm.
Compute the gcd of $26$ and $5$ by Euclid's algorithm keeping track of coefficients:
$$\begin{align} 26 = & 1 \cdot 26 + 0 \cdot 21 \\ 21 = & 0 \cdot 26 + 1 \cdot 21 \end{align}$$
$21$ fits into $26$ $1$ time leaving a remainder of $5$, so we substract $1$ time the second equation from the first, making the second equation the first (so the smallest number becomes the largest and the smallest is replaced b y the remainder):
$$\begin{align} 21 = & 0 \cdot 26 + 1 \cdot 21 \\ 5 = & 1 \cdot 26 - 1 \cdot 21 \\ \end{align}$$
$5$ fits into $21$ $4$ times so we subtract $4$ times the second equation ($20 = 4 \cdot 26 - 4\cdot 21$) from the first, and swap in the same way to get
$$\begin{align} 5 = & 1 \cdot 26 - 1\cdot 21\\ 1 = & -4 \cdot 26 + 5 \cdot 21\\ \end{align}$$
And the final equation shows that $\gcd(21,26) =1$
Taking the final equation $1 = -4 \cdot 26 + 5 \cdot 21$ modulo $26$, the first term vanishes and we are left with $1 \equiv 5 \cdot 21 \bmod{26}$ which just says that $5$ and $21$ are each other's inverse modulo $26$. So $21^{-1} \bmod{26} = 5$.
Instead of the algorithmic approach (which is fail-safe) we could happen to note that $5 \cdot 5 = 25 = -1 \bmod{26}$, so taking $-$ on both sides we get $5 \cdot -5 = 1 \bmod{26}$ and $-5 = 21 \bmod{26}$ so we get the same inverse for $21$.