|We shall begin with the number of squares first. Let us find a pattern by looking at some small values of n.
If n = 1, there is one 1-by-1 square.
If n = 2, there is one 2-by-2 square and four 1-by-1 squares.
If n = 3, there is one 3-by-3 square, four 2-by-2 squares and nine 1-by-1 squares.
At this point, a pattern starts to emmerge. If we continued the above sequence for an arbitrary n, then we would have one n-by-n square, four (n - 1)-by-(n - 1) squares, nine (n - 2)-by-(n - 2) squares, ... , and n2 1-by-1 squares.
Notice that this is just the summation:
Now, we shall look at the number of rectangles. The easiest way to think about this problem is using combinatorics.
Observe that on an n-by-n chessboard, there are n + 1 vertical lines and n + 1 horizontal lines. (These lines form the grid for the chessboard.)
When we form a rectangle, we choose two of the vertical lines and two of the horizontal lines. (Notice that our choice of lines determines the size of the rectangle formed.)
So, the number of rectangles is given by the formula:
Here I used the formula for the binomial coefficient which is given by: