# Rank and trace are equal for a real symmetric idempotent matrix

Proposition. Let $\mathbf{X} \in \mathbb{R}^{n \times n}$ be a matrix that is symmetric ( $\mathbf{X}^\top = \mathbf{X}$) and idempotent ( $\mathbf{X}^2 = \mathbf{X}$). Then the rank of $\mathbf{X}$ is equal to the trace of $\mathbf{X}$. In fact, they are both equal to the sum of the eigenvalues of $\mathbf{X}$.

The proof is relatively straightforward. Since $\mathbf{X}$ is real and symmetric, it is orthogonally diagonalizable, i.e. there is an orthogonal matrix $\mathbf{U}$ ( $\mathbf{U}^\top \mathbf{U} = \mathbf{I}$) and a diagonal matrix $\mathbf{D}$ such that $\mathbf{D} = \mathbf{UXU}^\top$ (see here for proof).

Since $\mathbf{X}$ is idempotent, \begin{aligned} \mathbf{X}^2 &= \mathbf{X}, \\ \mathbf{U}^\top \mathbf{D}^2 \mathbf{U} &= \mathbf{U}^T \mathbf{DU}, \\ \mathbf{D}^2 &= \mathbf{D}. \end{aligned}

Since $\mathbf{D}$ is a diagonal matrix, it implies that the entries on the diagonal must be zeros or ones. Thus, the number of ones on the diagonal (which is $\text{rank}(\mathbf{D}) = \text{rank}(\mathbf{X})$) is equal to the sum of the diagonal (which is $\text{tr}(\mathbf{D}) = \text{tr}(\mathbf{X})$).