$\mathbf {The \ Problem \ is}:$ If $A$ and $B$ be two $n\times n$ square matrix such that $A^2=A$ and $B^2=B,$ then show that $r(A-B)=r(A-AB)+r(AB-B)$ where $r(A)$ denotes rank of the square matrix $A.$
$\mathbf {My \ approach} :$ Actually I have tried that, from the two equations, $A(A-B)=(A-AB)$ and $(A-B)B=(AB-B)$, we have $r(A-AB)+r(AB-B) \leq r(A)+r(B)$ and again $A(AB-B)=0$ and $(A-AB)B=0$, then $r(A)+r(AB-B)\leq n$ and $r(B)+(A-AB)B\leq n$, but I can't draw any further conclusion to show that $r(A-AB)+r(AB-B) \leq r(A-B)$ .
And the other side is obvious by the rank-inequality $r(P+Q)\leq r(P)+r(Q).$
A small hint is warmly appreciated .
We want to show that $$ r(A-B) = r(A - AB) + r(AB - B). $$
By the claim proven below, it suffices to show that $A - AB$, $AB - B$ have trivially intersecting row-spaces and trivially intersecting kernels.
To show that the row-spaces intersect trivially, note that $$ \operatorname{im}(A - AB)^T = \operatorname{im}((I - B)^TA^T) \subset \operatorname{im}(I-B)^T,\\ \operatorname{im}(AB - B)^T = \operatorname{im}(B^T(I - A^T)) \subset \operatorname{im}(B)^T.\\ $$ However, we have $\operatorname{im}(B)^T \cap \operatorname{im}(I-B)^T = \{0\}$. To see this: if $x$ is in the first space, then $(I - B^T)x = 0$ which means that $B^Tx = x$. If $x$ is in the second space, then $B^Tx = 0$. For both to be true, we must have $x = 0$.
We now show that the kernels intersect trivially. Suppose that $x \in \ker(A-B)$, i.e. $(A-B)x = 0$. This can be rewritten as $$ (A - B)x = 0 \implies Ax - Bx = 0 \implies Ax = Bx. $$ It follows that $$ (A - AB)x = Ax - A(Bx) = Ax - A(Ax) = (Ax - A^2)x = 0. $$ Similarly, $$ (AB - B)x = A(Bx) - (Bx) = A(Ax) - (Ax) = (A^2 - A)x = 0. $$ So, $x \in \ker(A-B)$ implies that $x \in \ker(A - AB)$ and $x \in \ker(AB - B)$. The conclusion follows.
Proof: $$ \ker(P + Q) = \ker(P) \cap \ker(Q) \iff\\ \operatorname{im}(P^T + Q^T) = \operatorname{im}(P^T) + \operatorname{im}(Q^T) \iff\\ \dim \operatorname{im}(P^T + Q^T) = \dim \operatorname{im}(P^T) + \dim \operatorname{im}(Q^T) - \dim[\operatorname{im}(P^T) \cap \operatorname{im}(Q^T)] \iff\\ \dim \operatorname{im}(P^T + Q^T) = \dim \operatorname{im}(P^T) + \dim \operatorname{im}(Q^T) \implies\\ r(P + Q) = r(P) + r(Q). $$