I found few different formulas to calculate variance from different resources. I have searched the internet for quite a bit already and cannot understand why are they different.
1) $D(x) = \frac{\sum x_i^2}{n}-\bar{x}^2$
2) $\sigma^2=\frac{\sum x^2 - \frac{\left(\sum X\right)^2}{N}}{N}$
I found the second at Wikipedia:
$$\bar{S}^2=\frac{\sum_{i=1}^n x_i^2-\frac{\left( \sum_{i=1}^n x_i\right)^2}{n}}{n}=\frac{\sum_{i=1}^n x_i^2-n \bar{x}^2}{n}=\frac{\sum_{i=1}^n(x_i^2-\bar{x}^2}{n}$$
But there is no transition to the first formula I have found. Is there a mistake in the first formula which is the missing $\frac1n$? Or I don't understand something?
A formula can be written in different form and yet they represent the same thing.
To show the first formula is equivalent to the second formula:
\begin{align} \frac{\sum x_i^2}{n}-\bar{x}^2 &= \frac{\sum x_i^2}{n}-\left(\frac{\sum x_i}{n} \right)^2\\ &=\frac1n \left(\sum x_i^2 - \frac{\left(\sum x_i \right)^2}{n} \right) \end{align}
where in the last equality, I have pull out the common factor of $\frac1n$.
Also note that $\bar{X}$ does not depend on index $i$, hence
\begin{align}\sum_{i=1}^n (x_i^2-\bar{x}^2)&=\sum_{i=1}^n x_i^2 - \sum_{i=1}^n\bar{x}^2 \\ &=\sum_{i=1}^n x_i^2 - \bar{x}^2 \sum_{i=1}^n 1\\ &=\sum_{i=1}^n x_i^2 - n\bar{x}^2 \end{align}