Counts for square grids
GridRectanglesSquares
1 by 111
2 by 295
3 by 33614
4 by 410030
5 by 522555

Rectangles = C(m + 1, 2) x C(n + 1, 2). Squares = the sum of (m - k + 1)(n - k + 1) for k = 1, 2, 3, ...

— Formulas

Key takeaways: choose two vertical and two horizontal lines for rectangles, and add by side length for squares.