Legendre Symbol Calculator
Symbol inputs
- The Legendre symbol (a/p) is 1 when a is a quadratic residue modulo the odd prime p, -1 when it is a non-residue, and 0 when p divides a.
- The quadratic residues mod 11 are 1, 3, 4, 5, 9, and 7 is not in that list.
- Euler's criterion agrees: a^((p - 1)/2) mod p = 7^5 mod 11 = 10, and 10 is read as -1 (that is, p - 1).
- So the Legendre symbol (7/11) equals -1: 7 is a quadratic non-residue modulo 11.
The Legendre symbol calculator tells you, for a whole number a and an odd prime p, whether a is a quadratic residue mod p. The Legendre symbol (a/p) equals 1 if a is a quadratic residue mod p, -1 if it is a non-residue, and 0 if p divides a. That single value answers the question behind the symbol: does a have a square root modulo p? A quick example shows how it works. The quadratic residues mod 11 are 1, 3, 4, 5, 9, and 7 is not among them, so (7/11) = -1. Compare mod 17, where the quadratic residues are 1, 2, 4, 8, 9, 13, 15, 16; since 2 appears on that list, (2/17) = 1. And (13/13) = 0 because 13 divides 13.
The calculator relies on Euler's criterion, which computes the symbol as a^((p - 1)/2) mod p. For a = 7 and p = 11, that power comes out to 10, which is read as -1, matching the residue list. Euler's criterion is the accepted standard for this calculation because it follows directly from the definition of the symbol and the group structure of nonzero residues modulo a prime, so it gives the correct 1, -1, or 0 in every case. This page shows the formula, the step-by-step workings, worked examples and sources, so you can check each result by hand instead of taking the answer on trust.
Worked examples
7 over 11, a non-residue
(7 · 11)
| Legendre symbol (7/11) | -1 |
| Euler criterion value | 10 |
| Interpretation | 7 is a quadratic non-residue modulo 11 |
| Quadratic residues mod 11 | 1, 3, 4, 5, 9 |
2 over 17, a residue
(2 · 17)
| Legendre symbol (2/17) | 1 |
| Euler criterion value | 1 |
| Interpretation | 2 is a quadratic residue modulo 17 |
| Quadratic residues mod 17 | 1, 2, 4, 8, 9, 13, 15, 16 |
13 over 13, divisible
(13 · 13)
| Legendre symbol (13/13) | 0 |
| Euler criterion value | 0 |
| Interpretation | 13 divides 13, so the symbol is 0 by definition |
| Quadratic residues mod 13 | 1, 3, 4, 9, 10, 12 |
What is the Legendre symbol?
The Legendre symbol is a compact way to record whether a number is a quadratic residue modulo an odd prime. Fix an odd prime p and a whole number a. If you can find some integer x whose square leaves remainder a when divided by p, then a is called a quadratic residue mod p. If no such x exists, a is a quadratic non-residue. The Legendre symbol, written (a/p), turns that question into a single value: it is 1 when a is a quadratic residue mod p, -1 when a is a non-residue, and 0 when p divides a. Those three outcomes are the only possibilities, so the symbol is a shorthand classification rather than a separate computation.
A concrete example makes the definition easier to see. Work modulo 11 and square the numbers 1 through 10. The distinct remainders that appear are 1, 3, 4, 5, and 9, so these are the quadratic residues mod 11; every other nonzero remainder is a non-residue. The number 7 is not on that list, which means no square is congruent to 7 mod 11, and therefore (7/11) = -1. The same procedure works for any odd prime. Modulo 17, the quadratic residues are 1, 2, 4, 8, 9, 13, 15, and 16. Since 2 appears among them, (2/17) = 1. A Legendre symbol calculator applies exactly this classification for whatever a and p you supply.
The third value covers the case where a and p share a factor. Because p is prime, the only way that can happen is if p divides a, and then the symbol is defined to be 0. For instance, (13/13) = 0 because 13 divides 13. This convention keeps the symbol consistent with the underlying theory: a residue class that is congruent to 0 mod p cannot be the square of a nonzero class, and treating it as a separate case avoids contradictions in the rules that combine symbols.
There is also a direct arithmetic route to the same answer. Euler's criterion computes the symbol as a^((p - 1)/2) mod p. For a = 7 and p = 11, that exponent is (11 - 1)/2 = 5, and 7^5 mod 11 equals 10. The value 10 is congruent to -1 mod 11, so the result is read as -1, matching the list-based check. When the power comes out to 1 the symbol is 1, and when it comes out to 0 the symbol is 0. Euler's criterion is what most efficient implementations evaluate, while the residue-list method is the clearest way to understand what the symbol means.
- (a/p) = 1 when a is a quadratic residue mod p.
- (a/p) = -1 when a is a quadratic non-residue mod p.
- (a/p) = 0 when p divides a.
- Quadratic residues mod 11: 1, 3, 4, 5, 9, so (7/11) = -1.
- Quadratic residues mod 17: 1, 2, 4, 8, 9, 13, 15, 16, so (2/17) = 1.
Worked examples
A Legendre symbol calculator is easiest to trust when you can check its answers by hand. The symbol (a/p) is 1 if a is a quadratic residue mod p, -1 if it is a non-residue, and 0 if p divides a. Two small primes, 11 and 17, make good test cases because their full lists of quadratic residues are short enough to write out and compare directly.
For p = 11, the quadratic residues are 1, 3, 4, 5, 9. Because 7 does not appear in that list, 7 is a non-residue mod 11, so (7/11) = -1. For p = 17, the quadratic residues are 1, 2, 4, 8, 9, 13, 15, 16. The number 2 is on that list, so 2 is a residue mod 17 and (2/17) = 1.
Euler's criterion gives the same results through exponentiation. It computes the symbol as a^((p - 1)/2) mod p. For a = 7 and p = 11, the exponent is (11 - 1)/2 = 5, and 7^5 mod 11 comes out to 10, which is read as -1, matching the residue-list answer. For a = 2 and p = 17, the exponent is (17 - 1)/2 = 8, and 2^8 mod 17 comes out to 1, matching the list again. When the base is a multiple of the prime, the symbol is 0: (13/13) = 0 because 13 divides 13.
Both methods agree in these examples, which is the point of checking them side by side. The residue list tells you what the answer should be; Euler's criterion shows how the calculator produces it.
- Residues mod 11: 1, 3, 4, 5, 9 — 7 is missing, so (7/11) = -1.
- Residues mod 17: 1, 2, 4, 8, 9, 13, 15, 16 — 2 is present, so (2/17) = 1.
- Euler check for (7/11): 7^5 mod 11 = 10, read as -1.
- Euler check for (2/17): 2^8 mod 17 = 1.
- Zero case: (13/13) = 0 because 13 divides 13.
| a | p | Residues mod p | Is a in the list? | Legendre symbol (a/p) | Euler's criterion result |
|---|---|---|---|---|---|
| 7 | 11 | 1, 3, 4, 5, 9 | No | -1 | 10, read as -1 |
| 2 | 17 | 1, 2, 4, 8, 9, 13, 15, 16 | Yes | 1 | 1 |
| 13 | 13 | — | — | 0 | — |
Euler's criterion and faster methods
Euler's criterion is the direct way to turn the definition of the Legendre symbol into an actual computation. The symbol (a/p) is 1 if a is a quadratic residue mod p, -1 if it is a non-residue, and 0 if p divides a. Euler's criterion reaches the same answer arithmetically: compute a^((p - 1)/2) mod p, and read the result. A result of 1 means residue, a result of p - 1 (which stands for -1) means non-residue, and a result of 0 means p divides a. For a = 7 and p = 11, the power a^((p - 1)/2) mod p comes out to 10, which is read as -1. That agrees with the residue list for 11: the quadratic residues mod 11 are 1, 3, 4, 5, 9, and 7 is not among them, so (7/11) = -1.
The same check works on any example. The quadratic residues mod 17 are 1, 2, 4, 8, 9, 13, 15, 16, so (2/17) = 1, and Euler's criterion would return 1 for a = 2 and p = 17. The zero case is simpler still: (13/13) = 0 because 13 divides 13, and the power computation returns 0 as well. A Legendre symbol calculator that uses Euler's criterion is therefore doing one modular exponentiation and then mapping the output to 1, -1, or 0.
Euler's criterion is correct and easy to describe, but it is not the fastest route when p is large. The exponent (p - 1)/2 can be enormous, and the modular exponentiation behind it, while efficient, grows with the size of p. For big primes, the standard fast method is quadratic reciprocity, which relates (a/p) to (p/a) after flipping the arguments and adjusting by a sign that depends on the residues of a and p modulo 4. Because p mod a is smaller than p, the symbol shrinks at each step, and the process continues until the numbers are tiny enough to evaluate directly. This is the same style of reduction used in the Euclidean algorithm.
In practice, the two methods answer different needs. Euler's criterion shows exactly what the symbol means in terms of powers and is the clearest way to see why the three values 1, -1, and 0 arise. Quadratic reciprocity is the route to use for large primes, where repeated flipping and reduction avoids working with a huge exponent. A good Legendre symbol calculator can use either approach and still return the same symbol, since both are exact tests of whether a is a quadratic residue mod p.
One detail is worth keeping in mind: the symbol is only defined as described when p is an odd prime, and the zero case is handled first. If p divides a, the answer is 0 no matter what the power computation would produce, just as (13/13) = 0. When p does not divide a, Euler's criterion and quadratic reciprocity always agree, so choosing the faster method never changes the result.
Where the Legendre symbol is used
The Legendre symbol is not just a bookkeeping device for quadratic residues; it shows up wherever an algorithm needs to decide quickly whether a number has a square root modulo a prime. A Legendre symbol calculator handles the arithmetic for you, but knowing where the symbol is applied helps you see why the output — 1, -1, or 0 — matters in practice. The definition is simple: (a/p) is 1 if a is a quadratic residue mod p, -1 if it is a non-residue, and 0 if p divides a. Those three values feed directly into tests and protocols across number theory and cryptography.
Primality testing is one of the most common destinations for the symbol. Euler's criterion computes the symbol as a^((p - 1)/2) mod p, which turns the question of whether a is a square into a single modular exponentiation. For a = 7 and p = 11, that computation gives 10, which is read as -1 — matching the residue list, since the quadratic residues mod 11 are 1, 3, 4, 5, 9, so (7/11) = -1. The zero case is equally informative: (13/13) = 0 because 13 divides 13, which immediately flags that the modulus is not coprime to a. Because the symbol can be evaluated without factoring, it becomes a cheap check inside larger compositeness and primality routines.
The Jacobi symbol generalizes the Legendre symbol to odd composite moduli, and that extension is what makes the idea portable to real cryptographic key sizes. A Legendre symbol calculator is typically the entry point: once you are comfortable reading 1, -1, and 0 for a prime modulus, the Jacobi version lets you work with moduli that are products of primes, which is the setting for most public-key schemes. Quadratic residue problems in cryptography — deciding whether a value is a square modulo a large modulus — rely on exactly this machinery, and the difficulty of that decision for composite moduli is part of what gives such constructions their security.
Concrete examples keep the usage grounded. The quadratic residues mod 17 are 1, 2, 4, 8, 9, 13, 15, 16, so (2/17) = 1; the same number 2 gave a non-residue mod 11 earlier in the list above, which is a reminder that the symbol depends on both arguments, not just on a. Working through small primes by hand and then checking against a calculator builds the intuition you need before trusting results on large inputs.
In short, the Legendre symbol appears in three overlapping roles: as a fast filter in primality tests via Euler's criterion, as the prime-modulus foundation for the Jacobi symbol used with composite moduli, and as the core decision problem in cryptographic quadratic residue settings. Each role depends on the same three-valued output, so a reliable Legendre symbol calculator is useful across all of them.
FAQs
What does the Legendre symbol tell you?
It tells you whether the equation x^2 congruent to a mod p has a solution. A value of 1 means yes, a solution exists. A value of -1 means no solution exists. A value of 0 means p divides a, a special case handled separately. So the symbol gives a quick yes, no, or divisible answer.
What is (7/11)?
The answer is -1. The quadratic residues mod 11 are 1, 3, 4, 5, and 9. Since 7 is not among those residues, it is a non-residue mod 11, and the Legendre symbol (7/11) equals -1. That means x^2 congruent to 7 mod 11 has no solution.
What is (2/17)?
The answer is 1. You can confirm this directly: 6^2 = 36, and 36 is congruent to 2 mod 17. Since 2 is a perfect square mod 17, it is a quadratic residue there, so the Legendre symbol (2/17) equals 1. That means x^2 congruent to 2 mod 17 does have a solution.
How does Euler's criterion work?
Euler's criterion computes a^((p - 1)/2) mod p. If the result is 1, then a is a quadratic residue mod p. If the result is p - 1, read that as -1, then a is a non-residue. This gives a direct way to compute the Legendre symbol without testing every square.
What if p divides a?
If p divides a, the Legendre symbol is 0 by definition. For example, (13/13) equals 0. This is a separate case from residues and non-residues: the symbol is 1 when a is a nonzero square mod p, -1 when a is a non-residue, and 0 when p divides a.
Is the Legendre symbol the same as the Jacobi symbol?
Not quite. The Jacobi symbol generalizes the Legendre symbol to composite odd denominators, so it applies in more settings. However, for prime denominators the two agree, so the Legendre symbol is the special case of the Jacobi symbol where the denominator is an odd prime.