Quadratic residues and Legendre symbols
Decide whether a nonzero residue is a square modulo an odd prime using pair counting, Euler’s criterion, and multiplicativity.
On this page
The question for today
What you’ll understand
- Count nonzero squares modulo an odd prime by pairing square roots.
- Evaluate Legendre symbols using Euler’s criterion.
- Distinguish testing the existence of a root from constructing that root.
Squaring modulo a prime creates a pattern that ordinary positive squares do not reveal. Some nonzero residues have two square roots, and the rest have none. The Legendre symbol records this yes-or-no information compactly, with a third value for zero. It does not record the roots themselves. We will derive the size of the square set, interpret a power test for membership, and see how multiplying residues changes their square status.
A square map pairs opposite inputs
Fix an odd prime p. A nonzero residue a is a quadratic residue if x² is congruent to a for some x, and a nonresidue otherwise. If nonzero x is a root, then −x is a distinct root because p is odd. There cannot be a third: from x² = y² modulo p, primality forces p to divide x − y or x + y. Thus every nonzero square has exactly two roots.
There are p − 1 nonzero inputs to the squaring map, paired into opposite pairs, so there are (p − 1)/2 nonzero square values. Define the Legendre symbol to be one for these residues, negative one for nonresidues, and zero when p divides a. The bottom entry must be an odd prime in this lesson. Substituting a composite modulus into the same notation without a new definition would confuse it with a different object, the Jacobi symbol.
A half-period power tests square status
Euler’s criterion says a to the power (p − 1)/2 is congruent to its Legendre symbol. For a nonzero a, write a = gᵏ using a primitive root. The squares are exactly even exponents. Since g to the half group size is the nontrivial square root of one, it equals −1, and the half-period power of a is one or negative one according to the parity of k. This proves the test rather than merely reporting it.
The criterion also implies multiplicativity: the symbol of ab is the product of the symbols of a and b. Equivalently, even and odd generator exponents add like parity. Two nonsquares therefore multiply to a square, while multiplying a square by a nonsquare gives a nonsquare. If either factor is divisible by p, both sides of the multiplicative identity are zero. Include that case instead of silently assuming every residue is a unit.
A membership test is not a root algorithm
A Legendre symbol of one guarantees that two roots exist but does not directly name them. For small primes a table or a search may be enough. For primes congruent to three modulo four, a nonzero quadratic residue a has a root given by a to the power (p + 1)/4; squaring that candidate and using Euler’s criterion verifies it. Other primes require a more general root-finding method, not a change to the definition of a residue.
Composite moduli behave differently. A nonzero square can have more than two roots because the factorization of x² − y² need not force one factor to be zero modulo the whole modulus. Chinese remainders can combine root choices from several prime factors. Keep the odd-prime assumption in sight whenever using the half-of-the-units count or the two-root conclusion; these are consequences of field arithmetic, not universal properties of modular squaring.
Work it through
A power test and an explicit root
Determine whether 5 is a square modulo 11, then construct its two roots.
Compute the half-period power: 5² ≡ 3 and 5⁴ ≡ 9 modulo 11, so 5⁵ ≡ 9 × 5 ≡ 1. Euler’s criterion gives Legendre symbol one, proving that roots exist.
Because 11 is three modulo four, use exponent (11 + 1)/4 = 3. Compute 5³ ≡ 3 × 5 ≡ 4 modulo 11, which gives a root candidate.
Verify 4² = 16 ≡ 5 modulo 11. Its negative is 7, and 7² = 49 ≡ 5. The factorization argument shows there are no further roots modulo this prime.
The residue 5 is a quadratic residue modulo 11, with exactly the roots 4 and 7.
The living notebook
Explore the model
Interactive lab · function
Squaring merges opposite inputs
Set coefficient a to one, pause playback, and compare positions x = 1 and x = −1. Predict the same height with opposite tangent slopes. This real quadratic illustrates why opposite inputs share a square. It does not reduce values modulo p or count finite-field roots; apply the prime-modulus factorization argument separately.
- y at chosen x
- 0.608
- Tangent slope · 2ax
- 1.35
- Signed area · ax³/3
- 0.182
This lab uses only y = ax². Playback traces the curve within the fixed integration interval from 0 to x; it does not estimate numerical error or change the chosen point. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forThe symmetry of squaring suggests paired roots, while the exact number of modular roots depends on the arithmetic domain.
Pause & reason
Check your understanding
Your turn
Try it yourself
List the nonzero squares modulo 13 and use the list to evaluate (2/13) and (6/13). Verify multiplicativity for their product.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Square the representatives one through six; the remaining nonzero inputs give the same squares with opposite signs.
Compare with the solution
The squares are 1, 4, 9, 3, 12, and 10 from inputs one through six. Neither 2 nor 6 appears, so both symbols are −1. Their product is 12, which is a square because 5² ≡ 12 modulo 13. Thus the symbol of the product is one, agreeing with (−1)(−1). The finite list has six distinct values, exactly half of the twelve nonzero residues.
Keep the idea
Take it with you
- Exactly half the nonzero residues are squares modulo an odd prime.
- Euler’s criterion tests square status, and the Legendre symbol is multiplicative.
- A test establishing that roots exist is distinct from a procedure constructing them.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.