Here's a proof of the identity 1 2 + 2 2 + 3 2 + . . . + n 2 = n ( n + 1 ) ( 2 n + 1 ) 6 1^{2} + 2^{2} + 3^{2} + . . . + n^{2} = \frac{n(n+1)(2n+1)}{6} 12+22+32+...+n2=6n(n+1)(2n+1)​

Geometric Intuition

Think of it as stacking squares on top of each other to make a staircase/pyramid. Here's what the cross section looks like:

Each layer is a horizontal cross section of that staircase. Our goal is to find a formula to sum up all of the balls.

In our case of n = 4 n = 4 n=4, we can sum it up like this:

There are seven balls on the "first step" of our first layer. Here's what I mean:

That's (1) times (7) = 7 balls

Now, for the "second step" in our staircase, we have to take into consideration the balls from the base layer and the layer above that.

Now that's (2) times (5) = 10 balls

For the third step, we have to take into consideration the balls from the first, second and third layer.

That's (3) times (3)

The full sum looks like this: ( 1 ) ( 7 ) + ( 2 ) ( 5 ) + ( 3 ) ( 3 ) + ( 4 ) ( 1 ) (1)(7) + (2)(5) + (3)(3) + (4)(1) (1)(7)+(2)(5)+(3)(3)+(4)(1)

If you plug in 4 to the formula, it agrees with this sum, which is 30 \boxed{30} 30​.

Now we see a pattern.

For the first term, it's 1 ⋅ ( 2 ( 4 ) − 1 ) 1 \cdot (2(4) - 1) 1⋅(2(4)−1)

For the second term, it's 2 ⋅ ( 2 ( 4 ) − 3 ) 2 \cdot (2(4) - 3) 2⋅(2(4)−3)

For the i i ith term, it's ( i ) ( 2 n − 2 i + 1 ) (i)(2n - 2i+1) (i)(2n−2i+1)

Play around with it and plug some numbers in, and you will see that this is the case.

This agrees with the theorem that the sum of consecutive odd numbers is a perfect square. Here's a diagram to refresh your memory:

Algebraic Manipulation

We have

∑ k = 1 n k 2 = ( 1 ) ( 2 n − 1 ) + ( 2 ) ( 2 n − 3 ) + ( 3 ) ( 2 n − 5 ) . . . ( n ) ( 1 ) \displaystyle \sum_{k=1}^{n} k^2 = (1)(2n - 1) + (2)(2n - 3) + (3)(2n - 5) . . . (n)(1) k=1∑n​k2=(1)(2n−1)+(2)(2n−3)+(3)(2n−5)...(n)(1)

which can be represented as

∑ k = 1 n k 2 = ∑ k = 1 n ( k ) ( 2 n − 2 k + 1 ) \displaystyle \sum_{k=1}^{n} k^2 = \sum_{k=1}^{n} (k)(2n - 2k + 1) k=1∑n​k2=k=1∑n​(k)(2n−2k+1)

Algebra magic

∑ k = 1 n ( 2 n k − 2 k 2 + k ) = ∑ k = 1 n k 2 \displaystyle \sum_{k=1}^{n} (2nk - 2k^2 + k) = \displaystyle \sum_{k=1}^{n} k^2 k=1∑n​(2nk−2k2+k)=k=1∑n​k2

3 ∑ k = 1 n k 2 = ∑ k = 1 n ( 2 n k + k ) 3\displaystyle \sum_{k=1}^{n} k^2 = \displaystyle \sum_{k=1}^{n} (2nk + k) 3k=1∑n​k2=k=1∑n​(2nk+k)

We know that ∑ k = 1 n = n ( n + 1 ) 2 \boxed{\displaystyle \sum_{k=1}^{n} = \frac{n(n+1)}{2}} k=1∑n​=2n(n+1)​​

3 ∑ k = 1 n k 2 = 2 n ⋅ n ( n + 1 ) 2 + n ( n + 1 ) 2 3\displaystyle \sum_{k=1}^{n} k^2 = \frac{2n \cdot n(n+1)}{2} + \frac{n(n+1)}{2} 3k=1∑n​k2=22n⋅n(n+1)​+2n(n+1)​

Therefore:

∑ k = 1 n k 2 = ( 2 n + 1 ) n ( n + 1 ) 6 = n ( n + 1 ) ( 2 n + 1 ) 6 \displaystyle \sum_{k=1}^{n} k^2 = \frac{(2n+1)n(n+1)}{6} = \frac{n(n+1)(2n+1)}{6} k=1∑n​k2=6(2n+1)n(n+1)​=6n(n+1)(2n+1)​

QED :-)