$\mathrm{rank}(A)+\mathrm{rank}(I-A)=n$ for $A$ idempotent matrix

Let $A$ be a square matrix of order $n$. Prove that if $A^2=A$ then $\mathrm{rank}(A)+\mathrm{rank}(I-A)=n$.

I tried to bring the $A$ over to the left hand side and factorise it out, but do not know how to proceed. please help.


Solution 1:

Hint. Show that under the given condition, the following holds:

$$\ker A = \operatorname{im} (I -A) $$