In a square grid ($6 \times 6$) that comprises 25 small unit squares each of side 1 cm, how many rectangles (not squares) are there in the grid? This comes under Combinatorics under intersection of parallel lines. I calculated the number of rectangles to be $\binom62 \times \binom62 = 225$. But how does one subtract only the number of squares from this number? Please help.
 A: HINT: Count the squares according to their sizes. There is one square of side $5$, and there are $5^2=25$ of side $1$. How many are there of sides $4,3$, and $2$? (It’s probably easiest to count them in that order, but you should see a pattern pretty quickly.)
It may help to realize that when you’re counting squares of side $k$, once you choose the top and lefthand edges, there’s nothing left to choose: the bottom and righthand edges have to be $k$ units down and over, respectively. Of course this does put some limitations on which edges you can choose for the top and lefthand side.
Added: Indeed, you can carry this same idea further: once you know where the upper lefthand corner is, you know the whole square. How many places are there for the upper lefthand corner of a square of side $k$? It has to be at least $k$ units from the bottom and at least $k$ units from the righthand edge. How many vertices fit that description?
A: You need to count the squares. The number of $1\times 1$ squares is $5^2$. 
The number of $2\times 2$ squares is $4^2$. The number of $3\times 3$ squares is $3^2$. The number of $4\times 4$ squares is $2^2$. And finally there are (is?) $1^2$ square that is $5\times 5$. 
Add up to get what you need to subtract from the total count of the rectangles. 
To see that there are, for example, $2^2$ $4\times 4$ squares, note that the northwest corner of such a square can be in any grid position in a certain square at the northwest corner.
The idea genralizes. We can even use it to count the number of squares in a rectangular $m\times n$ array.
