# If product of matrices $A$ and $B$ is defined, then $\operatorname{rank}(AB)=\operatorname{rank}(BA)$

If product of matrices $A$ and $B$ is defined, then $\operatorname{rank}(AB)=\operatorname{rank}(BA)$. Is this always true, or just in some special cases?

It is trivially true if both are invertible, but not otherwise. Classic counterexample is $$A=\begin {bmatrix}1&0\\0&0\end {bmatrix}, \ \ \ B=\begin {bmatrix}0&1\\0&0\end {bmatrix}.$$

The answer is no. Here is a counter-example:

$$A=\begin {bmatrix}1&1\end {bmatrix}, \ \ \ B=\begin {bmatrix}1\\-1\end {bmatrix}.$$

It is not always true. Consider:

$$A=\begin{pmatrix} 1 & 1 \\ 0 & 0 \end{pmatrix} \qquad B=\begin{pmatrix} 1 & 0 \\ -1 & 0 \end{pmatrix}$$

Then:

$$AB=\begin{pmatrix} 0 & 0 \\ 0 & 0 \end{pmatrix} \qquad BA=\begin{pmatrix} 1 & -1 \\ 0 & 0 \end{pmatrix}$$