Modulo Operations with Negative Numbers

Master the modulo of negative numbers with our calculator – simplify complex calculations instantly!

Clear
Remainder2PHP and C convention — sign follows the dividend
Least non-negative residue2the usual mathematical convention
Quotient (truncated)3
Floor division3
Check5 × 3 + 2 = 17
Divides evenly?No

The method

a mod n is the remainder after dividing a by n

Two conventions for negatives

−17 mod 5 is either −2 or 3, depending on the convention. Most programming languages truncate towards zero and give −2; mathematics and Python floor instead and give 3. Both satisfy a = qn + r; they differ in which q they pick. Number theory always wants the non-negative answer.