<s>[INST] Given an $n \times n $ grid, how many squares exist? How many squares exist in an $n \times n$ grid?  There are obviously $n^2$ small squares, and $4$ squares of size $(n-1) \times (n-1)$.
How can I go about counting the number of squares of each size?
 [/INST] Let the vertices of the $n \times n$ grid by $\{(x,y)| 0\le x \le n; 0 \le y \le n\}$.  
(Is that what an $n \times n$ grid is?  A $1 \times 1$ has $4$ vertices and an $n \times n$ grid has $(n+1)^2$ vertices?  Or is a $1 \times 1$ grid a single point?  I'm assuming the former.)
A $k \times k$ square will have an lower left hand vertex as $(x,y)$ and a upper right hand vertex at $(x+k, y+k)$ with the stipulation $0 \le x; 0 \le y; x+k \le n; y+k \le n$ or in other words: $0 \le x \le n-k; 0 \le y \le n-k$.
There are $n-k+1$ possible options for $x$ and $n-k+1$ options for $y$ so there $(n-k+1)^2$ $k\times k$ squares.
So the total number of squares is $\sum{k=1}^n(n-k+1)^2$.  Let $j = n-k+1$ and we have #squares = $\sum_{j = n;j--}^1j^2 = \sum_{j=1}^n j^2 = \frac{n(n+1)(2n+1)}6$
Or to put it more simply.... A $k \times k$ square has a side of length $k$.  There are $n-(k-1)$ ways to choose this side from the grid that is $n$ long so for squares of lengths $1,2, ...., n$ there are $n, n-1....., 1$ way to choose the horizontal side and $n, n-1,...., 1$ ways to choose the vertical sides.  So there are $n^2, (n-1)^2,....., 1^2$ possible $1\times 1, 2\times 2, ...,n \times n$ squares. So there are $\sum k^2 = \frac{n(n+1)(2n+1)}6$ total squares.
</s>