The most common way to find inverse matrix is $M^{-1}=\frac1{\det(M)}\mathrm{adj}(M)$. However it is very trouble to find when the matrix is large.
I found a very interesting way to get inverse matrix and I want to know why it can be done like this. For example if you want to find the inverse of $$M=\begin{bmatrix}1 & 2 \\ 3 & 4\end{bmatrix}$$
First, write an identity matrix on the right hand side and carry out some steps:
$$\begin{bmatrix}1 & 2 &1 &0 \\ 3 & 4&0&1\end{bmatrix}\to\begin{bmatrix}1 & 2 &1 &0 \\ 3/2 & 2&0&1/2\end{bmatrix}\to\begin{bmatrix}1/2 & 0 &-1 &1/2 \\ 3/2 & 2&0&1/2\end{bmatrix}\to\begin{bmatrix}3/2 & 0 &-3 &3/2 \\ 3/2 & 2&0&1/2\end{bmatrix}$$ $$\to\begin{bmatrix}3/2 & 0 &-3 &3/2 \\ 0 & 2&3&-1\end{bmatrix}\to\begin{bmatrix}1 & 0 &-2 &1 \\ 0 & 2&3&-1\end{bmatrix}\to\begin{bmatrix}1 & 0 &-2 &1 \\ 0 & 1&3/2&-1/2\end{bmatrix}$$
You can 1. swap any two row of the matrix 2. multiply a constant in any row 3. add one row to the other row. Just like you are doing Gaussian elimination. when the identical matrix shift to the left, the right hand side become
$$M^{-1}=\begin{bmatrix}-2 &1 \\3/2&-1/2\end{bmatrix}$$
How to prove this method work?