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 take, similar to Euler's (?) proof given by @leonbloy. We know that if:
$\begin{align}
   A(z)
     &= \sum_{n \ge 0} a_n z^n
\end{align}$
then (writing $\mathtt{D}$ for the derivative):
$\begin{align}
  z \mathtt{D} A(z)
    &= \sum_{n \ge 0} n a_n z^n
\end{align}$
Also:
$\begin{align}
  \frac{A(z)}{1 - z}
    &= \sum_{n \ge 0} \left( \sum_{0 \le k \le n} a_n \right) z^n \\
  \frac{1}{1 - z}
    &= \sum_{n \ge 0} z^n
\end{align}$
This you can repeat and combine. In our case, we get that:
$\begin{align}
   \sum_{n \ge 0} n^2
     &= (z \mathtt{D})^2 \frac{1}{1 - z} \\
     &= \frac{z + z^2}{(1 - z)^3} \\
   \sum_{n \ge 0} \left( \sum_{0 \le k \le n} k^2 \right) z^n
     &= \frac{z + z^2}{(1 - z)^4}
\end{align}$
We are interested in the coefficient of $z^n$:
$\begin{align}
  [z^n] \frac{z + z^2}{(1 - z)^4}
    &= [z^n] \frac{z}{(1 - z)^4} + [z^n] \frac{z^2}{(1 - z)^4} \\
    &= [z^{n - 1}] (1 - z)^{-4} + [z^{n - 2}] (1 - z)^{-4} \\
    &= (-1)^{n - 1} \binom{-4}{n - 1} + (-1)^{n - 2} \binom{-4}{n - 2} \\
    &= \binom{n - 1 + 4 - 1}{4 - 1} + \binom{n - 2 + 4 - 1}{4 - 1} \\
    &= \binom{n + 2}{3} + \binom{n + 1}{3} \\
    &= \frac{(n + 2) (n + 1) n}{3!} + \frac{(n + 1) n (n - 1)}{3!} \\
    &= \frac{(2 n + 1) (n + 1) n}{6}
\end{align}$
This approach is less messy than the cited one (no horrible derivatives and then l'Hôpital thrice).
