Prove that $\text{rank}(\mathbf{I}-\mathbf{X}(\mathbf{X}^\intercal\mathbf{X})^{-1}\mathbf{X}^\intercal)=n-k-1$, where $\mathbf{X}$ is $n\times k+1$ This is required to show that $\text{SSR}/\sigma^2$ is $\chi^2(n-k-1)$, where SSR is the residual sum of squares $(\mathbf{y}-\mathbf{X}\boldsymbol{\hat{\beta}})^\intercal(\mathbf{y}-\mathbf{X}\boldsymbol{\hat{\beta}}) = \mathbf{y}'(\mathbf{I}-\mathbf{X}(\mathbf{X}^{\intercal}\mathbf{X})^{-1}\mathbf{X}^\intercal)\mathbf{y}$.
My attempt
(Let $\mathbf{H} = \mathbf{X}(\mathbf{X}^{\intercal}\mathbf{X})^{-1}\mathbf{X}^\intercal$)
$\mathbf{I}-\mathbf{H}$ is symmetric and idempotent. Therefore, it has $\text{rank}(\mathbf{I}-\mathbf{H})=r$ eigenvalues equal to 1, and $n-r$ eigenvalues equal to 0. Hence,
$\text{rank}(\mathbf{I}-\mathbf{H}) = \sum_{i=1}^n \lambda_{1i} = n - \sum_{i=1}^n \lambda_{2i}$, where $\lambda_{1i}$ are the eigenvalues of $\mathbf{I}-\mathbf{H}$ and $\lambda_{2i}$ are the eigenvalues of $\mathbf{H}$. But $\mathbf{H}$ is symmetric and idempotent as well, so $\sum_{i=1}^n \lambda_{2i} = \text{rank}(\mathbf{H})$. I could start from $\text{rank}{(\mathbf{X}^\intercal \mathbf{X})^{-1}}= k+1$ and apply some theorem "If $\mathbf{A}$ is $p\times p$ and symmetric of rank $p$ and $\mathbf{B}$ is $n\times p$ of rank $p$ then $\text{rank}(\mathbf{BAB^\intercal}) = p$" to show that $\text{rank}(\mathbf{H})=k+1$ as well, but is there such a theorem? Is there a shorter way?

We know that $H^2 = H \cdot H = H $ and by using this equation we can get
$(I-H)^2 = I-H$ which shows that $(I-H)$ is an idempotent matrix.
By using fact that the rank of idempotent matrix is trace of matrix,
$$
rank(I-H) = tr(I - H) = tr(I - H) = n - (k+1).
$$
