As Berci said, generally one may employ the Bezout gcd identity to calculate modular inverses. But that is overkill in the "easy inverse" case $\rm\ a^{-1}\ (mod\ an\pm 1)\:$ when the modulus $\rm\: \equiv \pm 1\,\ (mod\ a).\:$ This implies $\rm\:a,m\:$ are coprime, so $\rm\:a^{-1}$ exists $\rm\:mod\ m,\:$ and we can compute it simply as follows
$\rm\quad\ \ mod\ an\!-\!1\!:\ \ 1\ \equiv\ an\ \Rightarrow\ \dfrac{1}a \,\equiv\, \dfrac{an}a \,\equiv\, n$
$\rm\quad\ \ mod\ an\!+\!1\!:\ \ 1\equiv {-}an\:\Rightarrow\:\dfrac{1}a \,\equiv\, \dfrac{-an}a\, \equiv\, -n$
So $\rm\ mod\ 2n\!-\!1\!:\ \dfrac{1}2 \,\equiv\, n,\:$ by $\rm\:a = 2\:$ above. $ $ So $\rm\:n=3\:$ gives $\rm\ mod\ 5\!:\ \dfrac{1}2 \equiv 3,\,$ indeed $\rm\ 2\cdot 3\equiv 1.$
Beware $\ $ One can employ fractions $\rm\ x\equiv b/a\ $ in modular arithmetic (as above) only when the fractions have denominator $ $ coprime $ $ to the modulus $ $ (else the fraction may not uniquely exist, $ $ i.e. the equation $\rm\: ax\equiv b\,\ (mod\ m)\:$ might have no solutions, or more than one solution). The reason why such fraction arithmetic works here (and in analogous contexts) will become clearer when one learns about the universal properties of fraction rings (localizations).
The "easy inverse" case is essentially the case when computing the Bezout identity by the extended Euclidean algorithm requires only one step. It is much wasted effort to execute the algorithm in this simple case (which occurs quite frequently in practice due to the law of small numbers).