Can sandwiching an invertible matrix change the rank or null space? Suppose $M \succ 0$ and we have some matrix $X$ such that rank($X'X) = r$. Then is rank($X'MX ) = r$, and can we relate the null spaces of $X'X$ and $X'MX$ in any way?
Since multiplication by an invertible matrix doesn't change the rank of the original matrix, I think the rank is preserved. But I can't seem to directly relate the null spaces, which was my initial attempt at proving this statement.

Hints.

*

*If $X$ is a square matrix, then $\operatorname{rank}(X)=\operatorname{rank}(X'X)$ (why?)

*$\operatorname{Ker}(X)\subset \operatorname{Ker}(X'X)$.

*From 1 and 2 it follows that $\operatorname{Ker}(X)=\operatorname{Ker}(X'X)$.

*$\operatorname{rank}(X)=\operatorname{rank}(X'X)=\operatorname{rank}(X'MX)$.

*$\operatorname{Ker}(X)\subset \operatorname{Ker}(X'MX)$.

*It follows from 4 and 5 that $\operatorname{Ker}(X)=\operatorname{Ker}(X'MX)$.

*Thus $\operatorname{Ker}(X'X)=\operatorname{Ker}(X'MX)$.

Addition.
Here's a simple reasoning proving equality of ranks.
If $X$ is a diagonal matrix, the equality $\operatorname{rank}(X)=\operatorname{rank}(X'X)$ is obvious. Let $S$ be a non-singular matrix such that $XS$ is diagonal
(you certainly know how to find $S$).
We get
$$
\operatorname{rank}(X'X)
=\operatorname{rank}(S'X'XS)
=\operatorname{rank}(XS)'(XS)
=\operatorname{rank}(XS)
=\operatorname{rank}(X).
$$
In a similar way we can also prove
$$
\operatorname{rank}(X)=\operatorname{rank}(X'MX)
$$
provided that $M\succ0$.
