Let A be a square matrix of order n. Prove that if $A^2 = A$, then $\operatorname{rank}(A) + \operatorname{rank}(I - A) = n$. $A(I-A) = 0\implies\operatorname{rank}(A) + \operatorname{rank}(I-A)\le n$. 
I managed to get this but wasn't able to go further. Any help would be appreciated.
 A: Let $x\in \Bbb R^n$ then
$$x=Ax+(x-Ax)\in \operatorname{Im}A+\operatorname{Im}(I-A)$$
and then let $y\in \operatorname{Im}A\cap \operatorname{Im}(I-A)$ so $y=Ax=z-Az$ for some $x,z\in \Bbb R^n$ so applying $A$ we get
$$y=Ax=A^2x=Az-A^2z=Az-Az=0$$
so
$$\operatorname{Im}A\cap \operatorname{Im}(I-A)=\{0\}$$
hence we get
$$\Bbb R^n=\operatorname{Im}A\oplus \operatorname{Im}(I-A)$$
and the result follows by taking the dimension.
A: $dim(kerA) +rank A =n$, $A(I-A) =0$ implies $rank(I-A)\leq dim(kerA)$
A: $A^2=A$, thus $A$'s minimal polynomial must divide $x(x-1)$, which indicates:
1). $A$'s all possible eigenvalues are $1,0$. 
2). $A$ is diagonalizable. That's to say, exists invertible $P$ such that 
$$A=P\text{diag}(1,1,\cdots,1,0,0,\cdots,0)P^{-1}=P\Lambda P^{-1}$$
Note that 
$$\text{rank}A=\text{rank}\Lambda$$ 
And that
$$\text{rank}(I-A)=\text{rank}(P(I-A)P^{-1})=\text{rank}(I-\Lambda)$$
Can you take it from here?
A: As you have proved $\operatorname{rank}(A) + \operatorname{rank}(I-A)\le n$, the opposite inequality comes from the subadditivity of rank
$$
n=\operatorname{rank}(I)=\operatorname{rank}(A+I-A)\le\operatorname{rank}(A) + \operatorname{rank}(I-A).
$$
