📐 Math & Science

Modulo Calculator

Find the remainder of a ÷ n — correctly for negative numbers too.

  • 3results: modulo, remainder, quotient
  • 100sof digits handled exactly
  • ±negative numbers supported
  • 0rounding — pure integers

—

Mathematical modulo (always ≥ 0)—
Remainder (sign of a, like % in JS/C)—
Quotient (floor)—

How to use the Modulo Calculator

  1. 1

    Enter the dividend a

    Any whole number, positive or negative. Spaces, commas and underscores are ignored.

  2. 2

    Enter the divisor n

    Any non-zero whole number.

  3. 3

    Read a mod n

    The headline shows the mathematical modulo and the check line a = q × n + r.

  4. 4

    Compare with your code

    The remainder tile matches the % operator in JavaScript, C, C++ and Java.

Features

Always non-negative modulo

The main answer is between 0 and |n| − 1, the convention used in number theory.

Programmer’s remainder

A second tile shows the truncated remainder, which keeps the sign of a.

Built-in check

The line a = q × n + r lets you verify the answer by multiplying back.

Huge numbers

Uses BigInt, so a 30-digit dividend gives an exact answer.

Forgiving input

Paste 1,000,000 or 1_000_000 — separators are stripped automatically.

Zero guard

n = 0 shows “Undefined” instead of crashing.

Who uses it — and for what

Developers

Debug wrap-around indexes, pagination and negative-number % bugs.

Students

Practise modular arithmetic for number theory and competitive exams.

Planners

Work out weekdays and clock times after a number of days or hours.

Crypto learners

Try the remainder steps behind RSA, hashing and check digits.

What modulo means

a mod n is the remainder after dividing a by n. 17 mod 5 = 2 because 17 = 3 × 5 + 2. Clocks are the everyday example: 15:00 is 3 o’clock because 15 mod 12 = 3. Modulo is used to check whether a number is even (n mod 2 = 0), to cycle through lists, to wrap angles, in check digits like ISBNs and IBANs, in hashing and throughout cryptography.

Negative numbers

Programming languages disagree about negative numbers. In mathematics (and Python’s %), −17 mod 5 = 3, always between 0 and n − 1, because −17 = −4 × 5 + 3. In JavaScript, C, C++ and Java, the % operator returns the remainder with the sign of the dividend: −17 % 5 = −2. The calculator shows both so you can match whichever your code or textbook uses, and it handles numbers hundreds of digits long with exact big-integer arithmetic.

Every result is calculated in your browser the moment you type, so you can change a number and see the effect instantly — ideal for checking homework, worksheets and exam practice. Results are shown to a sensible number of decimal places; very large or tiny values switch to scientific notation.

Step-by-step: modulo of a negative number

Find −17 mod 5 by hand, the way the calculator does it.

  1. Divide ignoring signs: 17 ÷ 5 = 3 remainder 2.
  2. Because a is negative, step one multiple further down: q = −4, so −4 × 5 = −20.
  3. Find what is left: −17 − (−20) = 3.
  4. Check: −17 = −4 × 5 + 3. The answer 3 lies between 0 and 4, as a modulo must.

The truncating rule used by C-family languages instead picks q = −3 (rounding towards zero), leaving −17 − (−15) = −2. Both statements are true equations; they just choose a different quotient. That is the whole source of the “negative modulo” confusion.

Negative divisors

The calculator’s main answer stays non-negative even when n is negative: 17 mod −5 is shown as 2, with 17 = −3 × −5 + 2. Languages differ here too — Python’s 17 % −5 gives −3 because Python’s result takes the sign of the divisor. If your code uses a negative divisor, compare carefully with the language’s documentation, and note that the “Quotient” tile is then not the floor of a ÷ n.

Modular arithmetic tricks students should know

