# Variance expanded equation?

Per Wikipedia, this is what happens when you expand the variance equation:

$\ Var(X)=E[X-E[X])^2$ $=E[X^2 -2XE[X] + (E[X]))^2$ $=E[X^2] - 2E[X]E[X] + (E[X]))^2$

How do we get the $\ 2E[X]E[X]$ term?

\begin{align} \text{Var}(X)&=E\Big[\big(X-E[X]\big)^{2}\Big]\\ &=E\Big[X^{2}-2XE[X]+\big(E[X]\big)^{2}\Big]\\ &=E\big[X^{2}\big]-2E\big[XE[X]\big]+E\Big[\big(E[X]\big)^{2}\Big]\\ &\overset{*}{=}E\big[X^{2}\big]-2E\big[XE[X]\big]+\big(E[X]\big)^{2}\\ &\overset{**}{=}E\big[X^{2}\big]-2E[X]E[X]+\big(E[X]\big)^{2}\\ &=E\big[X^{2}\big]-2\big(E[X]\big)^{2}+\big(E[X]\big)^{2}\\ &=E\big[X^{2}\big]-\big(E[X]\big)^{2} \end{align}
$^{*}$Because $\big(E[X]\big)^{2}$ is a constant, so taking the expectation of $\big(E[X]\big)^{2}$ just gives the constant.
$^{**}$Because $E[X]$ is a constant, so taking the expectation of $E[X]$ just gives the constant.
It's from linearity of expectation and the fact that $E[X]$ is constant. I'll let $E[X]=c$ at some steps for clarity. \begin{align*} Var(X) &= E[ (X- E[X])^2] \\ &= E[ X^2 - 2X E[X] + (E[X])^2] \\ &= E[X^2] - E[2X E[X]] + E[(E[X])^2] \\ &= E[X^2] - E[2X c] + E[c^2] \\ &= E[X^2] - 2c E[X] + c^2 \\ &= E[X^2] - 2(E[X])^2 + (E[X])^2 \\ &= E[X^2] - (E[X])^2. \end{align*}