# Total no of squares on a Chess Board

Is there any formula than calculates the total number of squares on chessboard?

For example in a $8\times8$ chessboard, there are squares of sizes $1\times1$, $2\times2$, $\ldots$, $8\times8$.

So I want to know their total number. Is there a general formula for a $n\times n$ chessboard?

• Yes, it's classroom assignment question but not sure both have same assignment.. – Shyam Shingadiya Jun 11 '17 at 17:29
• Yes the logic is same, but only the representation is different. – Shyam Shingadiya Jun 11 '17 at 17:31

There are

$1^2 + 2^2 + 3^2 + 4^2 + 5^2 + 6^2 + 7^2 + 8^2 = 204$ squares on an $8\times8$ board.
In the general case, the number of squares is $1^2 + \dots + n^2$ for an $n\times n$ board,
or equivalently, $\rlap{\raise{2.5ex}{~\scriptsize ~n}}{\rlap{\lower{2ex}{\scriptsize{k\text{=1}}}}{\large{\sum}~k^2}}$.

As @M Oehm noted, a Faulhaber formula lets us simplify this to $\large ~~\frac{n(n+1)(2n+1)}6$.

This is because ...

For $1\times1$ squares, there are obviously $n^2$ of them.
You can fit $(n-1)$ rows of $2\times2$ squares in an $n^2$ area, and each row has $(n-1)$ in it.
You can fit $(n-2)$ rows of $3\times3$ squares in an $n^2$ area, and each row has $(n-2)$ in it.
...
You can fit $2$ rows of $(n-1)\times(n-1)$ squares in an $n^2$ area, and each row has $2$ in it.
And finally, of course, you can fit 1 $(n\times n)$ square in an $n^2$ area.

This expands to
$n^2 + (n-1)^2 + \dots + 2^2 + 1^2 = \rlap{\raise{2.5ex}{~\scriptsize ~n}}{\rlap{\lower{2ex}{\scriptsize{k\text{=1}}}}{\large{\sum}~k^2}} = \large ~~\frac{n(n+1)(2n+1)}6$.

• Is it worth mentioning that it's equal to $\dfrac{n(n+1)(2n+1)}{6}$? – boboquack Jun 11 '17 at 4:24
• Took a while to get a $\sum$ formula to look right inside a spoiler - finally sussed it out. – Rubio Jun 11 '17 at 7:57

In an n × n checkerboard, there are:

• n² squares of edge length 1;
• (n − 1)² squares of edge length 2;
• (n − 2)² squares of edge length 3;
• ...
• 9 squares of edge length n − 2
• 4 squares of edge length n − 1
• 1 square of edge length n

In other words, there are

∑ k²;   k = 1, ..., n

squares. With the Faulhaber formula, you can simplify this to:

¹/₆ n · (n + 1) · (2 n + 1)

On the regular checker board, where n = 8, there are 204 squares.

Caveat: This formula counts only the axis-aligned squares. If squares can be drawn with any grid point between the cells as corner, the solution is different.

Lets look at the patterns:

There is $1$ square in a $1$x$1$ square.

There is $5$ squares in a $2$x$2$ square, 4 small, 1 large.

There is $14$ squares in a $3$x$3$ square, 9 small, 4 medium, 1 large

There is $30$ squares in a $4$x$4$ square, 16 small, 9 medium, 4 large, 1 extra large.

Notice anything? These are the square pyramidal numbers according to oeis and wikipedia says

'Square pyramidal numbers also solve the problem of counting the number of squares in an n × n grid.'

For an $n$x$n$ box, it is the sum of $n^2 + (n-1)^2 + (n-2)^2 + ... + 0^2$, or more simply the sum of $n^2$ and all previous squares

From this we can derive the final formula for the total amounts of squares, $t$ in an $n$x$n$ grid:

$$t=\frac{n*(n+1)*(2*n+1)}{6}$$

• I'll add a few diagrams for how many squares in a $n$x$n$ grid, otherwise theres no proof – Beastly Gerbil Jun 11 '17 at 17:16
• That formula isn't the same thing. For instance, for $n=2$ it gives 6 squares rather than 5. – Deusovi Jun 11 '17 at 17:17
• @Deusovi oops. I just found a better one anyway, editing... – Beastly Gerbil Jun 11 '17 at 17:19
• It should be $(n-1)*(n-1)$, not $n(n-1)$ – Narusan Jun 11 '17 at 17:20
• @Beastly: Perfect, appreciated your help. This will not calculate rectangles, only squares, right..? – Shyam Shingadiya Jun 11 '17 at 17:20