Ma · Mathematics

Why Can a Perfect Square End Only in 0, 1, 4, 5, 6, or 9?

Published By the 9to5Science editorial team

At a glance

  1. 1. Check the final digit

    Write the integer as 10q + r, where r is its last digit.

  2. 2. Square modulo 10

    Since (10q + r)² and r² have the same remainder modulo 10, only r² matters.

  3. 3. List the possibilities

    Squaring the ten possible final digits gives only 0, 1, 4, 5, 6, and 9 as final digits.

  4. 4. Use the test carefully

    A different final digit rules out a perfect square, but an allowed final digit does not prove a number is square.

A quick way to rule out a number as a perfect square is to inspect its final digit. In ordinary base-10 notation, no integer square ends in 2, 3, 7, or 8. The reason is that the last digit of a square is determined entirely by the last digit of the integer being squared.

Why only the last digit matters

Since n2=(−n)2n^2=(-n)^2, it is enough to consider nonnegative integers. Any nonnegative integer nn can be written as n=10q+rn=10q+r, where qq is an integer and rr is one of 0,1,…,90,1,\ldots,9. The remainder rr is the last digit of nn. Squaring gives

(10q+r)2=100q2+20qr+r2.(10q+r)^2=100q^2+20qr+r^2.

The first two terms are multiples of 10, so they cannot change the final digit. Equivalently, modulo 10,

n2≡r2(mod10).n^2\equiv r^2\pmod{10}.

Thus, to find every possible final digit of a square, it is enough to square the ten possible final digits of an integer.

Last digit of nnLast digit of n2n^2
00
11
24
39
46
55
66
79
84
91

The only resulting digits are 0,1,4,5,6,0,1,4,5,6, and 99. Therefore, if an integer ends in 2,3,7,2,3,7, or 88, it cannot be a perfect square.

A direct proof by cases

You can also group the possible last digits into pairs that give the same square ending:

  • If nn ends in 0, then n2n^2 ends in 0.
  • If nn ends in 1 or 9, then n2n^2 ends in 1.
  • If nn ends in 2 or 8, then n2n^2 ends in 4.
  • If nn ends in 3 or 7, then n2n^2 ends in 9.
  • If nn ends in 4 or 6, then n2n^2 ends in 6.
  • If nn ends in 5, then n2n^2 ends in 5.

These cases cover every possible integer last digit and establish the claim. The argument works for negative integers too: a negative integer still has one of the same ten final digits, and its square is nonnegative.

Worked examples

Consider 1372137^2. The number 137 ends in 7, so its square must end in 9. Indeed,

1372=18,769.137^2=18{,}769.

For another example, 24 ends in 4, so its square must end in 6. In fact,

242=576.24^2=576.

The test is especially useful for rejecting candidates without calculating a square root. For example, 1,238 cannot be a perfect square because it ends in 8. There is no need to test nearby squares.

The test is necessary, not sufficient

A perfect square must end in one of the six listed digits, but not every number with one of those endings is a square. For instance, 21 ends in 1, an allowed square ending, but it is not a perfect square: 42=16<21<25=524^2=16<21<25=5^2.

So the last-digit test has a one-way use: an ending of 2, 3, 7, or 8 proves that a number is not a square; an ending of 0, 1, 4, 5, 6, or 9 merely means the test does not rule it out. Other methods, such as checking whether the integer square root is an integer, are needed to decide whether it actually is a square.

Common mistakes

  • Treating the list as a characterization. The list gives possible endings, not a guarantee that every number with one of those endings is square.
  • Using the wrong base. This exact list applies to the usual base-10 notation. In another base, the possible final digits are determined by squares modulo that base and may differ.
  • Checking more than the last digit when only this test is needed. The final digit of n2n^2 depends only on the final digit of nn, because every other term in (10q+r)2(10q+r)^2 is divisible by 10.

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.