Calculators
Grid Rectangle Calculator
Count all rectangles, squares and nonsquare rectangles in a rectangular grid with exact browser-only arithmetic.
Count axis-aligned rectangles on a complete rectangular grid, including squares. Enter row and column counts as positive integers of up to 100 digits. Results stay in your browser.
How to count rectangles in a grid
For r rows and c columns of cells, choose two of the r + 1 horizontal grid lines and two of the c + 1 vertical grid lines. The rectangle count is r(r + 1)c(c + 1)/4, including squares. The square count is the sum of (r − k + 1)(c − k + 1) for k from 1 to min(r, c), evaluated with a closed formula rather than a loop. Subtract squares to get nonsquare rectangles. A 2 × 3 grid contains 18 rectangles: 8 squares and 10 nonsquare rectangles. An 8 × 8 board contains 1296 rectangles, including 204 squares. Inputs describe cells, not grid lines. Only axis-aligned shapes with corners at grid intersections are counted; tilted shapes and grids with missing cells are excluded. Enter positive whole numbers of up to 100 decimal digits per dimension. Leading zeros and surrounding whitespace are accepted; signs, separators, decimals and scientific notation are rejected. Exact BigInt arithmetic preserves all digits and calculations stay in your browser.
Frequently Asked Questions
Everything you need to know about this tool, how it works, and privacy.
What formula counts rectangles in a grid?
For r rows and c columns of cells, use r(r + 1)c(c + 1)/4. This includes squares.
How many rectangles are on an 8 × 8 chessboard?
There are 1296 axis-aligned rectangles, including 204 squares and 1092 nonsquare rectangles.
Do I enter cells or grid lines?
Enter the number of rows and columns of cells. A 2 × 3 grid has 3 horizontal and 4 vertical grid lines.
Are tilted rectangles included?
No. Every counted rectangle follows the grid lines, with all four corners at grid intersections.
Can dimensions be very large?
Each dimension can contain up to 100 decimal digits. Exact integer arithmetic and closed formulas avoid enumerating individual shapes.