I have come across 100s of puzzles where you are asked to count number of squares in a grid image. You can always count squares manually however there is 99% chance that you may miss some of those. Puzzles where you have to count squares in N x N grid, a simple formula can be used to answer such puzzles.

So instead of counting squares manually, we will use a simple formula. Let’s see how to get the formula.

Let’s assume we have 2 X 2 grid like below:

There are total 5 squares in 2 x 2 grid. 4 small squares and 1 big square.

In 3 x 3 grid just like one we have here. There are 9 small squares(1 x 1), 4 2×2 squares and 1 big square.

If you have noticed, answer of N x N grid always goes like NxN + (N -1)(N-1) + (N – 2)(N-2) down to 1 when N = 1

In math, formula for the sum of the N first square numbers is:

N(N+1)(2N+1)/6

Now same formula can be used to count squares in N x N grid as well.

Let’s try it again:

Grid with only 1 square = 1(1+1)(2*1+1)/6 = 1

Grid with 2 x 2 squares = 2(2+1)(2*2+1)/6 = 5

Grid with 3 x 3 squares = 3(3+1)(2*3+1)/6 = 14

Grid with 4 x 4 squares = 4(4+1)(2*4+1)/6 = 30

Using above formula, we can even count squares in hard puzzles like Count squares puzzle . There are 3 grids in this picture. One with 4 x 4 and two with 2 X 2 grids. So answer should be 30 + 2(5) = 40