• Foundation
  • About 11 min
  • 5 practice questions

Counting rectangles in a grid

Count all rectangles in a grid of cells by choosing pairs of grid lines, and see how squares fit inside the total.

If something looks wrong, please tell us.

A rectangle on a grid is fixed by choosing two vertical lines and two horizontal lines. This turns the problem into choosing pairs, just as for segments on a line. A square is also a rectangle, so a rectangle count includes all the squares.

The rule

A grid with m rows and n columns of cells has m plus 1 horizontal lines and n plus 1 vertical lines. The number of ways to choose 2 horizontal lines is (m plus 1) times m, divided by 2. The number of ways to choose 2 vertical lines is (n plus 1) times n, divided by 2. Multiply the two numbers.

Rectangles in an m by n grid of cells = [m(m+1)/2] times [n(n+1)/2].

— Formula to remember
Rectangles in some grids
Grid (rows by columns)Pairs of horizontal linesPairs of vertical linesRectangles
1 by 3166
2 by 2339
2 by 33618
3 by 36636
4 by 41010100

Worked examples

Example 1. How many rectangles are in a 2 by 3 grid? Working: pairs of horizontal lines: 3 lines give 3 pairs. Pairs of vertical lines: 4 lines give 6 pairs. 3 times 6 is 18. Answer: 18.

Example 2. How many rectangles that are not squares are in a 3 by 3 grid? Working: total rectangles are 36; squares are 14. 36 minus 14 is 22. Answer: 22.

Example 3. A strip of 1 row and 5 cells: how many rectangles? Working: one row has 2 horizontal lines, which give 1 pair. The 6 vertical lines give 6 times 5, divided by 2, which is 15 pairs. 1 times 15 is 15. Answer: 15.

Key takeaways: choose two vertical and two horizontal lines; multiply; subtract the squares to get the non-square rectangles.

Check your understanding

  1. 1. How many rectangles (squares included) are there in a 2 by 2 grid?

    1. 9
    2. 12
    3. 16
    4. 18
    Show answer

    Answer: A. There are 3 horizontal and 3 vertical lines, each giving 3 pairs. 3 x 3 = 9.

  2. 2. How many rectangles are there in a grid of 3 rows and 4 columns of cells?

    1. 60
    2. 72
    3. 80
    4. 90
    Show answer

    Answer: A. 4 horizontal lines give 4 x 3 / 2 = 6 pairs. 5 vertical lines give 5 x 4 / 2 = 10 pairs. 6 x 10 = 60.

  3. 3. How many rectangles in a 2 by 2 grid are NOT squares?

    1. 2
    2. 3
    3. 4
    4. 5
    Show answer

    Answer: C. There are 9 rectangles in all and 5 squares (4 small, 1 large). 9 - 5 = 4.

  4. 4. How many rectangles are there in a strip of 4 cells in one row?

    1. 8
    2. 10
    3. 12
    4. 15
    Show answer

    Answer: B. 2 horizontal lines give 1 pair. 5 vertical lines give 5 x 4 / 2 = 10 pairs. 1 x 10 = 10.

  5. 5. A grid has 2 rows and 3 columns of cells. How many horizontal and how many vertical lines does it have?

    1. 2 horizontal and 3 vertical
    2. 4 horizontal and 3 vertical
    3. 3 horizontal and 3 vertical
    4. 3 horizontal and 4 vertical
    Show answer

    Answer: D. A grid of m rows has m + 1 horizontal lines, and n columns give n + 1 vertical lines. So 2 + 1 = 3 horizontal and 3 + 1 = 4 vertical.

Privacy · Terms · Refunds · Delivery