Skip to main content
Number tools100% FreeInstant

Modulo Calculator: a mod b with Remainder and Quotient

This free calculator finds a mod b for any whole numbers, including negatives and very large values. It shows the mathematical modulo, the truncated remainder used by many languages and the quotient.

By Debmedia Technologies LLP · Kolkata, India · Updated

What Is It and When Do You Need It?

The modulo operation is behind clocks, calendars, hashing and cryptography. It also trips people up when negative numbers are involved.

Enter two whole numbers.

How to Use This Tool

  1. Enter or paste your input in the box or boxes above.
  2. Choose the options, if there are any.
  3. Press the button to run the tool.
  4. Read the result and use the copy button where one is shown.

How the Calculation Works

The tool uses exact integer maths. The truncated quotient q rounds toward zero and the remainder is a - b x q. The floored quotient rounds down and the mathematical modulo is a - b x floor(a / b), which always has the sign of b. The check line shows that a = b x q + r.

Worked Example

17 mod 5 gives quotient 3 and remainder 2. -7 mod 3 gives a mathematical modulo of 2 (quotient -3) but a truncated remainder of -1 (quotient -2).

Common Uses

  • Programming and hashing.
  • Clock arithmetic.
  • Checking divisibility.
  • Cryptography homework.

Tips and Common Mistakes

  • b cannot be zero.
  • For clock maths with a 12-hour clock, use b = 12.
  • A mod of 0 means a divides evenly by b.
  • Check the first result against a case you already know, so you can trust the tool for the rest.
  • Nothing you type leaves your device. The work is done by your browser, so it also works with a slow connection once the page has loaded.

Next, you may need the GCD and LCM calculator, prime number checker, Fibonacci calculator, quadratic equation solver.

Everything runs in your browser. Nothing you type is uploaded, stored or sent to any outside service.

Frequently Asked Questions

It is the remainder after dividing a by b. 17 mod 5 is 2 because 17 = 3 x 5 + 2.
The mathematical answer is always between 0 and b - 1, so -7 mod 3 is 2. Many programming languages give -1 instead.
Languages differ. Python uses the mathematical (floored) result, while JavaScript, Java and C use the truncated result.
Yes. The tool uses exact whole-number arithmetic with no rounding.

Disclaimer: results are calculated in your browser from the numbers you enter. Check important results before you rely on them for money, health, safety or legal decisions.