From this page it can be shown that the number of possible rectangles in and m*n grid can be found by first choosing $2$ lines from a possible $m+1$ to form the vertical sides of the rectangle, and then $2$ from the $n+1$ horizontal sides, to give ${{m+1} \choose {2}}*{{n+1} \choose {2}}$ rectangles.
I want to extend this proof to cover only squares
I have tried choosing $2$ from ${m+1}$ for one set of sides, as a square can be formed with any two lines, but I am having trouble on how many choices there are for the remaining sides. If the first two sides are beside each other, then the last two can be any two sides that are beside each other, so there are so n choices, but after that I get lost.
The formula given on the page using a different approach is $$\frac {{n}{(2n+1)}{(n+1)}}{6}$$ or the sum of squares when m = n