Skip to content

Modulo Calculator

Enter a dividend and a divisor to find the remainder. For negative numbers the calculator shows both common conventions, since programming languages differ.

Result

17 mod 5
2
Quotient (floored)
3
Check
5 × 3 + 2 = 17
Remainder with truncated division (C, Java, JavaScript %)
2
Quotient with truncated division
3

The first result takes the sign of the divisor, as in mathematics and in Python. The truncated form takes the sign of the dividend, as the % operator does in C, Java and JavaScript. The two agree when both numbers are positive.

Formula

  • a mod n = a − n × ⌊a ÷ n⌋
  • a = n × quotient + remainder, with 0 ≤ remainder < n for positive n

How the Modulo Calculator works

The modulo operation gives the remainder when one whole number is divided by another. Seventeen divided by five is three with two left over, so 17 mod 5 is 2.

Modular arithmetic wraps around like a clock. Hours are counted mod 12, and days of the week mod 7. It is the foundation of hashing, checksums and public-key cryptography.

Worked example

17 mod 5: 17 ÷ 5 = 3 remainder 2, because 5 × 3 + 2 = 17. So 17 mod 5 = 2.

Frequently asked questions

What is −7 mod 3?

In mathematics and Python it is 2, because −7 = 3 × (−3) + 2. In C, Java and JavaScript, −7 % 3 gives −1, because those languages truncate the quotient toward zero.

How do I tell if a number is even with modulo?

A number is even when n mod 2 equals 0 and odd when it equals 1.

Related calculators

All math and statistics calculators · All calculators

Related unit converters

Calculations run in your browser and nothing you enter is sent to a server. Results are provided for general information. Check critical figures independently before relying on them.

☕ Like this tool?

Buy me a coffee to support development

☕ Support UnitGenie

If this tool has been helpful, consider buying me a coffee to support development and keep it free for everyone!