TITLE: How to use the Extended Euclidean Algorithm manually?
QUESTION [85 upvotes]: I've only found a recursive algorithm of the extended Euclidean algorithm. I'd like to know how to use it by hand. Any idea?

REPLY [2 votes]: Just to complement the other answers, there's an alternative form of the extended Euclidean algorithm that requires no backtracking, and which you might find easier to understand and apply.  Here's how to solve your problem* using it:
$\newcommand{\x}{\phantom}
\newcommand{\r}{\color{red}}
\newcommand{\g}{\color{green}}
\newcommand{\b}{\color{blue}}$
*) …from a duplicate question that I originally wrote this answer for.
$$\begin{aligned}
\g{ 0} \cdot 19 + \r{\x+1} \cdot 29 &= \b{  29} && (1) \\
\g{ 1} \cdot 19 + \r{\x+0} \cdot 29 &= \b{  19} && (2) \\
\g{-1} \cdot 19 + \r{\x+1} \cdot 29 &= \b{  10} && (3) = (1) - (2) \\
\g{ 2} \cdot 19 + \r{  -1} \cdot 29 &= \b{\x09} && (4) = (2) - (3) \\
\g{-3} \cdot 19 + \r{\x+2} \cdot 29 &= \b{\x01} && (5) = (3) - (4)
\end{aligned}$$
…and now you have your solution: $\g{-3} \cdot 19 \equiv \b{1} \pmod{29}$, so the inverse of $19$ modulo $29$ is $-3$ (or $29 - 3 = 27$, if you prefer a non-negative solution).
In effect, what we're doing is trying to find a solution to the linear equation $\g x \cdot 19 + \r k \cdot 29 = \b r$ with the smallest possible $\b r > 0$.  We do this by starting with the two trivial solutions $(1)$ and $(2)$ above, and then generate new solutions with a smaller and smaller $\b r$ by always subtracting both sides of the last solution from the one before it as many times as needed to get a smaller $\b r$ than we have so far.  (In your example, that's only once each time, but I'll show another example below where we that's not the case.)
Eventually, we'll either find a solution with $\b r = 1$, in which case the corresponding $\g x$ coefficient is the inverse we want, or we'll end up with $\b r = 0$, in which case the previous solution's $\b r > 1$ is the greatest common divisor of the number we're trying to invert and the modulus, and thus no inverse exists.  (Of course, we could also just keep going until $\b r = 0$ in any case, and then check the previous line to see if $\b r$ there equals $1$ or not, but that would be extra work we can easily avoid.)
Also, it's worth noting that we're not actually using the $\r k$ coefficients for anything, so if all you're interested in is finding the modular inverse (and/or the GCD), you don't actually have to calculate those.  But showing them makes it clearer why the algorithm works.  (Also, if you do calculate $\r k$, it's easy to verify that you didn't make any mistakes just by checking that the last equation with $\b r = 1$ really holds.)

Anyway, here's a couple more worked examples to illustrate some cases that your example doesn't.  To start with, let's try to find the inverse of $13$ modulo $29$:
$$\begin{aligned}
\g{ 0} \cdot 13 + \r{\x+1} \cdot 29 &= \b{  29} && (1) \\
\g{ 1} \cdot 13 + \r{\x+0} \cdot 29 &= \b{  13} && (2) \\
\g{-2} \cdot 13 + \r{\x+1} \cdot 29 &= \b{\x03} && (3) = (1) - 2 \cdot (2) \\
\g{ 9} \cdot 13 + \r{  -4} \cdot 29 &= \b{\x01} && (4) = (2) - 4 \cdot (3) \\
\end{aligned}$$
This time, we could (and needed to) subtract solution $(2)$ from $(1)$ twice, since $\lfloor 29 \mathbin/ 13 \rfloor = 2$.  And, similarly, we could subtract $(3)$ from $(2)$ four times, since $\lfloor 13 \mathbin/ 3 \rfloor = 4$.  And we can verify that $\g 9$ is indeed the inverse of $13$ modulo $29$ just by checking that $9 \cdot 13 - 4 \cdot 29$ indeed equals $1$.
Now let's try an example where the inverse does not exist, like trying to find the inverse of $15$ modulo $27$:
$$\begin{aligned}
\g{ 0} \cdot 15 + \r{\x+1} \cdot 27 &= \b{  27} && (1) \\
\g{ 1} \cdot 15 + \r{\x+0} \cdot 27 &= \b{  15} && (2) \\
\g{-1} \cdot 15 + \r{\x+1} \cdot 27 &= \b{  12} && (3) = (1) - (2) \\
\g{ 2} \cdot 15 + \r{  -1} \cdot 27 &= \b{\x03} && (4) = (2) - (3) \\
\g{-9} \cdot 15 + \r{\x+5} \cdot 27 &= \b{\x00} && (5) = (3) - 4 \cdot (4) \\
\end{aligned}$$
Oops.  The last solution, with $\b r = 0$, is quite useless to us (except for checking that we did the arithmetic right).  From the previous solution $(4)$, however, we can read that $\gcd(15, 27) = 3$, and even that $\g x = 2$ is a solution to the "generalized inverse" equation $\g x \cdot 15 \equiv \gcd(15, 27) \pmod{27}$.

Ps. See also this answer I wrote on crypto.SE last year, explaining the same algorithm from a slightly different viewpoint.