Matrices such that $A^2=A$ and $B^2=B$ Let $A,B$ be two matrices of $M(n,\mathbb{R})$ such that $$A^2=A\quad\text{and}\quad B^2=B$$
Then $A$ and $B$ are similar if and only if $\operatorname{rk}A = \operatorname{rk}B$.
The first implication is pretty easy because the rank is an invariant under matrix similarity. But the second one is kind of baffling me. I thought of reasoning about linear mappings instead of matrices. My reasoning was, basically, that if we consider the matrix as a linear mapping with respect to the canonical basis ($T(v)$ for the matrix $A$, $L(v)$ for the matrix $B$) then we have $$T(T(v))=T(v)\quad\text{and}\quad L(L(v))=L(v)$$
for all $v \in V$. Then the mapping must be either the $0$ function or the identity function (if this was the case, then the rest of the demonstration would be easy). But I soon realised that equating the arguments of the function, in general, doesn't work. 
Thanks in advance for your help.

Your way of thinking is very good.
Hint: If $L:V\to V$ is an idempotent linear transformation ($L^2=L$) then $$V=\ker L\oplus{\rm im\,}L\,.$$

 Use the decomposition $v=(v-Lv)+Lv$.

