Logic, Pattern and Formula for counting number of squares in a square grid.
Number of squares in a 6×6, 5×5, 4×4, 3×3 grids.
Number of squares in a 1 X 1 grid

1 square of 1 X 1
Number of squares in a 2 x 2 grid

4 squares of 1 X 1 (sq. 1,2,3,4)
1 square of 2 x 2 (sq. 1234)
______________________
5 squares Total
Number of squares in a 3 x 3 grid
9 squares of 1 X 1 (squares 1,2,3,4,5,6,7,8,9)
4 squares of 2 x 2 (squares made by combining squares 1245, 2356, 4578, 5689)
1 square of 3 x 3 (square made by joining all 9 squares 123456789)
______________________
14 squares Total
Therefore, number of squares in a 4×4 grid
16 squares of 1 X 1
9 squares of 2 X 2
4 squares of 3 X 3
1 square of 4 X 4
______________________
30 squares Total
Pattern / Formula
Generalising
Number of squares in a nxn square grid = sum of squares of n natural numbers
=n2 + (n-1)2 + (n-2)2 ………….32 + 22 + 12
or
n(n+1)(2n+1)/6 (sum of square of n natural numbers)

Using the formula, we can get number of squares in a 5 x 5 grid.
= 5(5+1)(2×5+1)/6
= 55
number of squares in a 6 x 6 grid
= 6(6+1)(2×6+1)/6
= 91