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?

$\begin{aligned} & \hspace{0.5in} \begin{aligned}\displaystyle \sum_{1 \le k \le n}k^2 & = \sum_{1 \le k \le n}~\sum_{1 \le r \le k}r =\sum_{1 \le r \le n}~\sum_{r \le k \le n}r \\& = \sum_{1 \le r \le n}~\sum_{1 \le k \le n}r-\sum_{1 \le r \le n}~\sum_{1 \le k \le r-1}r \\& = n\sum_{1 \le r \le n}r-\frac{1}{2}\sum_{1 \le r \le n}r(r-1) \\& =\frac{1}{2}n^2(n+1)-\frac{1}{2}\sum_{1 \le r \le n}r^2+\frac{1}{2}\sum_{1 \le r \le n}r \\& =\frac{1}{2}n^2(n+1)-\frac{1}{2}\sum_{1 \le k \le n}k^2+\frac{1}{4}n(n+1) \end{aligned} \\& \begin{aligned}\implies\frac{3}{2}\sum_{1 \le k \le n}k^2 & =   \frac{1}{2}n^2(n+1)+\frac{1}{4}n(n+1) \\& = \frac{1}{4}n(n+1)(2n+1) \end{aligned}\\& \implies \hspace{0.15in} \displaystyle \sum_{1 \le k \le n}k^2 = \frac{1}{6}n(n+1)(2n+1).\end{aligned}$
