<s>[INST] 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?
 [/INST] Firstly, calculate the sum $S=\sum_{k=1}^n k(k+1)$ which is: 
$S=1\cdot 2+2\cdot 3+ \cdots +n(n+1)$, 
multiplying $S$ by 3 
we get:
$3S=1\cdot 2\cdot 3+2\cdot 3\cdot (4-1)+3\cdot 4\cdot (5-2)+ \cdots +n\cdot (n+1)\cdot (n+2-(n-1))$
$3S=1 · 2 · 3 + 2 · 3 · 4 − 1 · 2 · 3 + 3 · 4 · 5 − 2 · 3 · 4 + · · ·
+ n(n + 1)(n + 2) − (n − 1)n(n + 1)$
This telescoping series collapses to yield:
$$3S=n(n+1)(n+2)$$
$$S=\frac{n(n+1)(n+2)}{3}$$
On the other side we have:
\begin{alignat*}{2}
&\sum_{k=1}^n k(k+1)&&=\sum_{k=1}^n k^2+k \\
                   & &&=\sum_{k=1}^n k^2+\sum_{k=1}^n k \\
&\frac{n(n+1)(n+2)}{3}&&=\sum_{k=1}^n k^2+\frac{n(n+1)}{2} \\
&\sum_{k=1}^n k^2&&=\frac{n(n+1)(n+2)}{3}-\frac{n(n+1)}{2}  \\
&\sum_{k=1}^n k^2&&=\frac{n(n+1)(2n+1)}{6}
\end{alignat*}
</s>