Deriving the variance of a binomial distribution I know that the variance of a binomial distribution is the number of trials multiplied by the variance of each trial, but I'm not seeing the derivation of this. Here's my logic so far:
For each trial ($x$),
$p$ = probability of success (1), and
$1-p$ = probability of failure (0):
$$E(x) = 1\cdot p+0\cdot(1-p) = p$$
$$E(x^2) = 1^2\cdot p+0^2\cdot(1-p) = p$$
$$Var(x) = E(x^2)-E(x)^2 = p - p^2 = p(1-p)$$
From here, for any combination of trials ($X$):
$$X = x_1 + x_2 + \cdots + x_n$$
$$E(X) = E(x_1) + E(x_2) + \cdots + E(x_n)$$
$$E(X) = np$$
$$E(X^2) = E(x_1^2) + E(x_2^2) + \cdots + E(x_n^2)$$
$$E(X^2) = np$$
By this, the logic indicates the variance would be:
$$Var(X) = E(X^2) - E(X)^2 = np - (np)^2 = np(1-np)$$
...however, this is not correct, since the variance is as follows:
$$Var(X) = Var(x_1) + Var(x_2) + \cdots + Var(x_n)$$
$$Var(X) = p(1-p) + p(1-p) + \cdots + p(1-p)$$
$$Var(X) = np(1-p)$$
I'm not seeing in my derivation where I'm missing the mark mathematically, and resulting in the incorrect "n" in the parentheses.
 A: $E [X_i X_j] = p^2$. ${}{}{}{}{}{}{}{}{}$
So $E X^2 = \sum_{i=1}^n E X_i^2 + \sum_{i \neq j} E[X_i X_j] = np +(n^2-n)p^2$, and
so $\operatorname{var} X = np(1-p)$.
A: Your computation of $\mathbb{E}[X^2]$ is incorrect. In particular, 
$$
\mathbb{E}[X^2] \neq \mathbb{E}[X_1^2] + \dots + \mathbb{E}[X_n^2]
$$
since $\mathbb{E}[X^2] = \mathbb{E}[(X_1+\dots+X_n)^2]$.
A: To extend your line of thought, $X=X_2 + X_2 + X_3 + \cdots + X_n$ be the random variable that denotes the number of successes in $n$ Bernoulli trials. As you correctly state, all the $X_i $ s are indicator variables that 'indicate' whether success/failure occurs in the $i^{th} $ trial. 
Clearly, $E[X_i]=p$ and $E[X_i ^2]=p$
Now $X=X_1 + X_2 + \cdots + X_n$
Squaring both sides, we have
$$X^2 = \{X_1 ^2 + X_2 ^2 + \cdots + X_n ^2\} + 2{n\choose k}\sum_{i \neq j}(X_I X_J) $$
This is the important bit that you were missing. 
Now you can evaluate expectation of $X^2$ by using the linearity of expectations property and the fact that for two independent random variables $X,Y$ we have $E[XY]=E[X]E[Y]$
For completeness, 
$$ \Rightarrow E[X^2]=nE[X_i ^2] + n(n-1)E[X_i]E[X_i]$$
$$ \Rightarrow E[X^2]=np + n(n-1)p^2 $$
$$ \Rightarrow \sigma ^2(X)=E[X^2] - (E[X])^2$$
$$ \Rightarrow \sigma^2(X)=np+n(n-1)p^2 -(np)^2$$
$$ \Rightarrow \sigma^2(X)=np-np^2=np(1-p) $$
