Why is there a pattern to the last digits of square numbers?

The answer to this question is a bit less profound than you might hope. To see why, first note that the last digit of the square of any natural number only depends on the number's last digit - any other digits represent powers of 10 and do not make any difference to the last digit of the square.

So the problem amounts to working out the last digit of the squares of single digit numbers (and 10, if we don't consider 0 a natural number). They are:

  1. 1
  2. 4
  3. 9
  4. 6
  5. 5
  6. 6
  7. 9
  8. 4
  9. 1
  10. 0

The relative frequencies of these last digits here explain why they take up the proportions of square numbers that you observe.


These numbers are the squares modulo 10. Notice that the square of the number $10n+k$ is $$ (10n+k)^2 = 10(10n^2+2nk)+k^2, $$ so the last digit of the square is determined by only the last digit of the original number. In particular, we find $$ 0^2=0 \quad 1^2=1 \quad 2^2 = 4 \quad 3^2 = 9 \quad 4^2 = 10+6 \\ 5^2 = 20+5 \quad 6^2 = 30+6 \quad 7^2 = 40+9 \quad 8^2 = 60+4 \quad 9^2 = 80+1, $$ or writing "$\equiv$" to mean that they have the same last digit, $$ 0^2 \equiv 0 \\ 1^2 \equiv 1 \equiv 9^2 \\ 2^2 \equiv 4 \equiv 8^2 \\ 3^2 \equiv 9 \equiv 7^2 \\ 4^2 \equiv 6 \equiv 6^2 \\ 5^2 \equiv 5, $$ so every last digit except $0$ and $5$ is the last digit of two squares out of a block of 10 consecutive numbers, while $0$ and $5$ are the last digit of only one each.


Others have covered the reason why the last digit of the number you are squaring is all that matters. There is also a good reason why some digits appear twice and others appear once. The point is that if $k$ is any digit then $(10-k)^2=100-20k+k^2$ has the same last digit as $k^2$, so for any $k$ other than $0$ or $5$ there is another digit whose square ends in the same thing. ($0$ and $5$ are special because $10-0$ isn't a digit and $10-5=5$.) The same thing applies in any base, with the caveat that there is only an analogue of $5$ in even bases ($5=10/2$); in odd bases every $k$ except $0$ comes in a pair.

(This argument immediately tells you that in base $b$, squares can have at most $1+\lfloor b/2\rfloor$ possible last digits. In fact this bound is attained if and only if $b$ is either a prime or twice an odd prime.)

(To answer Vignesh Manoharan: The bound is exact if and only if for any $a$ the only solutions to $x^2\equiv a^2$ mod $n$ are $x\equiv\pm a$ mod $n$. As you say, this is equivalent to $n\mid (x-a)(x+a)$ implies $n\mid (x-a)$ or $n\mid (x+a)$, which is certainly true for $n$ prime. But it's also true for $n=2p$ where $p$ is an odd prime, since $p$ will divide one factor, and $2$ must divide both as they differ by an even number. It's not true if $n=qr$ where $q,r>1$ are the same parity, by setting $x=(q+r)/2$ and $a=(q-r)/2$; any other base has a factorisation of this form.)