How to rearrange exponent terms in a Gaussian likelihood? 
I'm working out of the textbook "Bayesian Data Analysis for the Behavioral and Neural Sciences" by Todd Hudson, and on p. 105 (above) we see the preceding explanation for a Gaussian likelihood, leading to an expression proportional to
$$\left(\sigma\sqrt{2\pi}\right)^{-n}\, \exp\left(-\frac{\sum_i\left(x_i - \mu\right)^2}{2\sigma^2}\right)\ \propto\ \sigma^{-n}\,\exp\left({-\frac{n}{2} \frac{\overline{x^2}-{\bar x}^2}{\sigma^2}}\right)\ \exp\left({-\frac{n}{2} \frac{(\bar x - \mu)^2}{\sigma^2}}\right).$$
I understand why we take the products of each datum (independent samples) and how that leads to the summation in the exponent of the last line. However, how do we go  from summing the squared errors (on the left-hand side of the proportionality symbol) to the two exponents on the right-hand side of the proportionality symbol (i.e., $\overline{x^2}-{\bar x}^2$ and $(\bar x - \mu)^2$)?
Intuitively, I can see we have the sample variance in one and the squared distance between the sample mean and the hypothesized mean ($\mu$) of the distribution in the other exponent. But what are the actual steps involved in breaking down the summation into these two separate parts?
Any help explaining the mechanics of this is much appreciated.

Subtract and add $n(\bar x)^2$ after expanding the left hand side:
$$\begin{aligned}
\sum_{i=1}^n (x_i-\mu)^2 &= \sum_{i=1}^n x_i^2 - 2\mu\sum_{i=1}^n x_i + \sum_{i=1}^n \mu^2 \\
&= n \overline{x^2} - 2\mu n \bar x+n\mu^2 \\
&= n\overline{x^2} \color{Red}{- n(\bar x)^2} + n(\color{Red}{(\bar x)^2} - 2 \mu \bar x + \mu^2)\\
&= n(\overline{x^2} - (\bar x)^2) + n(\bar x-\mu)^2.
\end{aligned}$$
Divide both sides by $2\sigma^2$ and exponentiate to obtain the statement in the question.
Comment 1
Notice that $\mu$ doesn't have any necessary relationship with the $x_i:$ it's any number.  In words, this is best expressed upon dividing all sides by $n:$

The mean squared difference between a batch of data $(x_i)$ and any reference value $\mu$ equals the variance of those data, $\overline {x^2} - (\bar x)^2,$ plus the square of the difference between the reference and the mean of the data.

Comment 2
This is easy to remember once you understand it is the Pythagorean Theorem: in $n$ dimensional Euclidean space, the points $\mathbf x = (x_i),$ $\mathbf{\mu}=(\mu,\mu,\ldots,\mu),$ and $\bar{ \mathbf{x}} = (\bar x,\bar x,\ldots, \bar x)$ form a triangle.  (The latter two lie on the line where all coordinates are equal.)  The right angle is at $\bar{\mathbf x}.$  It is a right angle because the dot product of $\mu - \bar{\mathbf x}$ and $\mathbf x - \bar{\mathbf x}$ is, by definition,
$$(\mu - \bar{\mathbf x}) \cdot (\mathbf x - \bar{\mathbf x}) = (\mu - \bar x)(x_1-\bar x +  x_2-\bar x + \ldots +  x_n - \bar x) = 0.\tag{*}$$
The Pythagorean Theorem says the square of the hypotenuse is the sum of the squares of the legs,
$$||\mathbf x - \mu||^2 = ||\mu - \bar{\mathbf x}||^2 + ||\mathbf x - \bar{\mathbf x}||^2.$$
That's just another (standard) notation for the result.  Thus, if you know the Pythagorean Theorem, $(*)$ constitutes another proof.  That relation (of perpendicularity) is known as the Normal Equations.  ("Normal" vectors are perpendicular ones.)