Remainders can be added and multiplied before you finish the sum, which makes huge calculations easy:

  • (a + b) mod n = ((a mod n) + (b mod n)) mod n, and the same for multiplication.
  • Last digit = mod 10. The last digit of 7¹⁰⁰ is 7¹⁰⁰ mod 10. Powers of 7 end in 7, 9, 3, 1 and repeat every 4, and 100 mod 4 = 0, so the last digit is 1.
  • Casting out nines. A number mod 9 equals its digit sum mod 9. To check 1234 × 5678 = 7,006,652: 1234 mod 9 = 1, 5678 mod 9 = 8, and 1 × 8 = 8; the digits of 7,006,652 add to 26, and 26 mod 9 = 8. The check passes.
  • Divisibility. a mod n = 0 means n divides a exactly — 2024 mod 4 = 0, one of the leap-year rules.

Common mistakes

  • Confusing the quotient with the remainder — in 17 mod 5, the 3 is the quotient; the answer is 2.
  • Expecting a mod n to be bigger than n. It never is; if your answer is, subtract n until it is not.
  • Writing modulo of decimals: this tool takes whole numbers only. For 7.5 mod 2, multiply both by 10 (75 mod 20 = 15), then divide the answer by 10 to get 1.5.

Where modulo is used

Programmers use it to wrap an index round a circular buffer (i mod length), to alternate row colours (row mod 2), to split items into pages and to convert seconds into minutes and seconds. Calendars use it for weekdays and leap years. Check digits on ISBNs, credit cards and bank numbers all depend on remainders, and modern cryptography — RSA, Diffie–Hellman, elliptic curves — is built entirely on arithmetic modulo very large numbers. For finding common factors of two numbers, the LCM & GCD Calculator uses repeated modulo steps (Euclid’s algorithm), and the Long Division Calculator shows where a remainder comes from digit by digit.

Worked examples

What day is it 100 days after a Wednesday?

a = 100, n = 7 → 100 mod 7 = 2 (100 = 14 × 7 + 2). Fourteen whole weeks bring you back to Wednesday, and 2 more days lands on Friday.

One hour before 12 o’clock

a = −1, n = 12 → modulo 11, remainder −1, quotient −1. The modulo answer, 11 o’clock, is what a clock face shows; the −1 is what a plain % in JavaScript would give, a common source of “index out of range” bugs.

A 30-digit number mod 97

a = 123456789012345678901234567890, n = 97 → 52, with quotient 1272750402189130710322005854. Mod-97 arithmetic on long numbers is exactly how IBAN bank account numbers are validated.

Pro tips

  • In JavaScript, write ((a % n) + n) % n to get the always-positive modulo shown here (for positive n).
  • Hours after midnight: use n = 24 for the 24-hour clock and n = 12 for a 12-hour dial (where 0 means 12).
  • To test divisibility by any number, check whether the modulo tile shows 0.

Glossary

Modulus
The number you divide by in a mod n — here, n.
Congruent
Two numbers are congruent mod n if they leave the same remainder, written a ≡ b (mod n). For example 17 ≡ 2 (mod 5).
Euclidean division
Division where the remainder is always between 0 and |n| − 1, the convention of the main result here.
Truncated division
Division that rounds the quotient towards zero, so the remainder takes the sign of the dividend.

Frequently asked questions

What is 10 mod 3?

1.

What is −1 mod 5?

4 in mathematics; −1 with the JavaScript % operator.

Can n be zero?

No — division by zero is undefined.

Why does JavaScript give −2 for −17 % 5?

The % operator in JavaScript (and C, C++, Java) truncates the quotient towards zero, so the remainder keeps the sign of the dividend. The mathematical modulo is 3.

Can I use decimals?

No, both inputs must be whole numbers. Scale decimals up by a power of ten first, then scale the answer back down.

Is mod the same as remainder?

For positive numbers, yes. They differ only when a or n is negative, which is why the page shows both.

Found it useful? Share the Modulo Calculator:

Last updated 2026-11-28 · Built by Vinayak Agarwal · Part of Math & Science (42 tools)