Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

sometimes there are puzzles where you have to give the number of squares you see in a picture, typically an intersection of squares. Is there a fast method to find it based on the number of corners and intersections?

share|cite|improve this question
Examples: Google image search for "how many squares" – Dan Brumleve Oct 10 '11 at 6:02
I don't have a solution, but here's a simple algorithm if you wanna do every single one by hand: First you have to partition the set of lines into subsets such that in each set the lines are all parallel or perpendicular, and that two lines from two different sets are neither. Then for each of these sets, you take corners one by one and count the number of squares which have that corner as top left corner. – Arthur Oct 10 '11 at 10:52
up vote 0 down vote accepted

In a $m \times n$ grid, $m,n \in \mathbb{N}$ and $m>n$,number of squares of all possible dimensions is given by $$ \sum _{i=1}^{n} (m-i+1) \times (n-i+1)$$ so it is obvious of the case when $m=n$.

If you also want to know the number of rectangles in the same grid,then it is given by $$\binom{m+1}{2} \times \binom{n+1}{2}$$ Since there are $(m+1)$ and $(n+1)$ horizontal and vertical lines respectively and by selecting any two vertical and any two horizontal line we will get a rectangle.

share|cite|improve this answer

This is not an answer (complete), but if you are given $n\times n$ chess-board type figure, total number of squares is $$\sum_{k=1}^nk^2=\frac{n(n+1)(2n+1)}{6}$$

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.