Modulo Calculator

Enter a number and a modulus to find the remainder, or add an exponent for a power mod n.

Any whole number, positive or negative.

A whole number other than 0.

Try

Result

You entered−17 mod 5-17 \bmod 5

−17 mod 5=3\displaystyle -17 \bmod 5 = 3

Programming languages such as C and JavaScript give -2 for -17 % 5; mathematicians give 3.

Quotient

−4\displaystyle -4

Truncated remainder

−2\displaystyle -2

Congruence

−17≡3(mod5)\displaystyle -17 \equiv 3 \pmod{5}
Show the work
  1. Division algorithm

    Dividing aa by nn and rounding the quotient down to a whole number qq leaves a remainder rr that is never negative. Here a=−17a = -17 and n=5n = 5.

    Using a=n×q+r,0≤r<na = n \times q + r, \quad 0 \le r < n

    q=⌊−175⌋=−4\begin{aligned} q &= \left\lfloor \frac{-17}{5} \right\rfloor \\ &= -4 \end{aligned}
  2. Remainder from the quotient

    The remainder is what is left of aa after taking away qq whole copies of nn. Here q=−4q = -4, so rr lands between 00 and 44.

    r=a−n×q=−17−5×(−4)=−17−(−20)=3\begin{aligned} r &= a - n \times q \\ &= -17 - 5 \times \left(-4\right) \\ &= -17 - \left(-20\right) \\ &= 3 \end{aligned}
  3. Result

    So −17 mod 5=3-17 \bmod 5 = 3.

Worked examples