Is there a geometric interpretation for lower order terms in sum of squares formula? So we know that $\sum_{k=1}^n k^2 = n(n+1)(2n+1)/6$ and if we think about making a square layer out of $n^2$ unit cubes, and then placing a square layer of $(n-1)^2$ unit cubes on top of the first layer centered upon the center, and so forth, we can build a chunky square pyramid of $\sum_{k=1}^n k^2$ unit cubes that has height $n$ and base side length $n$. As $n$ gets large, we can think of this as a Riemann sum for the volume of an ordinary square pyramid of height $n$ and base side length $n$, which has volume $n^3/3$. And indeed the leading term of $n(n+1)(2n+1)/6$ is $n^3/3$. So I was wondering, does the quadratic (and or linear) term in  $n(n+1)(2n+1)/6$ have any geometric interpretation in terms of the ordinary square pyramid, e.g. being a multiple of surface area of the triangular sides or something?
 A: You want to talk about
$$\frac{n(n+1)(2n+1)}6=\frac{n^3}3+\frac{n^2}2+\frac n6$$
I'd prefer to think of the pyramid layers not as centered on one another, but aligned in one corner of the plane. That way they form a regular integer grid, which makes things a bit easier for me. The layer $k$ is represented by the square $0\le x,y\le k;\;k-1<z<k$, so the $z$ axis is going from the tip towards the base.
Your argument about the pyramid value still holds. The volume covered by the pyramid $0\le x,y\le z\le n$ is equal to $\frac{n^3}3$ since its base is $n^2$ and its height is $n$. But your cubes are protruding beyond that. Let's look at the edges first. In each layer, the outer edge of the square consists of a seried of $k-1$ cubes which are half inside and half outside the volume of the pyramid you have already accounted for. The corner cube is a bit more tricky, so we might want to have a closer look at that later. There are two edges to each layer, so multiplying the volume of $\frac12$ per cube by the total number of half-accounted cubes, you get
$$\frac12\sum_{k=1}^n 2(n-1)=\frac{n^2-n}2$$
Now about the corner cubes of each layer. They are all the same, so we'll take the simplest one to imagine, namely the one from the $k=1$ layer. The volume accounted for by the pyramid volume is $\frac13$, but its actual volume is $1$. So you'd add $\frac23$ for each such cube, and there is one such cube in each layer, so you have to add $\frac23n$ to the sum and obtain the final result:
$$\frac{n^3}3+\frac{n^2-n}2+\frac{2n}3=\frac{n^3}3+\frac{n^2}2+\frac n6$$
If you want to do this strictly one degree after the other, then you'd include the corner cubes into the consideration of the edge cubes, turning that term into $\frac{n^2}2$, and in the last step only consider that part of the edge cubes which hasn't ben accounted for by either pyramid volume or edge volume. But you'd have to be careful of how many times you count each part of them in this case, since the edge corrections would overlap. That's the reason I find the above to be simpler.
So if you look at the described cube arangement from the top (i.e. the $-z$ direction), then the cubic term is associated with the inner volume of the continuous pyramid, the square term is associated with the edge cubes which (almost) cover the square if you project them down to the base plane, and the linear term is associated with the edge cubes which form a (diagonal) line in that projection. The coefficients are the correction terms which express how much of each group hasn't been accounted for by the higher orders.
