ZapKit

Modulo calculator

Get the remainder of a division, including the tricky negative cases where programming languages disagree, and work out large modular powers.

What is modulo?

Modulo, written mod or %, gives the remainder after dividing one number by another. It's behind clock and calendar arithmetic, alternating rows, checksums, hashing, cyclic buffers and cryptography, and comes up constantly in programming.

Enter a dividend and divisor to see the floored remainder used by Python, the truncated remainder used by JavaScript, C and Java, and the always-positive Euclidean remainder, each with its quotient where it applies. Add an optional power to calculate a modular exponent exactly with whole-number arithmetic.

How to use the Modulo calculator

  1. 1.Enter a and n

    The number to divide and the divisor.

  2. 2.Add a power if you need one

    For aᵉ mod n, used in cryptography.

  3. 3.Compare the conventions

    Floored, truncated and Euclidean results side by side.

Example: a negative dividend

−17 divided by 5, and a modular power:

Floored (Python)
3, quotient −4
Truncated (JavaScript)
−2, quotient −3
4¹³ mod 13
4

a = n × q + r

Python and JavaScript give different answers for the same sum, and the tool shows both.

Why languages disagree

For positive numbers every method agrees: 100 mod 7 is 2. With a negative dividend they split. Python and spreadsheets round the quotient down, so −17 mod 5 = 3. JavaScript, C, C++ and Java truncate towards zero, so −17 % 5 = −2. The Euclidean definition always gives a result from 0 up to the divisor.

Modular exponentiation works out huge powers like 4¹³ mod 13 without computing the full power, by squaring and reducing at each step. It's how RSA encryption and many hash functions work.

Frequently asked questions

Which result should I use for clock arithmetic?

Floored or Euclidean, which never go negative for a positive divisor.

How do I get a positive remainder in JavaScript?

Use ((a % n) + n) % n, which matches the Euclidean column.

Does it accept decimals?

Yes for remainders, like 7.5 mod 2 = 1.5. Powers need whole numbers.

What is a mod 0?

Undefined, because you can't divide by zero.

More Utilities tools