Analysis of how-many-squares and rectangles are are there on a chess board?

I know the formula $$f(n) = \frac{n \cdot (n + 1) \cdot (2n + 1) } 6$$

Since chess board consists $8\times 8$, hence here $n=8$.

But I want to know how it has been concluded? Also how to tackle the number of rectangles?

Here is an easy way to count the number of rectangles. There are $9$ horizontal lines on the chessboard, and $9$ vertical lines. Choose two distinct horizontal lines, and two distinct vertical lines. These determine a unique rectangle. And any rectangle determines a pair of horizontal lines and a pair of vertical lines.

So the number of rectangles is $\binom{9}{2}^2$. That is $1296$.

Exactly the same idea can be used to count the number of rectangles on an $m$ by $n$ chessboard. It is $$\binom{m+1}{2}\binom{n+1}{2}.$$

The number of squares is a bit less nice. It is easy to see that there are $8^2$ small $1\times 1$ squares, $7^2$ $2\times 2$ squares, and so on down to $1^2$ $1\times 1$ squares, for a total of $$1^2+2^2+3^2+\cdots+8^2.$$ Now we can add up, but there is also a simple formula for the sum of the first $n$ squares. The same idea works for counting the squares on an $n \times n$ chessboard.

• It is easy to see that there will be 64 small (1 x1) squares . But what is the logic behind 2 x 2 squares ? How is it $7^2$ – Geek Aug 4 '12 at 7:36
• @Geek, consider for $2 \times 2$ squares how many centers they have. – ladaghini Aug 4 '12 at 7:45
• @ladaghini not an elegant way to think in terms of center ...How would you calculate for 3 x 3 then ? – Geek Aug 4 '12 at 7:47
• @Geek: For the $3\times 3$, for example, consider the top left corner. It can take $6$ positions on the top line, $6$ positions on the second line, and so on up to $6$ positions on the sixth line, total $6^2$. Equivalently, the top left little square of the $3\times 3$ can take $6$ positions on the first row, $6$ positions on the second row, and so on. Same idea works for $k\times k$ squares. – André Nicolas Aug 4 '12 at 7:52
• @mehdi: consider this picture. – robjohn Jun 16 '14 at 15:25

If you look at a chessboard ($n = 8$), there are

• 1 square of size 8x8
• 4 squares of size 7x7
• 9 squares of size 6x6
• and so on until
• 64 squares of size 1x1

So, really, the formula boils down the the summation $\sum_{i=1}^n i^2$, which can be derived as shown in the answers here. See also a combinatorial approach to better suit your question.

For rectangles, note that for an $n \times m$ chessboard, there are $n+1$ lines that form the rows and $m+1$ lines that form the columns. A rectangle will be bound by two of these rows and two of these columns, so the number of rectangles is given by:

$R(n,m) = \binom{n+1}{2}\binom{m+1}{2}$

Note that the formula is generalized for any rectangular chessboard, not just a square one.

To get the squares, integrate $(m+1-x)(n+1-x)$ for $x$ from $1$ to $m$, where $m$ and $n$ are the dimensions of a $m\times n$ chessboard, where $m\lt n$.

I made a formula that if a square is made up of small and same size of square with in then the number of rectangle and square in that square is equall to the whole square of sum of conscutive number from 1 to number of square in a row or columns. Example- number of square and rectangle in a chess board is equall to whole square of {1+2+3+4+5+6+7+8} that is whole square of 36 which is equall to 1296