Modulo calculator

Enter a dividend and a modulus to get the remainder. Because languages disagree about negative numbers, you see the Euclidean, floored and truncated remainders side by side, with big-integer precision. A second mode computes a^b mod n.

A whole number, positive or negative, up to 1,000 digits. In power mode this is the base.
A whole number other than 0. In power mode it must be positive.
Used in power mode only. A whole number, 0 or more.
a mod n (Euclidean, never negative)3
Floored remainder (Python, sign of n)
3
Truncated remainder (C, Java, JavaScript %, sign of a)
-2
Quotient for the truncated remainder
-3
Quotient for the floored remainder
-4

Runs in your browser: nothing you enter is sent anywhere.

How to use it

  1. Choose remainder or modular power.
  2. Enter a and n (and the exponent e in power mode).
  3. The headline answer is the Euclidean remainder. The rows below show the other two conventions and their quotients.

How it works

The truncated remainder is the raw BigInt %. The floored remainder adds n when the raw remainder is nonzero and has the opposite sign from n. The Euclidean remainder adds |n| when the raw remainder is negative. Each quotient q satisfies a = n × q + r. Powers use square-and-multiply: for each bit of the exponent the running base is squared mod n.

Worked example

−17 mod 5:

  • Truncated: −17 = 5 × (−3) + (−2), remainder −2.
  • Floored and Euclidean: −17 = 5 × (−4) + 3, remainder 3.

And 2^100 mod 13: since 2^12 ≡ 1 (mod 13) and 100 = 8 × 12 + 4, the answer is 2^4 mod 13 = 16 mod 13 = 3.

Tips

  • When a is a multiple of n the remainder is 0 in every convention.
  • If a < n and both are positive, the remainder is just a.
  • Check your work: n × quotient + remainder must give back a.

Frequently asked questions

What does a mod n mean?

It is the remainder after dividing a by n. 17 mod 5 = 2 because 17 = 3 × 5 + 2. Clocks use it: 15 o'clock is 15 mod 12 = 3 o'clock.

Why do languages give different answers for negative numbers?

The remainder must satisfy a = n × q + r, and several choices of q work. Truncated division (C, Java, JavaScript) rounds q toward zero, so −17 % 5 = −2. Floored division (Python) rounds q down, giving 3. Euclidean always keeps 0 ≤ r < |n|, also 3. Floored and Euclidean differ only when n is negative.

Which one should I use?

For the mathematical "a mod n", for hashing and array wrap-around, or for clock arithmetic, use the Euclidean value, which is never negative. Use the truncated one to match what a C-style % operator returns.

What is modular exponentiation?

It is a^e mod n computed without writing out the huge number a^e. Square-and-multiply keeps every step below n², so 4^13 mod 497 = 445 is quick and so is an exponent with hundreds of digits. It underlies RSA and Diffie-Hellman.

Is there a size limit?

Numbers may have up to 1,000 digits. All arithmetic uses exact big integers, so there is no rounding or overflow, unlike a 64-bit % operator.

More in Math

All tools in this category: Math ·Updated November 3, 2026

Privacy choices

Google Analytics shows us which tools are used and whether they work. It may set cookies. Your choice is kept in this browser.