$\text{rank}(AB) = \text{rank}(BA)$ if product of $A$ and $B$ is defined? How can I prove this statement is true/false? I have found a counterexample which proves it is not, but I don't understand why it doesn't work, neither why it does work in some cases.
 A: If you have found a counter-example, then that's enough to conclude this identity is not true. However, you might be looking at some specific matrices $A, B$, then it might hold for them; however, that would be a total coincidence.
The reason why it doesn't hold in generally is pretty intuitive. I presume you know that $\text{rank}:M\rightarrow \mathbb{F}$ is a function that tells you what the dimension of the range of a particular matrix is. So $\text{rank}(I_2)=2$, because its range is the whole space of $\mathbb{R}^2$. Compare this to $\begin{bmatrix}1&0\\0&0\end{bmatrix}$, which maps all of $\mathbb{R}^2$ into the horizontal axis - it collapses the plane down, losing information. 
Now think about some matrices that would collapse the space in different ways. Say $A$ maps $\mathbb{R}^3$ into the $x$-$y$ plane, but that whole plane is the kernel of $B$; then $\text{rank}(BA)=0$, because the product matrix $BA$ maps everything to the origin. Now suppose $B$ maps the $z$ axis back to itself, and $A$ then maps this line into the plane. Then $\text{rank}(AB)=1$, because this product matrix maps $\mathbb{R}^3$ into a line, a one-dimensional subspace. 
Explicitly, this becomes:
$$AB=\begin{bmatrix}
1&0&1\\
0&1&0\\
0&0&0
\end{bmatrix}
\begin{bmatrix}
0&0&0\\
0&0&0\\
0&0&1
\end{bmatrix}
=
\begin{bmatrix}
0&0&1\\
0&0&0\\
0&0&0
\end{bmatrix}
\qquad \text{rank}(AB)=1$$
Compare with
$$BA=\begin{bmatrix}
0&0&0\\
0&0&0\\
0&0&1
\end{bmatrix}
\begin{bmatrix}
1&0&1\\
0&1&0\\
0&0&0
\end{bmatrix}
=
\begin{bmatrix}
0&0&0\\
0&0&0\\
0&0&0
\end{bmatrix}
\qquad \text{rank}(BA)=0$$
In other words, the rank is different because applying matrices in different orders changes which vectors end up where. And really, this is just another way of saying matrices don't commute! Which you probably already knew. :)
