Prove that if $X=n\times k$ matrix of rank $k$, then $X(X^TX)^{-1}X^T$ has rank $k$
I thought that $X^TX$ would be a full rank matrix of rank $k$, since it must have full rank to be invertable.
Then $X$ multiplied by $(k\times k)$ matrix, will be a matrix of rank $\min{k,n}$. Then multiply this by a matrix of rank $k$ we get $k$ as the total rank.
Is there a rule that says: if $A$ and $B$ have rank $k$ then so does $AB$ and $BA$?