prove the similar matrices have the same rank
Similar matrices have the same rank.
Proof:
Part (1): We will show that rank$(AB)$=rank$(B)$ if $A$ is invertible.
Take some $U \in \text{ker}(B)$. Then, $BU=0$, so $(AB)U=A(BU)=A0 = 0$. Thus, $U\in \text{ker}(AB)$, so $\text{ker}(B) \subseteq \text{ker}(AB)$.
Conversely, for some $U \in \text{ker}(AB)$, $(AB)U=0$, so $A(BU)=0$. Thus $BU=A^{-1}0=0$, so $U \in \text{ker}(B)$. Therefore, $\text{ker}(AB)= \text{ker}(B)$, implies nullity(AB)=nullity(B), implies rank(AB)=rank(B), provided that A is nonsingular.
Part (2): Show that: rank$(AB)$=rank$(A)$, if B is invertible. rank$(AB)$=rank$((AB)^{t})$=rank$(B^{t}A^{t})$=rank$(A^{t})$=rank$(A)$, since $B^{t}$ is nonsingular.
Thus, similar matrices have the same rank. We have rank(XB)=rank(B) and rank(AX)=rank(A) and $X^{-1}AX=B$ implies $AX=XB$. Therefore, rank(A)=rank(B).
By definition, $A\sim B$ iff there exists an invertible matrix $C$ such that $A=CBC^{-1}$ (and hence $AC=CB$). If $v$ is in the image of $B$, say $v=Bw$, then $Cv=CBW=ACw$ is in the image of $A$. Thus $C$ maps $\operatorname{Im}(B)\to \operatorname{Im}(A)$. As $C$ is injective, we conclude $\operatorname{rank}(A)\ge \operatorname{rank}(B)$. By symmetry, also $\operatorname{rank}(B)\ge \operatorname{rank}(A)$.