Skip to content
Calculator Tools
Basic Math Calculators

Modulo Calculator

Calculate a mod n for positive and negative numbers using the mathematical (always non-negative) definition.

Enter values

Results update as you type.

Result

-17 mod 5

3

Truncated remainder (JavaScript/C %)
-2
Step-by-stepShow
  1. -17 = 5 × -4 + 3

About the Modulo Calculator

Calculate a mod n for positive and negative numbers using the mathematical (always non-negative) definition.

Also known as: mod calculator, modulus calculator, a mod b, modular operation.

How to use this calculator

  1. Enter a, n (modulus).
  2. The result updates instantly as you type — press Calculate (or Enter) at any time.
  3. Open “Step-by-step” to see how the answer was worked out.
  4. Use Copy result or Share to save the answer or send a link with your inputs.

Formula

a mod n = a − n × ⌊a / n⌋

Worked example

Using the values pre-filled in the calculator above:

  • a = -17
  • n (modulus) = 5

the calculator returns:

  • -17 mod 5: 3
  • Truncated remainder (JavaScript/C %): -2

Working

  1. -17 = 5 × -4 + 3

Frequently asked questions

Why does −17 mod 5 give 3 and not −2?

Mathematically, the result of a mod n (for positive n) is always between 0 and n − 1. Many programming languages instead return a truncated remainder (−2), which keeps the sign of the dividend.