Squares Modulo 4 and 8 Explained with Worked Examples

Every perfect square leaves remainder 0 or 1 when divided by 4, and every odd square leaves remainder 1 when divided by 8: and for odd .

Write 2x or 2*x to multiply, ^ for powers, and ; between simultaneous equations. You can also type factor, expand, derivative of, integrate … from a to b, limit … as x->0 or 15% of 80.

Try an example

Before you start

This page is easier if you are comfortable with:

What Squares modulo 4 and 8 means

An even number is , so its square is divisible by 4. An odd number is , so its square is ; since is always even, the square is , which leaves remainder 1 on division by 8. The idea of remainders comes from linear congruences, and the pattern of odd and even numbers is in even, odd and consecutive numbers.

The result is used to prove that some numbers are not squares: any number of the form or is not a square, and any odd number that is 3, 5 or 7 mod 8 is not a square. It also limits sums of two squares, because the remainders of mod 4 can only be 0, 1 or 2, a fact used in the sum of two squares theorem.

The same idea explains why one leg of a Pythagorean triple is always even, and relates to other residue rules such as the digit sum rule and the rule for 11. A deeper tool is Euler's theorem.

What is it used for?

Squares leave very few remainders, so remainders can prove that a number is not a perfect square.

How to use squares modulo 4 and 8

  1. Find the remainder of the number on division by 4 (or by 8 for an odd number).
  2. Compare with the allowed remainders 0 and 1 (mod 4), or 1 (mod 8 for odd squares).
  3. If the remainder is not allowed, the number is not a square.
  4. If it is allowed, the test is inconclusive and more checking is needed.

Graph

Remainder of x² on division by 4 for x = 1 to 81² → 12² → 0012345678900.511.522.53Remainder of x² on division by 4 for x = 1 to 8xremainderGraph with x from 0 to 9 and y from 0 to 3. Shows bars (8); point 1² → 1 at (1, 1); point 2² → 0 at (2, 0.05).

Only the remainders 0 and 1 ever appear, so 2 and 3 are impossible.

Worked examples

These examples are worked by hand, step by step, so you can compare your own working.

Example 1: an odd square

Find modulo 8.

Worked example
Answer
11
  1. Square
  2. Remainder

Example 2: not a square

Show that 2023 is not a perfect square.

Worked example
Answer
2023 is not a square2023\ \text{is not a square}
  1. Divide by 4
  2. Remainder 3 is impossible for a square

Example 3: an odd number

Show that 1997 is not a perfect square.

Worked example
Answer
1997 is not a square1997\ \text{is not a square}
  1. Divide by 8
  2. An odd square would leave remainder 1

Special cases

A few situations come up again and again. Knowing them saves time and helps you spot answers that cannot be right.

7² mod 8

49 = 6·8 + 1

1.

6² mod 4

36

0.

9² mod 8

81

1.

5² mod 8

25

1.

Word problems

Every square is ≡ 0 or 1 (mod 4); every odd square is ≡ 1 (mod 8). These constraints rule out many Diophantine equations.

7² mod 8

Odd square.

  1. 49 − 48
  2. Check: ✓1

6² mod 4

Even square.

  1. 36 = 9·4
  2. Check: ✓0

9² mod 8 Higher

Odd square.

  1. 81 − 80
  2. Check: ✓1

5² mod 8 Higher

Odd square.

  1. 25 − 24
  2. Check: ✓1

Common mistakes

Squares ≡ 2 or 3 (mod 4)

possible ✗

never ✓

Only 0, 1.

Even squares mod 8

always 0 ✗

0 or 4 ✓

2² = 4, 4² = 0.

Odd squares mod 4

3 ✗

1 ✓

Always 1.

n² + 1 divisible by 3

sometimes ✗

check mod 3 instead ✓

Different modulus.

Exam tips

  1. Squares mod 4: 0 or 1.
  2. Odd squares mod 8: 1.
  3. Even squares mod 8: 0 or 4.
  4. Use to show impossibility.
  5. Test small residues.

Practice questions

Try each one on paper, then open the answer. Use the solver above to see the full working.

1. 11² mod 8 Foundation

1

2. 10² mod 4 Foundation

0

3. 13² mod 8 Foundation

1

4. 14² mod 8 Higher

4

5. 15² mod 4 Higher

1

6. 12² mod 8 Higher

0

Practice generator

Unlimited fresh questions with instant marking. Choose a level, work it out on paper, then type your answer.

Solve: …

Key terms

Quadratic residue
Square mod n.
Congruence
≡ mod n.
Parity
Odd or even.
Residue class
Remainders.
Impossibility argument
Contradiction mod 4.
Modulus
n.

Frequently asked questions

What can a square be mod 4?

0 or 1.

What is an odd square mod 8?

1.

Why?

(2k + 1)² = 4k(k + 1) + 1 and k(k + 1) is even.

How is it used?

To show equations like a² + b² = 4c + 3 have no solutions.

Which page covers the sum of two squares theorem?

sum of two squares theorem.

Which page covers Pythagorean triples?

Pythagorean triples.

More in Discrete maths and number theory and the formula sheets.