So let us take two numbers a and a + 1. When you square them, the difference between their squares is 2a + 1. (a^2 + 2a + 1 - a^2).
We observe that 0^2 is congruent to 0 mod 8.
1^2 is congruent to 1 mod 8, adding 2(0) + 1 = 1, which is congruent to 1 mod 8.
2^2 is congruent to 4 mod 8, adding 2(1) + 1 = 3, which is congruent to 3 mod 8.
3^2 is congruent to 1 mod 8, adding 2(2) + 1 = 5, which is congruent to 5 mod 8.
4^2 is congruent to 0 mod 8, adding 2(3) + 1 = 7, which is congruent to 7 mod 8.
5^2 is congruent to 1 mod 8, adding 2(4) + 1 = 9, which is congruent to 1 mod 8.
At this point, it looks like there is a pattern:
4x^2 is congruent to 0 mod 8.
(4x + 1)^2 is congruent to 1 mod 8.
(4x + 2)^2 is congruent to 4 mod 8.
(4x + 3)^2 is congruent to 1 mod 8.
. Now, let us prove that this is the case for any number n.
n^2 is congruent to x mod 8.
(n + 1)^2 is congruent to x + 2n + 1 mod 8, adding 2n + 1.
(n + 2)^2 is congruent to x + 4n + 4 mod 8, adding 2n + 3.
(n + 3)^2 is congruent to x + 6n + 1 mod 8, adding 2n + 5. (This creates x + 6n + 9 mod 8, but we remove 8 because we know x + 6n + 9 is congruent to x + 6n + 1 mod 8).
(n + 4)^2 is congruent to x mod 8, adding 2n + 7. (This creates x + 8n + 8 mod 8, but we remove 8n + 8 for the same reason).
We have just proven that n^2 is congruent to (n + 4)^2 mod 8. Therefore, the pattern holds and every number will be 0, 1 or 4 mod 8.