# Normal method of moments derivation explanation of Algebra step

In deriving normal estimators using method of moments, why does the below equality hold?

$$\frac{1}{n} \sum X_i^2 - \bar{X}^2 = \frac{1}{n} \sum (X_i - \bar{X})^2$$

This is from Example 7.2.1 from Casella & Berger in which $X_1, \ldots, X_n$ are iid $\mathcal N(\theta, \sigma^2)$.

Just expand out the right side using FOIL to get \begin{align} \sum_{i=1}^n (X_i - \bar{X})^2 &= \sum_{i=1}^n (X_i^2 - 2X_i\bar{X} + \bar{X}^2)\\ &= \left(\sum_{i=1}^n X_i^2\right) -2\bar{X}\left(\sum_{i=1}^n X_i\right) + n\bar{X}^2\\ &= \left(\sum_{i=1}^n X_i^2\right) - 2\bar{X}\cdot n \bar{X} + n\bar{X}^2\\ &= \left(\sum_{i=1}^n X_i^2\right) - n\bar{X}^2 \end{align}