A square is a regular quadrilateral, which means that it has four equal sides and four equal angles $(90^{\circ}\:\text{angles})$
Now, first we calculate the number of squares in $8 \times 8$ grid.
- $8 \times 8 \implies 1^{2} = 1$ square
- $7 \times 7 \implies 2^{2} = 4$ squares
- $6 \times 6 \implies 3^{2} = 9$ squares
- $5 \times 5 \implies 4^{2} = 16$ squares
- $4 \times 4 \implies 5^{2} = 25$ squares
- $3 \times 3 \implies 6^{2} = 36$ squares
- $2 \times 2 \implies 7^{2} = 49$ squares
- $1 \times 1 \implies 8^{2} = 64$ squares
The number of squares in $8 \times 8$ grid $ = 1 + 4 + 9 + 16+ 25+ 36 + 49 + 64$
$ \quad = 1^{2} + 2^{2} + 3^{2} + 4^{2} + 5^{2} + 6^{2} + 7^{2} + 8^{2}$
We know that, $1^{2} + 2^{2} + 3^{2} + \dots + n^{2} = \dfrac{n(n+1)(2n+1)}{6}$
$\quad = \dfrac{8(9)(17)}{6} = 204$ squares.
$\textbf{(or)}$
Let the chess board be axis-aligned with its southwest and northeast corners at $(0,0)$ and $(8,8)$ , and consider a square with southwest and northeast corners at $(x_{1},y_{1})$ and $(x_{2},y_{2}).$
The squares centered south of the $45^{\circ}$ diagonal line $x=y$ are exactly described by $0 \leq y_{1}< x_{1} < x_{2} \leq 8$ , so there are $\binom{9}{3} = 84$ of these.
The squares centered on or north of that line are exactly described by $0\leq x_{1} < x_{2} < y_{2} + 1 \leq 9$ , so there are $\binom{10}{3} = 120$ of these.
That gives a total of $ = 84 + 120 = 204$ squares.
Now, the small colored square gives $5$ squares and two extra between another colored square.
$\therefore 7 \times 6 + 5 = 47$ squares (from magenta to red color).
And, $7 \times 5 + 5 + 2 = 42$ squares (from black to violet color).
Now, we can count hidden squares.
There are $5 \times 4 = 20$ hidden squares.
$\therefore$ The total number of squares $ = 204 + 47 + 42 + 20 = 313.$