# LRT of normal distribution - explanation of numerator

Let $X_1,...,X_n$ be random sample of $X$~$N(\mu,\sigma^2)$ with known $\sigma^2$. I am trying to derive test statistic for that distribution

I know that $\hat{\mu}=\overline{X}$

$$\lambda(x)=\frac{\sup_{\Theta_0}L(\theta|x)}{\sup_{\Theta}L(\theta|x)}=\frac{(2\pi)^\frac{-n}{2}(\sigma^2)^{\frac{-n}{2}}e^{-\frac{1}{2\sigma^2}\sum (x_i-\mu_0)^2}}{(2\pi)^\frac{-n}{2}(\sigma^2)^{\frac{-n}{2}}e^{-\frac{1}{2\sigma^2}\sum (x_i-\overline{x})^2}}$$

Which results in

$$\lambda(x)=e^{-\frac{n}{2\sigma^2}(\overline{x}-\mu_0)^2}$$

So my question now is. How to transform numerators exponent from $$\sum(x_i-\mu_0)^2$$ to $$\sum(x_i-\overline{x})^2+n(\overline{x}-\mu_0)^2$$

Whith results in:

$$\sum(x_i-\mu_0)^2 = \sum(x_i-\overline{x})^2+n(\overline{x}-\mu_0)^2$$

It is clearly some product of two exponential functions, but I don't understand it.

$$\begin{eqnarray} \sum(x_i-\mu)^2 &=& \sum(x_i-\bar{x}+\bar{x}-\mu)^2 \\ &=&\sum(x_i-\bar{x})^2 + \sum(\bar{x}-\mu)^2+2\sum(x_i-\bar{x})(\bar{x}-\mu) \\ &=& \sum(x_i-\bar{x})^2 + \sum(\bar{x}-\mu)^2 + 2(\bar{x}-\mu)\sum(x_i-\bar{x})\\ &=& \sum(x_i-\bar{x})^2 + \sum(\bar{x}-\mu)^2 \\ &=& \sum(x_i-\bar{x})^2 + n(\bar{x}-\mu)^2 \end{eqnarray}$$ as $\sum(x_i-\bar{x}) = \sum x_i - \sum\bar{x} = \sum x_i - n\bar{x} = \sum x_i - \sum x_i = 0$.