Deriving the variance of the Bernoulli distribution For a Bernoulli distribution, $\mu_X = p$. I can easily derive this from the general equation for mean of a discrete random variable:
$$
\mu_X=\sum_{i=1}^kx_iPr(X=x)
$$
$$
\mu_X=1(p)+0(1-p)=p
$$
I know that the variance of the Bernoulli distribution is supposed to be $\sigma_x^2=p(1-p)$. But I can not seem to derive that properly from the general equation for variance of a discrete random variable:
$$
\sigma_x^2=\sum_{i=1}^k(x_i-\mu_X)Pr(X=x_i)
$$
$$
\sigma_x^2=(x_0-p)(1-p)+(x_1-p)(p)
$$
$$
\sigma_x^2=(0-p)(1-p)+(1-p)(p)
$$
$$
\sigma_x^2=-p(1-p)+(1-p)(p)
$$
$$
\sigma_x^2=-p+p^2+p-p^2
$$
$$
\sigma_x^2=0
$$
This is obviously incorrect; what am I doing incorrectly in my derivation?

By definition, 
$$Var(X)=E(X^2)-E(X)^2%$$
Consider a success being a $1$ and a failure being a $0$. 
Then we have
$$\begin{align*}
Var(X)
&=\sum_{x=0}^1(x^2)Pr(X=x)-\left(\sum_{x=0}^1(x)Pr(X=x)\right)^2\\\\
&=\left(1^2\cdot p + 0^2 (1-p)\right)-\left(1 \cdot p + 0 (1-p)\right)^2\\\\
&=p-p^2\\\\
&=p(1-p)
\end{align*}$$
