<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] Notice that $(k+1)^3 - k^3 = 3k^2 + 3k + 1$ and hence
$$(n+1)^3 = \sum_{k=0}^n \left[ (k+1)^3 - k^3\right] = 3\sum_{k=0}^n k^2 + 3\sum_{k=0}^n k + \sum_{k=0}^n 1$$
which gives you
$$\begin{align}
\sum_{k=1}^n k^2
& = \frac{1}{3}(n+1)^3 - \frac{1}{2}n(n+1) - \frac{1}{3}(n+1) \\
& = \frac{1}{6}(n+1) \left[ 2(n+1)^2 - 3n - 2\right] \\
& = \frac{1}{6}(n+1)(2n^2 +n) \\
& = \frac{1}{6}n(n+1)(2n+1)
\end{align}$$
</s>