CalcGallery

Modulo Calculator

The remainder of a division under all three conventions programming languages use, which disagree for negative numbers, and modular powers done exactly.

Built by AbhiLast reviewed September 24, 2026

Division with remainder17 ÷ 5= 5 × 3 + 2

Your numbers

Result

Remainder, truncated: C, Java, JavaScript: 2

For whole numbers. The three conventions agree whenever both numbers are positive.

Remainder, floored: Python, Ruby
2
Remainder, Euclidean: never negative
2
Quotient, truncated
3
Report a problem with this calculator
Your entries are kept on this device only.

Results follow the mathematical operation and values shown. Check that you selected the intended operation, convention and dataset type before relying on the result. Read the full disclaimer

How to use the Modulo Calculator

  1. Enter the whole number to divide, a, and the number to divide by, b.
  2. Read the remainder under each of the three conventions, and the quotient.
  3. To raise a to a power e and take the remainder, choose the modular power and enter e.

The three conventions

truncated   r = a − b × trunc(a ÷ b)     takes the sign of afloored     r = a − b × floor(a ÷ b)     takes the sign of bEuclidean   r = a mod |b|, adjusted to 0 ≤ r < |b|

When a and b are both positive, all three give the same answer. They differ only when one or both is negative, which is exactly when a program ported from one language to another starts to misbehave.

Modular exponentiation

Squaring and reducing at each step keeps every intermediate number small, so a power with an exponent of a million is instant and exact. It is the operation at the heart of public-key cryptography.

With your numbers

  1. 17 = 5 × 3 + 2

Quick reference

For whole numbers. The three conventions agree whenever both numbers are positive.

Common math examples, worked out with this calculator's starting values.
ExampleResult
17 mod 5Remainder, truncated: C, Java, JavaScript: 2
−7 mod 3Remainder, truncated: C, Java, JavaScript: -1
7 mod −3Remainder, truncated: C, Java, JavaScript: 1
−7 mod −3Remainder, truncated: C, Java, JavaScript: -1
10 mod 5Remainder, truncated: C, Java, JavaScript: 0
2 to the 100, mod 7a to the e, mod b: 2

Common questions about the Modulo Calculator

Why does −7 mod 3 give different answers?
Because languages disagree on which way to round the quotient. JavaScript, C and Java truncate toward zero, so −7 ÷ 3 is −2 remainder −1. Python and Ruby round down, so it is −3 remainder 2. Mathematicians usually want a remainder that is never negative, the Euclidean one, which is also 2. All three are correct for their convention; the page shows each.
Which should I use?
Whichever your language or textbook uses. For clock arithmetic, array indexing that wraps around, or anything where a negative remainder would be a bug, the Euclidean remainder from 0 up to |b| − 1 is usually what you want.
How is a huge power taken mod a number?
By repeated squaring, taking the remainder at every step, so the numbers never grow larger than the modulus squared. 2 to the power 100, mod 7, is 2. Computing 2¹⁰⁰ in full first works here, but for most bases and large exponents the full power is far too big to hold exactly.
What about dividing by zero?
There is no remainder: division by zero is not defined, and the page says so.

Report a problem with this calculator