Logic, Pattern and Formula for counting number of squares in a rectangular grid.

Number of squares in a 6×4, 4×6, 5×4, 4×5 or 3×2 grid.

__In a 1X2 (or 2X1) grid__

Number of rows R=1, Number of columns C=2

- 2 squares of 1×1 (sq 1, sq-2)

It’s not possible to get 2×2 or any bigger size.

**Total=2 squares**

** **

__In a 3X2 (or2x3) grid__

Number of rows R=3, Number of columns C=2

**6**squares of 1×1 (1,2,3,4,5,6) RxC = 3×2=6**2**Squares of 2×2 (sq1234, sq3456) (R-1) X (C-1)=(3-1)x(2-1)=2- 0 squares of 3×3 or bigger sizes

Its not possible to get a bigger square

__Total = 6+2+0=8 Squares__

__In a 3X4 (or 4X3) grid__

Number of rows R=3, Number of columns C=4 ( or R=4 and C=3)

**12**squares of 1×1 (1,2,3……11,12) = RxC = 3×4 squares**6**squares of 2×2 (sq1-2-5-6, sq2-3-6-7……sq 7-8-11-12) = (R-1) X (C-1)

** **=(3-1) X (4-1) =2×3=6 squares

**2**squares of 3×3 (sq1-3-11-9, sq2-4-12-10) = (R-2) X (C-2) = (3-2) X (4-2)

=1×2=2 squares

**0**squares of 3×3 or bigger sizes as R-3 =0

**Total = 12+6+2+0=20 Squares**** **

__Similarly, in a 6X4 (or 4X6) grid__

- 6 x 4=24 squares of 1 X 1
- 5 x 3=15 squares of 2 x 2
- 4 x 2= 8 squares of 3 x 3
- 3 x 1= 3 squares of 4 x 4
- 2 x 0= 0 squares of 5 x 5

**Total =24+15+8+3+2=50 squares **

**Pattern /Formula for number of squares in a rectangular grid**

**RXC + (R-1) (C-1) +(R-2) (C-2) + (R-3) (C-3)**……………….

Till R-(n-1) or C-(n-1) becomes 1

R and C are number of rows and columns in a grid.

**Note**: A **square grid** is also a rectangular grid with number of rows=number of columns. Therefore, this pattern can also be used to find number of squares in a square grid (putting R=C=n in above formula)

= n^{2 }+ (n-1)^{2 }+(n-2)^{2 }………….3^{2 }+2^{2 }+1^{2}

= n(n+1)(2n+1)/6 for square grid