Sum of First $n$ Squares Equals $\frac{n(n+1)(2n+1)}{6}$ I am just starting into calculus and I have a question about the following statement I encountered while learning about definite integrals:

$$\sum_{k=1}^n k^2 = \frac{n(n+1)(2n+1)}{6}$$

I really have no idea why this statement is true. Can someone please explain why this is true and if possible show how to arrive at one given the other?
Another way (by Euler, I think), from the geometric sum: 

$$1 + x + x^2 + \cdots + x^n = \frac{x^{n+1}-1}{x-1} \tag{1}$$

Differentiate both sides and multiply by $x$:

$$x + 2 x^2 + 3 x^3 + \cdots + n x^{n} = \frac{n x^{n+2}-(n+1) x^{n+1} +x}{(x-1)^2} \tag{2}$$

Differentiating once more, we get on the LHS

$$1 + 2^2 x + 3^2 x^2 + \cdots + n^2 x^{n-1} \tag{3}$$

which, evaluated at $x=1$ gives our desired sum $\sum_{k=1}^n k^2$. Hence, we just need to compute the derivative on the RHS in $(2)$ (eg, with L'Hopital rule) and evaluate it at $x \to 1$.

It should be evident that this procedure also can be applied (though it also turns more cumbersome) for sums of higher powers.



(Update) here's a concrete computation, applying the binomial theorem on the RHS of $(1)$ and doing a series expansion around $x=1$. Let

$$\begin{align}
g(x)&amp;=\frac{x^{n+1}-1}{x-1}\\
&amp;=\frac{\left(1+(x-1)\right)^{n+1}-1}{x-1}\\
&amp;={n+1 \choose 1}+{n+1 \choose 2}(x-1)+{n+1 \choose 3}(x-1)^2+O\left((x-1)^3\right) \tag{4}
\end{align}$$

Deriving, multiplying by $x$ and deriving again: $$(g'(x) \, x)'={n+1 \choose 2}+{n+1 \choose 3}2 \, x + O(x-1) \tag{5}$$
which evaluated at $x=1$ gives the desired answer:
$${n+1 \choose 2}+2{n+1 \choose 3} =\frac{n(n+1)(2n+1)}{6}  $$

We can apply the same procedure for higher powers. For example:
$$ \sum_{k=1}^n k^3={n+1 \choose 2}+{n+1 \choose 3}6+{n+1 \choose 4}6$$
Another method by using telescoping sum :-
 We know $(a+b)^3-a^3-b^3=3ab(a+b)$ , take 

$a=k-1 , b=2$ , then $a+b=k+1$ and $(k+1)^3-(k-1)^3-2^3=6(k-1)(k+1)=6k^2-6$ , 

hence $(k+1)^3-(k-1)^3-8+6=(k+1)^3-k^3+k^3-(k-1)^3-2=6k^2$ , taking sum over $k$ 

from $1$ to $n$ we get , $\sum_{k=1}^n [(k+1)^3-k^3] + \sum_{k=1}^n [k^3-(k-1)^3] -\sum_{k=1}^n 2 = 6 \sum_{k=1}^nk^2$ , the first 

sum on the left hand side is telescoping resulting in $(n+1)^3-1$ , the second sum is also telescoping resulting in $n^3-(1-1)^3=n^3$ , and the third sum is simply $2n$ , hence 

$6 \sum_{k=1}^nk^2=(n+1)^3-1+n^3-2n=2n^3+3n^2+n=n(n+1)(2n+1)$