# Sum of Squares of First N Integers
$\sum_{n=1}^b n^2 = \frac{b(b+1)(2b+1)}{6}$ ^z1v20k
## Proof by Binomial Expansion
Start with binomial expansion of $(n-1)^3$ [^1]:
$
\begin{gather}
(n-1)^3=n^3-3n^2+3n-1 \\
n^3-(n-1)^3 = 3n^2 -3n + 1
\end{gather}
$
[^1]: Per [[Binomial Theorem]]
We can take the sum of both sides from $n=1$ to $b$ to get:
$\sum_{n=1}^b\left[n^3-(n-1)^3\right] = \sum_{n=1}^b\left[3n^2 -3n + 1\right]$
Lets look at the two sides one by one. The left sum can be expanded like:
$
\begin{gather}
\sum_{n=1}^b\left[n^3-(n-1)^3\right] = \\
1 + \\
2^3-1+ \\
3^3-2^3+ \\
4^3 - 3^3 \\
+\ldots+ \\
b^3-(b-1)^3 \\
=b^3
\end{gather}
$
It is said that this series telescopes: all terms cancel out until the last $b^3$.
The right sum can be simplified as:
$\sum_{n=1}^b\left[3n^2 -3n + 1\right] = 3 \sum_{n=1}^b \left[n^2\right] - 3 \sum_{n=1}^b[n] + b$
When we put the left and right sides together we get:
$
\begin{gather}
b^3 = 3 \sum_{n=1}^b \left[n^2\right] - 3 \sum_{n=1}^b[n] + b \\
3 \sum_{n=1}^b \left[n^2\right] = b^3 + 3 \sum_{n=1}^b[n] - b
\end{gather}
$
[[The Gauss Trick]] tells us the value of $\sum_{n=1}^b n$, so we can simplify
$
\begin{align}
3 \sum_{n=1}^b \left[n^2\right] &= b^3 + 3 \sum_{n=1}^b[n] - b \\
3 \sum_{n=1}^b \left[n^2\right] &= b^3 + 3 \frac{b(b+1)}{2} - b \\
\sum_{n=1}^b \left[n^2\right] &= \frac 1 3 b^3 + \frac{b(b+1)}{2} - \frac 1 3 b \\
&=\frac 1 6[ 2b^3 + 3b(b+1) - 2b] \\
&= \frac 1 6b [2b^2 + 3b+1] \\
&= \frac 1 6 b
(2b+1)(b+1)\end{align}
$