Let $A$ and $B$ be square matrices of order n so that $AB = BA$. Prove $\mathrm{rank}(A+B) \leq \mathrm{rank}(A) + \rm{rank}(B) - \mathrm{rank}(AB)$. For $AB=BA$ to hold, that would mean, $A$ is a diagonal or identity matrix. I tried substituting real matrices in and realized that $\mathrm{rank}(AB) = \mathrm{rank}(A)$, so that means $\mathrm{rank}(A+B) \leq \mathrm{rank}(B)$.

But how do I formalize this as a proof? Am I on the right track?

and also why is it that it is $\mathrm{rank}(A+B) \leq \mathrm{rank}k(B)$ and not just $\mathrm{rank}(A+B) =\mathrm{rank}(B)$?

Appreciate your help and thanks!
 A: Hint 1: Show that the column space $C(A+B)$ of $A+B$ is contained in $C(A) + C(B)$. Deduce that the rank of $A+B$ (dimension of its column space) is lesser or equal than $\dim(C(A) + C(B)) = \dim C(A) + \dim C(B) - \dim(C(A) \cap C(B))$.
Hint 2: Argue that $C(AB) \subseteq C(A)$ and similarly $C(BA) \subseteq C(B)$. Then use the fact that $A,B$ commute to conclude that $\dim(C(A) \cap C(B)) \geq \dim C(AB)$.
A: There are many statements that are incorrect in the original post.
(1) There are many pairs of matrices $A$ and $B$ so that $AB=BA$.  For example, consider the case where $A=B^k$ for some $k$.  Then $AB=B^{k+1}=BA$.
(2) The statement that $\operatorname{rank}(AB)=\operatorname{rank}(A)$ is false.  Consider, for example, the case where $B$ is the zero matrix.  In general, it is true that $\operatorname{rank}(AB)\leq\operatorname{rank}(A)$.
(3) The statement that $\operatorname{rank}(A+B)\leq\operatorname{rank}(B)$ is false.  Consider, for example, where $A=\begin{bmatrix}1&0\\0&0\end{bmatrix}$ and $B=\begin{bmatrix}0&0\\0&1\end{bmatrix}$.  Then $\operatorname{rank}(A+B)=2$ but $\operatorname{rank}(B)=1$.
A: I have seen a proof by using partitioned matrices.

From $$
\begin{bmatrix}
I&I\\
O&I
\end{bmatrix}
\begin{bmatrix}
A&\\
&B
\end{bmatrix}
\begin{bmatrix}
I&-B\\
I&A
\end{bmatrix}
=
\begin{bmatrix}
A+B&-AB+BA\\
B&BA
\end{bmatrix}
=\begin{bmatrix}
A+B&O\\
B&AB
\end{bmatrix}
$$
we know
$$
r(A)+r(B)\geq r(LHS)=r(RHS) \geq r(A+B)+r(AB)
$$
in which $r(\cdot)$ represents rank of matrix.

I think it's actually an elegant proof but I have no idea or reasonable explanation about where the inspiration comes from. Up to now, I think the proof of using theory of linear space is more acceptable.
