Suppose you want to know whether x2≡8137(mod5959) has a solution. However, 5959=59×101 is composite. You have no quick way to factor it. The Legendre Symbol only makes sense for a prime modulus. So it cannot be applied directly to 5959. Yet the formula that computes Legendre symbols via The Law of Quadratic Reciprocity looks purely combinatorial. It flips numerator and denominator with a sign correction. This almost begs to be extended past primality. The Jacobi symbol is exactly this extension. It is a multiplicative bookkeeping device defined for any odd positive denominator. It is built by multiplying Legendre symbols over the prime factorization. The payoff is enormous. Reciprocity for the Jacobi symbol lets us compute (na) for huge a and odd n. We use an algorithm that looks exactly like the Euclidean algorithm. It is a sequence of reductions and flips. This runs in time polynomial in logn, without ever factoring n. This is remarkable for one key reason. The Legendre symbol's own defining property (quadratic residue or not) genuinely depends on primality. Yet the Jacobi symbol strips this dependency away from the computation. It does this while sacrificing part of its meaning. A Jacobi symbol of +1 no longer certifies that a is a square mod n. The big picture is this. The Jacobi symbol is a completely multiplicative function on the group of integers coprime to n. It agrees with the Legendre symbol prime by prime. It also satisfies its own reciprocity law. This law mirrors quadratic reciprocity almost verbatim. This makes it the natural setting for fast primality tests (Solovay–Strassen). It also suits the definition of pseudosquares in cryptography. And it enables a cleaner theoretical treatment of quadratic forms over composite moduli. This article gives the precise definition and proves complete multiplicativity. It proves the three supplementary laws and the reciprocity law in full. It works two nontrivial numerical examples. It shows exactly where the Jacobi symbol fails to detect quadratic residues. This is the price paid for its computational freedom. It closes by pointing toward the algorithmic and cryptographic uses. These uses make this symbol indispensable in practice.
Key takeaways
The Jacobi symbol (na) extends the Legendre symbol to any odd n>0 by multiplying over n's prime factors.
It is completely multiplicative in both the top and bottom arguments (for odd, coprime, positive denominators).
It satisfies its own reciprocity law: for odd coprime m,n>0, (nm)(mn)=(−1)2m−12n−1.
Supplementary laws for −1 and 2 hold in exactly the same form as for the Legendre symbol.
Crucially, (na)=1 does not imply a is a quadratic residue mod n when n is composite.
Key idea: factoring out primality lets reciprocity become a fast recursive algorithm, at the cost of losing the residue-detection meaning.
Where this lives today
The Jacobi symbol's chief modern role is computational: because it can be evaluated in O((logn)2) bit operations via a Euclidean-style recursive algorithm (exactly mirroring the worked examples above), it gives a fast way to compute Legendre symbols for large primes without needing to run Euler's criterion (which would require modular exponentiation, itself efficient but structurally different) — the two methods cross-check each other in implementations. This same fast evaluation underlies the Solovay–Strassen primality test, a foundational randomized algorithm in Cryptography and complexity theory: for a candidate prime n, one checks whether a(n−1)/2≡(na)(modn) for random a, exploiting the counterexample phenomenon above (composite n will often fail this check because the Jacobi symbol's +1 verdict does not match true residue behavior). In cryptography, the gap this article highlights — that (na)=1 does not imply a is a square mod n — is not a bug but a feature exploited constructively: it defines the notion of a pseudosquare, an integer with Jacobi symbol +1 that is nevertheless not a quadratic residue. The hardness of distinguishing true squares from pseudosquares modulo an RSA-like composite (the quadratic residuosity problem) underlies the semantic security of the Goldwasser–Micali public-key cryptosystem, one of the first schemes proven secure under a precise cryptographic hardness assumption. Beyond cryptography, the Jacobi symbol appears throughout analytic and algebraic number theory: in the theory of binary Quadratic Forms and their composition, in class field theory as a prototype for more general power-residue symbols (cubic and higher-order reciprocity), and in the study of character sums, where (n⋅) is used as a real Dirichlet character modulo n when n is not a perfect square, feeding into L-functions and the analytic study of quadratic fields.
Ask the tutor: How does the Solovay–Strassen test use Euler's criterion together with fast Jacobi symbol computation to detect compositeness efficiently?
DefinitionThe Jacobi Symbol
Let n be a positive odd integer with prime factorization
n=p1e1p2e2⋯pkek
(where the pi are distinct primes, possibly k=0 giving n=1), and let a be any integer. The Jacobi symbol(na) is defined by
(na)=i=1∏k(pia)ei,
where each factor (pia) is the ordinary Legendre Symbol. By convention (1a)=1 for every a (the empty product). Thus the Jacobi symbol takes values in {−1,0,1}: it is 0 if and only if gcd(a,n)>1, and otherwise it is ±1.
Intuition
The definition is deliberately naive: to evaluate (na), factor n and multiply Legendre symbols. This immediately shows the symbol is 1 whenever a is an actual quadratic residue mod n (with gcd(a,n)=1), because each prime-power Legendre-symbol factor is forced to be 1 when a is a square mod each pi. But the converse fails: the symbol can be +1 by an even number of −1 factors canceling, without a being a square mod any of the individual primes dividing n. This is the central subtlety of the whole theory, and it is why the Jacobi symbol is a computational tool rather than a residue-detector once n is composite. The deeper reason the symbol is useful despite this is that its multiplicativity and reciprocity properties hold unconditionally, regardless of what is happening internally with residues. The proof of Jacobi reciprocity reduces cleanly to the prime case via a careful additivity argument on the exponents 2p−1 and 8p2−1 that appear in the Legendre supplementary laws — the whole engineering effort of this article is checking that these exponents behave well modulo 2 under multiplication of odd numbers, so that products of prime factorizations reciprocate coherently.
Figure
Jacobi symbol as a signed product over prime factors, illustrated for n = 21 = 3·7
TheoremComplete Multiplicativity and Reciprocity of the Jacobi Symbol
Let m,n be positive odd integers and a,b integers.
(1) Multiplicativity in the top:(nab)=(na)(nb).
(2) Multiplicativity in the bottom:(mna)=(ma)(na).
(3) Supplementary law for −1: if gcd(a,n)=1 is not required here since n itself determines this;
(n−1)=(−1)2n−1.
(4) Supplementary law for 2:
(n2)=(−1)8n2−1.
(5) Reciprocity: if in addition gcd(m,n)=1, then
(nm)(mn)=(−1)2m−1⋅2n−1.
LemmaAdditivity of the reciprocity exponent modulo 2
Define ε(n)=2n−1mod2 and ω(n)=8n2−1mod2 for odd positive n. Then for odd positive m,n:
ε(mn)≡ε(m)+ε(n)(mod2),ω(mn)≡ω(m)+ω(n)(mod2).
Equivalently, (−1)2mn−1=(−1)2m−1(−1)2n−1 and (−1)8(mn)2−1=(−1)8m2−1(−1)8n2−1.
Proof
Technique: direct algebraic identity via writing m=1+2s, n=1+2t. Write m=1+2s and n=1+2t with s,t integers (since m,n are odd). Then
mn−1=(1+2s)(1+2t)−1=2s+2t+4st,
so
2mn−1=s+t+2st≡s+t=2m−1+2n−1(mod2).
This proves the first identity, since reducing an exponent of −1 modulo 2 does not change the value (−1)(⋅). For the second identity, we use the standard fact that for any odd integer k, k2≡1(mod16) (proof: k=2j+1, so k2−1=4j(j+1), and j(j+1) is even, so 4j(j+1) is divisible by 8; in fact one checks k2≡1(mod8) directly and the sharper mod-16 fact is not needed — we redo this cleanly below). Actually we only need 8k2−1mod2, i.e. k2−1mod16. Let k=2j+1. Then k2−1=4j(j+1). Since j(j+1) is always even (product of consecutive integers), write j(j+1)=2r; then k2−1=8r, so 8k2−1=r=2j(j+1), which is the j-th triangular number Tj. We must show Tm′:=8(mn)2−1≡8m2−1+8n2−1(mod2). Compute directly:
(mn)2−1=m2n2−1=(m2−1)(n2−1)+(m2−1)+(n2−1).
Divide by 8:
8(mn)2−1=8(m2−1)(n2−1)+8m2−1+8n2−1.
Since m,n are odd, 8∣(m2−1) and 8∣(n2−1) (as shown: 8m2−1=Tj is an integer), so (m2−1)(n2−1) is divisible by 64, hence 8(m2−1)(n2−1) is divisible by 8, in particular even. Therefore modulo 2,
8(mn)2−1≡8m2−1+8n2−1(mod2),
as required. ■
∎
Proof
Proof of the Theorem. Technique: reduction to the Legendre symbol case via prime factorization, using multiplicativity of both the symbol and the reciprocity exponent (previous lemma). Write n=∏i=1kpiei and, when needed, m=∏j=1ℓqjfj, with pi,qj odd primes.
(1) Multiplicativity in the top. By definition,
(nab)=i=1∏k(piab)ei.
For each prime pi, the Legendre symbol is completely multiplicative: (piab)=(pia)(pib). This is a standard property of the Legendre symbol, provable via Euler's criterion (pa)≡a(p−1)/2(modp), since (ab)(p−1)/2=a(p−1)/2b(p−1)/2. Substituting,
(2) Multiplicativity in the bottom. The prime factorization of mn is the "concatenation" of the factorizations of m and n (multiply exponents of shared primes if gcd(m,n)>1; if gcd(m,n)=1 the prime sets are disjoint, but the argument works regardless since the Jacobi symbol definition is literally a product over the multiset of prime-power factors). Precisely, if mn=∏ipiei∏jqjfj (merging exponents where primes coincide), then by definition
(mna)=i∏(pia)ei⋅j∏(qja)fj=(ma)(na),
directly from the definition applied separately to m and to n, since the definition of (na) only depends on the multiset of prime-power factors of n and multiplies Legendre-symbol contributions independently for each. No property of the Legendre symbol beyond its own definition is needed here; this is purely a statement about how the defining product behaves under merging factorizations.
(3) Supplementary law for −1. By definition and the known Legendre-symbol supplementary law (p−1)=(−1)(p−1)/2 (a standard consequence of Euler's criterion, part of The Law of Quadratic Reciprocity package),
We must show ∑iei2pi−1≡2n−1(mod2). This follows by repeated application of the additivity lemma: writing n as a product of ei copies of each pi (i.e. n=p1⋅p1⋯p1⋅p2⋯, a product of ∑ei odd primes with repetition), the lemma gives
2n−1≡i∑ei⋅2pi−1(mod2)
by induction on the number of factors (base case one factor is trivial; inductive step is exactly the additivity identity of the Lemma applied to "current partial product" times "next prime factor"). Hence (n−1)=(−1)(n−1)/2.
(4) Supplementary law for 2. Identical argument using the Legendre supplementary law (p2)=(−1)(p2−1)/8 and the second part of the additivity Lemma, by the same induction on the factorization of n into (not necessarily distinct) odd primes:
(5) Reciprocity. Let m=∏j=1ℓqjfj and n=∏i=1kpiei with gcd(m,n)=1, so no qj equals any pi. By definition and multiplicativity already established (parts 1–2 applied repeatedly, or directly from the definition):
(nm)(mn)=(i∏(pim)ei)(j∏(qjn)fj).
Expand (pim)=∏j(piqj)fj (Legendre symbol multiplicativity in the top, as in part 1 but now with the Legendre symbol directly) and similarly (qjn)=∏i(qjpi)ei. Substituting,
By the computation in part (3) above, ∑iei2pi−1≡2n−1(mod2) and ∑jfj2qj−1≡2m−1(mod2). Since we only care about the exponent modulo 2 (as it exponentiates −1), we conclude
(nm)(mn)=(−1)2n−1⋅2m−1=(−1)2m−1⋅2n−1.
This completes the proof of all five parts. ■
∎
Worked examples
Example 1: Evaluate (99071001) where 9907 is prime, without directly testing quadratic residuosity. First check 9907 is odd (it is) and that gcd(1001,9907)=1: factor 1001=7×11×13, and none of 7,11,13 divides 9907 (since 9907 is prime and larger than each), so the gcd is 1 and the symbol is ±1. We use the Jacobi-symbol algorithm — reciprocity plus reduction mod the current denominator — even though 9907 happens to be prime, illustrating that the method doesn't care about primality of either argument. Step 1: (99071001). Both 1001 and 9907 are odd and positive, and coprime, so reciprocity applies. We have 1001≡1(mod4) (since 1001=4⋅250+1) — actually let's directly track the sign via the formula (−1)21001−1⋅29907−1. Compute 21001−1=500 (even) and 29907−1=4953 (odd). The product 500×4953 is even (since 500 is even), so the reciprocity sign is (−1)even=+1. Hence
(99071001)=(10019907).
Step 2: Reduce 9907mod1001. Compute 9907=9×1001+898 (check: 9×1001=9009, 9907−9009=898). So
(10019907)=(1001898).
Step 3: Factor out powers of 2: 898=2×449, and 449 is odd. So
(1001898)=(10012)(1001449).
Step 4: Evaluate (10012)=(−1)810012−1. Since 1001≡1(mod8) (as 1001=8×125+1), we have 10012≡1(mod16) hence certainly 810012−1 is even (the standard supplementary rule states (n2)=1 when n≡±1(mod8)). So (10012)=1. Step 5: Now handle (1001449), both odd, coprime (since 449 is prime and does not divide 1001=7×11×13). Reciprocity sign: 2449−1=224 (even), so the sign is automatically +1 regardless of 1001's residue mod 4. So
(1001449)=(4491001).
Step 6: Reduce 1001mod449: 1001=2×449+103 (check: 2×449=898, 1001−898=103). So
Step 8: Reduce 449mod103: 449=4×103+37 (check: 4×103=412, 449−412=37). So
(103449)=(10337).
Step 9: Reciprocity: 237−1=18 (even), sign +1:
(10337)=(37103).
Step 10: Reduce 103mod37: 103=2×37+29. So
(37103)=(3729).
Step 11: Reciprocity: 229−1=14 (even), sign +1:
(3729)=(2937).
Step 12: Reduce 37mod29=8:
(2937)=(298)=(292)3=(292)
(since 8=23 and cubing a value in {−1,1} preserves it). Step 13: (292)=(−1)(292−1)/8. Since 29≡5(mod8), the standard rule gives (292)=−1 (rule: (n2)=−1 when n≡3,5(mod8)). Let's double check via the formula: 292−1=840, 840/8=105, which is odd, so (−1)105=−1. Confirmed. Tracing back: every reciprocity sign used above was +1, and the only sign contribution is this final −1. So
(99071001)=−1.
This tells us 1001 is a quadratic non-residue mod the prime 9907 — and since 9907 is prime, this conclusion is fully justified (unlike in composite-modulus cases).
Example 2: Evaluate (235158) where 235=5×47 is composite, and compare direct factorization with the reciprocity algorithm. Check validity: 235 is odd. gcd(158,235): 158=2×79, and 235=5×47 share no common factor with 158, so gcd is 1. Method A: direct factorization.(235158)=(5158)(47158). 158≡3(mod5) (since 158=31×5+3). Squares mod 5 are {1,4}; 3 is not among them, so (5158)=(53)=−1. 158≡158−3×47=158−141=17(mod47). We need (4717). Use reciprocity (both primes, 17≡1(mod4), so sign automatically +1 regardless): (4717)=(1747). Reduce 47mod17=47−2×17=13. So (1747)=(1713). Reciprocity: 13≡1(mod4) so sign +1: (1713)=(1317). Reduce 17mod13=4: (1317)=(134)=(132)2=1 (any nonzero square is +1, since squaring ±1 gives 1). So (4717)=1, hence (47158)=1. Therefore (235158)=(−1)(1)=−1. Method B: Jacobi reciprocity directly on 235 without factoring.(235158): first pull out the factor of 2: 158=2×79, so
(235158)=(2352)(23579).
(2352)=(−1)(2352−1)/8. Since 235≡3(mod8) (as 235=29×8+3), the rule gives (2352)=−1. Now (23579): reciprocity sign (−1)279−1⋅2235−1=(−1)39×117; both 39 and 117 are odd so the product is odd, sign is −1. So
(23579)=−(79235).
Reduce 235mod79: 235=2×79+77, so (79235)=(7977). Factor 77=7×11: (7977)=(797)(7911). (797): reciprocity sign (−1)27−1⋅279−1=(−1)3×39, odd times odd is odd, sign −1: (797)=−(779). Reduce 79mod7=2: (779)=(72). Since 7≡7(mod8), rule gives (72)=1. So (797)=−1. (7911): reciprocity sign (−1)5×39, odd, sign −1: (7911)=−(1179). Reduce 79mod11=79−7×11=2. (1179)=(112). Since 11≡3(mod8), rule gives −1. So (1179)=−1, hence (7911)=−(−1)=1. So (7977)=(−1)(1)=−1, thus (79235)=−1, thus (23579)=−(−1)=1. Finally (235158)=(2352)(23579)=(−1)(1)=−1. Both methods agree: (235158)=−1. Since the symbol is −1, we can immediately conclude 158 is not a square mod 235 (a −1 value always correctly certifies non-residuosity — this direction never fails, as we prove below). The subtlety only arises when the symbol equals +1.
CounterexampleWhy coprimality with the modulus, and why +1 cannot certify residuosity, is essential
The reciprocity theorem requires gcd(m,n)=1; dropping this makes the formula meaningless (the symbol may be 0 and the exponent identity has no residue-theoretic content). But the more instructive failure, central to why the Jacobi symbol is not simply "a bigger Legendre symbol," is this: the implication "(na)=1 and gcd(a,n)=1⇒a is a square mod n" is false for composite n. Take n=15=3×5 and a=2. Compute
(152)=(32)(52).
Squares mod 3 are {1} (nonzero residues 1,2; 12=1,22=1), so 2 is a non-residue mod 3: (32)=−1. Squares mod 5 are {1,4}; 2 is not among them, so (52)=−1. Hence
(152)=(−1)(−1)=1.
Yet 2 is a quadratic non-residue mod both 3 and mod 5 individually, and by the Chinese Remainder Theorem, x2≡2(mod15) has a solution if and only if x2≡2 has a solution mod 3and mod 5 simultaneously — which it does not, since it fails mod 3 already. So 2 is not a square mod 15, despite (152)=+1. This shows precisely what breaks: the Legendre symbol's residue-detection meaning relies on Z/pZ being a field, where the squares form an index-2 subgroup of (Z/pZ)× and Euler's criterion converts symbol value into an exact residue test. For composite n, (Z/nZ)× splits (by CRT) into a product of the prime-power unit groups, and "being a square in the product" requires being a square in every factor — a much stronger condition than the product of signs being +1. The Jacobi symbol only ever sees the product of signs, so it cannot distinguish "even number of non-residue factors" from "residue in every factor." Note carefully what does not break: if (na)=−1, then some prime factor piei of n must contribute (pia)ei=−1 to the product, and in particular (pia)=−1 for that prime (with ei odd), so a is a non-residue mod pi, hence a cannot be a square mod n (again by CRT, since it already fails at one prime power). So the one-directional implication "(na)=−1⇒a is a non-residue mod n" remains true; only the converse direction (from +1) fails.
Scope, edge cases & common traps
Situation
What holds
What can fail
n prime
Jacobi symbol = Legendre symbol exactly
nothing — full residue-detection meaning holds
n composite, symbol =−1
a is provably a non-residue mod n
none; this direction is always valid
n composite, symbol =+1
multiplicativity/reciprocity still hold
does not implya is a residue mod n
gcd(m,n)>1
symbol is 0
reciprocity formula is vacuous/inapplicable
n even or negative
undefined in this article's convention
some texts extend to negative or even n with extra care; formulas must be re-derived
The mathematician behind it
Origins · 1 minCarl Gustav Jacob Jacobi and how this was discovered
CG
Carl Gustav Jacob Jacobi
1804–1851 · 19th-century Prussia (Königsberg and Berlin)
Jacobi was one of the most prolific mathematicians of the 19th century, renowned for foundational work on elliptic functions, the theory of determinants (the Jacobian), and dynamics (Hamilton–Jacobi theory). His introduction of the generalized symbol bearing his name, in an 1837 paper extending Gauss and Legendre's work on quadratic residues, was a small but structurally important piece of his broader program of turning number-theoretic identities into computational and algebraic machinery, a hallmark of his mathematical style across many fields.
History
- 1801: Gauss publishes Disquisitiones Arithmeticae, proving quadratic reciprocity and developing the residue framework the Jacobi symbol will later generalize.
- 1798: Legendre introduces the symbol (pa) that bears his name, in his own attempted proof of reciprocity.
- 1837: Jacobi introduces the generalized symbol for composite odd denominators, proving its multiplicativity and reciprocity properties.
- 1914: The Jacobi symbol becomes a standard computational tool as algorithmic number theory develops alongside early primality-testing ideas.
- 1977: Solovay and Strassen publish their probabilistic primality test built directly on efficient Jacobi symbol computation.
Is the Jacobi symbol defined when n is even or negative?
The classical definition given here requires n to be a positive odd integer, matching the article's convention. Many textbooks extend the definition to negative odd n using (−na) conventions tied to the sign of a, and some extend to n=0 or specific even cases with care, but these extensions require re-deriving multiplicativity and reciprocity from scratch since the proofs above rely essentially on unique factorization into odd primes and on the additivity lemma for 2n−1 and 8n2−1, both of which assume n odd and positive. Within this article's scope, always assume n>0 and odd; consult specialized references before using extended conventions elsewhere.
Why does the Jacobi symbol equal the Legendre symbol when n is prime?
When n=p is an odd prime, the factorization n=p1e1⋯pkek in the definition collapses to the single term p1, so the defining product ∏i(pia)ei has exactly one factor: (pa)1=(pa). So the Jacobi symbol reduces to exactly the Legendre symbol in this case, with no discrepancy — this is why all the supplementary laws and reciprocity look identical in form to their Legendre-symbol counterparts, since they must specialize correctly when n happens to be prime.
Can the Jacobi symbol ever be used to prove n is composite?
Yes, and this is precisely the mechanism behind the Solovay–Strassen primality test. If n is an odd prime, then Euler's criterion guarantees a(n−1)/2≡(na)(modn) for every a coprime to n. If one computes both sides for a random a and finds they disagree, then n cannot be prime (the criterion, applicable to Legendre symbols of primes, must have failed, so n is composite), giving a probabilistic compositeness witness without needing to factor n.
Does (na)=1 ever have any residue-related meaning for composite n?
It has a precise but weaker meaning: it says the number of prime-power factors piei of n for which a is a non-residue mod pi, counted with the parity of ei, is even. By the Chinese Remainder Theorem this is strictly weaker than "a is a residue mod every prime power factor of n," which is the actual condition for a to be a square mod n (when gcd(a,n)=1). The gap between these two conditions is exactly what defines a pseudosquare, discussed in the cryptography applications above.
How is the Jacobi symbol actually computed efficiently in practice?
The algorithm mirrors the worked examples: repeatedly extract factors of 2 from the numerator using the supplementary law for 2, then apply reciprocity to swap numerator and denominator (tracking the sign via 2m−1⋅2n−1mod2, which only needs m,nmod4), then reduce the new numerator modulo the new denominator, and repeat. This is essentially the binary/Euclidean GCD algorithm with sign bookkeeping, running in O((logn)2) bit operations (or faster with binary-GCD-style optimizations), entirely avoiding factorization of either argument.
Is the Jacobi symbol a group homomorphism?
Yes, in the following precise sense: for fixed odd n>0, the map a↦(na) restricted to (Z/nZ)× (integers coprime to n) is a group homomorphism into {±1}, by the multiplicativity property proved above. This makes it a real-valued Dirichlet character modulo n (when n is not a perfect square, it is a nontrivial character), which is the perspective used in analytic number theory when studying L-functions attached to quadratic fields.
What role does the additivity lemma for 2n−1 and 8n2−1 play, conceptually?
It is the technical hinge that lets the entire theorem reduce to the prime case. Because Jacobi symbol identities are defined via products over prime factorizations, and because the Legendre-symbol supplementary laws and reciprocity law involve exponents 2p−1 and 8p2−1, one needs these exponents to combine additively (mod 2) when primes are multiplied together into a composite n. Without this lemma, there would be no way to lift the prime-based reciprocity law to a genuine composite-denominator statement; with it, the lift is mechanical.