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?

A natural approach for this kind of problems when you don't know the result is to proceed as follows :
We may want to write the sum $\sum_{k=1}^n k^2$ as a telescopic sum, so we will try to find a polynomial of degree 3 ( why ? ) $P$ so that $P\left( k+1 \right) - P\left(k\right)=k^2$. Let $P\left( x \right) = ax^3+bx^2+cx$ for all reals $x$, then our constraint becomes :
$k^2= a\left( \left(k+1\right)^3 - k^3 \right) + b\left( \left(k+1\right)^2 - k^2 \right) + c$
Which after expanding and rearranging becomes :
$k^2 = 3ak^2 + \left( 3a+2b \right)k + a+b+c$
But we know that two polynomials are equal iff their coefficients are equal too, so we just need to solve this system :
$\left\{ \begin{aligned}
a &= \frac{1}{3} \\
3a+2b &= 0 \\
a+b+c &= 0
\end{aligned} \right.$
Which gives us $\left( a,b,c \right) = \left( \frac{1}{3}, \frac{-1}{2}, \frac{1}{6} \right)$
And Voilà, we just found the coefficients of our polynomial ! Now we just have to evaluate our telescopic sum :
$\sum_{k=1}^n k^2 = \sum_{k=1}^n P\left( k+1 \right) - P\left(k\right) = P\left(n+1\right)-\underbrace{P\left(1\right)}_{=0}$
$\sum_{k=1}^n k^2 = \frac{1}{3}\left(n+1\right)^3 - \frac{1}{2}\left(n+1\right)^2+\frac{1}{6}\left(n+1\right)$
$\sum_{k=1}^n k^2 = \frac{1}{6}\left(n+1\right)\left( 2 \left(n+1\right)^2 - 3 \left(n+1 \right) + 1 \right)$
$\sum_{k=1}^n k^2 = \frac{1}{6}\left(n+1\right)\left( 2n^2+n \right)$
$\sum_{k=1}^n k^2 = \frac{1}{6}n\left(n+1\right)\left(2n+1\right)$
Which completes the proof :-)
