Maths & numbers

Modular square root calculator for a prime modulus

Find every root of x² ≡ a modulo an odd prime, including an exact square check and the no-solution case.

Your numbers

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

A modular square root asks which integers have a specified square remainder. It does not take an ordinary square root and round it. First reduce a into the interval from zero to p minus one. For a nonzero quadratic residue modulo an odd prime, exactly two residues solve the equation; they are additive negatives of each other. Zero has just one root. A nonresidue has none. This calculator returns all roots in one full residue range, using exact integer arithmetic.

THE FORMULAx² ≡ a (mod p); for a ≠ 0, a^((p−1)/2) ≡ 1 is the quadratic-residue test.

A worked example

For a = 10 and p = 13, 6² = 36 = 2 × 13 + 10 and 7² = 49 = 3 × 13 + 10. The returned roots are therefore 6 and 7. Their sum is 13, so 7 represents −6 modulo 13. Adding any multiple of 13 to either root gives another integer solution.

Good to know

Only odd prime moduli up to one billion are accepted. Composite moduli can have a different number of roots and need another algorithm. The radicand must be a whole number between −10¹² and 10¹². These bounds support an educational browser calculation rather than cryptographic key operations.

Verify the remainder, not the size of the square

The equation x² ≡ 10 modulo 13 says that x² − 10 is divisible by 13. A root need not be close to √10. For x = 6, the difference is 26; for x = 7, it is 39. Both are multiples of the modulus. The result table performs this check for every returned root, so the answer can be verified without trusting an intermediate approximation.

Negative radicands are reduced first. Entering −3 with modulus 13 gives the same problem because −3 and 10 represent the same residue. The page sorts roots into increasing nonnegative order. It is reporting representatives of infinite congruence classes, not claiming that the original equation has only two integer solutions.

Six and seven both square to ten modulo thirteenx² ≡ 10 (mod 13)6² = 2 × 13 + 107² = 3 × 13 + 10Roots in one residue range: 6 and 7
The two roots are negatives of one another modulo 13: 6 + 7 = 13. Their squares leave the same remainder 10.

Why the algorithm checks the modulus first

Primality is essential to the two-root statement. Modulo 8, the equation x² ≡ 1 has four roots: 1, 3, 5 and 7. A composite input is therefore rejected rather than passed through the prime-field procedure. For a nonzero radicand, Euler’s criterion determines whether a solution exists before Tonelli–Shanks searches for it. A no-solution answer is a valid mathematical result.

When p leaves remainder 3 on division by 4, a root can be computed as a raised to (p + 1)/4 modulo p. Other odd primes require the more general procedure. For instance, 13 falls in that second group. Both methods finish with the same exact square verification. To investigate forward modular powers instead, use the existing modular exponentiation calculator; it solves a different direction of the problem.

A few questions, answered

Why does zero produce only one root?

Over a prime field, x² = 0 implies x = 0. Negating zero produces the same residue, so there is no second distinct root.

Is this an ordinary square root calculator?

No. It solves a congruence with a specified modulus. A positive integer that is not a perfect square can still be a quadratic residue modulo some primes.

Find your calculator

Start typing to explore the library.