Modulo Calculator

Find the remainder of a division (a mod n) under every common convention, including how negatives behave in different programming languages.

Quotient (q)
−4
Remainder (r)
3
a = n × q + r
−17 = 5 × (−4) + 3
Divides evenly?
No
−17 mod 53quotient −4, floored convention
  • With negative numbers, programming languages disagree. Check which convention your language uses (see the table).

Show the work

  1. Divide: −17 ÷ 5 = −3.4
  2. Round the quotient down (toward −∞). Quotient q = −4
  3. Remainder r = a − n × q = −17 − 5 × (−4) = 3
  4. Check: 5 × (−4) + 3 = −17 ✓
01234
On a clock with 5 positions (0 to 4), counting 17 steps backward from 0 lands on 3. That is what “mod 5” means.
All remainder conventions
ConventionQuotientRemainderUsed by
Floored (sign of divisor)−43Python %, Excel MOD, Ruby, R, math texts
Truncated (sign of dividend)−3−2C, C++, Java, JavaScript %, C#, Go, Rust
Euclidean (never negative)−43Number theory; Rust rem_euclid
Rounded (IEEE remainder)−3−2IEEE 754 remainder(), Python math.remainder

The modulo operation, written a mod n (or a % n in code), gives the remainder left when a is divided by n. It’s the arithmetic of clocks and calendars, of checksums and hash tables, of “every third row” and “odd or even”. With positive numbers everyone agrees on the answer. With negatives — or with decimals — calculators, spreadsheets and programming languages quietly disagree. This tool shows the result under all four common conventions so you can match the one you need.

How to use the modulo calculator

  1. Enter the dividend a — the number being divided.
  2. Enter the divisor n — the modulus. It can be negative or a decimal, but not zero.
  3. Choose the convention you want for the headline answer. The table underneath lists all four.
  4. For small whole-number moduli, a clock diagram shows where a lands when you count around n positions.

The definition

Every convention finds a quotient q and remainder r with:

a = n × q + r,    |r| < |n|

They differ only in how q is rounded:

Convention Quotient q Sign of r −17 mod 5
Floored ⌊a ÷ n⌋, rounded down Same as n 3
Truncated a ÷ n with decimals dropped Same as a −2
Euclidean Chosen so r ≥ 0 Never negative 3
Rounded (IEEE) a ÷ n to the nearest integer Either −2

Worked example: −17 mod 5

Divide: −17 ÷ 5 = −3.4

Floored: round down to q = −4; r = −17 − 5 × (−4) = 3

Truncated: drop the decimals, q = −3; r = −17 − 5 × (−3) = −2

Check both: 5 × (−4) + 3 = −17 and 5 × (−3) + (−2) = −17

The two answers differ by exactly 5, the modulus. That is always the case when the floored and truncated results disagree.

Which convention does my language use?

Language or tool Operator −17 mod 5
Python -17 % 5 3
Excel, Google Sheets =MOD(-17, 5) 3
JavaScript, TypeScript -17 % 5 −2
C, C++, Java, C#, Go -17 % 5 −2
Rust -17 % 5 / (-17i32).rem_euclid(5) −2 / 3
IEEE 754 remainder remainder(-17, 5) −2

A common bug: using % in JavaScript to wrap an index around an array of length 5 gives −2 for −17, which is not a valid index. The fix is ((a % n) + n) % n, which turns any truncated result into the floored one for positive n.

Modular arithmetic in everyday life

  • Clocks: 9 a.m. plus 50 hours is 9 + 50 = 59, and 59 mod 24 = 11 — so 11 a.m., two days later.
  • Days of the week: 100 days from a Monday is 100 mod 7 = 2 days later, a Wednesday.
  • Even and odd: n mod 2 is 0 for even numbers and 1 for odd ones.
  • Check digits: ISBN-10 and many ID numbers use mod 11 or mod 10 sums to catch typing errors.
  • Cryptography: RSA and similar systems do almost all their work mod a huge number; the modular inverse comes from the Euclidean algorithm.

Decimals and exactness

Binary floating point can’t store 0.1 exactly, so in many languages 0.3 % 0.1 returns about 0.09999999999999998 instead of 0. This calculator scales decimals to whole numbers before dividing, so the remainder is exact. For the quotient and remainder of ordinary long division with all the steps written out, see the long division calculator.

Frequently asked questions

What does mod mean?

a mod n is the remainder after dividing a by n. 17 mod 5 = 2 because 17 = 3 × 5 + 2. It's the arithmetic of clocks: 17 hours after midnight on a 12-hour clock reads 5, because 17 mod 12 = 5.

What is −17 mod 5?

It depends on the convention. In mathematics, Python and Excel, −17 mod 5 = 3, because −17 = −4 × 5 + 3. In C, Java and JavaScript, −17 % 5 = −2, because those languages truncate the quotient to −3.

Why do programming languages give different answers for negative numbers?

They round the quotient differently. Truncated division rounds toward zero, so the remainder takes the sign of the dividend. Floored division rounds down, so the remainder takes the sign of the divisor. Both satisfy a = n × q + r; they just pick different q.

Can I use mod with decimals?

Yes. 5.5 mod 2 = 1.5, because 5.5 = 2 × 2 + 1.5. The calculator works in exact decimals, so values like 0.3 mod 0.1 correctly give 0 instead of a floating-point leftover.

What is the difference between mod and remainder?

For positive numbers they are the same. For negatives, "mod" usually means the floored or Euclidean result (never negative for a positive modulus), while "remainder" in programming often means the truncated result, which can be negative.

Last reviewed October 2026 by the CalcFluent editorial team. How we check our calculators.