Calcist

Style

Buttons

Spacing

How much to show

Decimal places

Text size

Modulo calculator

Find a mod n, the remainder after division, for numbers of any length. For negative numbers it shows the math, JavaScript and Euclidean answers side by side.

Whole numbers can have thousands of digits. Decimals like 5.5 work too.

Private: calculated on your device. Nothing you type is sent anywhere.

Next: Want the full division with the working? Use the long division calculator. Working in binary or hex? Try the programmer calculator.

What a mod n means

a mod n is the remainder after dividing a by n. Write a = n × q + r, where q is a whole number (the quotient) and r is the remainder.

a = n × q + r
Floored: q = floor(a ÷ n), r takes the sign of n
Truncated: q = a ÷ n rounded toward 0, r takes the sign of a
Euclidean: 0 ≤ r < |n|

For positive numbers all three give the same answer. They differ when a or n is negative. Math books and Python's % use the floored version, which matches modular arithmetic: −7 mod 3 = 2. JavaScript, C and Java's % operator truncates instead, so −7 % 3 is −1. The calculator shows all three so you can match whichever one you need.

Worked examples

17 mod 5: 17 ÷ 5 = 3.4, so q = 3. Then 17 − 5 × 3 = 17 − 15 = 2.

−7 mod 3: −7 ÷ 3 = −2.33. Floored, q = −3 and r = −7 − 3 × (−3) = −7 + 9 = 2. Truncated, q = −2 and r = −7 − 3 × (−2) = −1. Both are correct under their own rule, and they differ by exactly 3.

Big numbers: 2¹⁰⁰ = 1,267,650,600,228,229,401,496,703,205,376. Since 2³ = 8 = 7 + 1, every third power of 2 is 1 more than a multiple of 7, and 2¹⁰⁰ = 2 × (2³)³³. So 2¹⁰⁰ mod 7 = 2. The calculator uses exact big-integer arithmetic, so it gets this from all 31 digits without rounding.

Where mod is used

  • Clock time: 15:00 is 15 mod 12 = 3 o'clock. 100 hours from now is 100 mod 24 = 4 hours later on the clock, 4 days on.
  • Days of the week: 30 days after a Monday is 30 mod 7 = 2 days later, a Wednesday.
  • Even and odd: n mod 2 is 0 for even numbers and 1 for odd ones.
  • Programming: wrapping around a list, alternating rows, check digits and hashing.

Limitations

  • mod 0 isn't defined, just like division by 0.
  • Numbers can have up to 5,000 digits. Decimals are handled exactly too, using the same rules: 5.5 mod 2 = 1.5.
  • Spreadsheets differ: Excel's MOD follows the floored rule (the result has the sign of the divisor).

Sources

How we checked this

Before every update, this calculator is run in a real browser with these known answers, and it must match all of them:

  • 17 mod 5 = 2 ✓
  • −7 mod 3 = 2 (floored), quotient −3 ✓
  • −7 % 3 = −1 in JavaScript (truncated) ✓
  • 7 mod −3: Euclidean remainder 1 ✓
  • 2^100 mod 7 = 2, using all 31 digits ✓
  • Decimals: 5.5 mod 2 = 1.5 ✓
  • Edge: 100-digit numbers fit a phone screen: (10^99 + 1) mod 10^50 = 1 ✓
  • Edge: mod 0 is rejected ✓

Last checked October 26, 2026. Spotted something wrong? The math is done in your browser with the formula shown on this page, so you can check any result by hand.

Add this calculator to your website (free)

Paste this code into any web page. The calculator works on your page, resizes itself, has no ads and no tracking cookies, and nothing your visitors type is sent anywhere. More about embedding.

Questions people ask

How do you calculate a mod n?

Divide a by n, round the quotient down to a whole number, multiply back and subtract. 17 mod 5: 17 ÷ 5 = 3.4, so 17 − 5 × 3 = 2.

What is −7 mod 3?

2 in math and in Python (the floored rule): −7 = 3 × (−3) + 2. JavaScript's −7 % 3 gives −1 because it rounds the quotient toward zero.

Is mod the same as remainder?

For positive numbers, yes. With negative numbers, "remainder" usually means the truncated version (sign of the dividend), while "mod" usually means the floored version (sign of the divisor).

What is 0 mod n?

0, for any n that isn't 0, because 0 = n × 0 + 0.

What is a smaller number mod a bigger one, like 3 mod 5?

The smaller number itself: 3 mod 5 = 3, because 5 goes into 3 zero times with 3 left over.

Related calculators