FREE TOOLS. ZERO LIMITS.
No Signup RequiredNo Watermarks
ToolzNova ยท Math calculators

Modulo Calculator Online

Work out a mod n, the remainder after division. Handles very large whole numbers, negative numbers and decimals, and shows both remainder conventions.

Modulo Calculator

Free modulo calculator that runs in your browser. Nothing is uploaded.

a mod n

For negative numbers, maths and Python use the floored result; JavaScript, C and Java use the truncated one.

How to use the modulo calculator

1Enter the dividend

The number being divided, a.

2Enter the divisor

The number you divide by, n. It canโ€™t be zero.

3Read the result

See a mod n, the quotient and a check line.

Modulo examples

a mod n is what is left after taking away as many whole nโ€™s as possible: a = n ร— q + r.

With negatives, the two common conventions give different answers.

CalculationFloored (maths, Python)Truncated (JS, C, Java)
17 mod 522
โˆ’17 mod 53โˆ’2
17 mod โˆ’5โˆ’32
5.5 mod 21.51.5

Understanding modular arithmetic

This short guide explains what the modulo calculator does, how to get the best result and when another tool is a better fit.

What modulo means

Modulo is the remainder after division. 17 divided by 5 is 3 with 2 left over, so 17 mod 5 = 2. It is often called clock arithmetic, because clocks wrap around: 10 hours after 17:00 is 27:00, and 27 mod 24 = 3, so it is 03:00. Calendars, angles and repeating patterns all use the same idea.

Modulo Calculator โ€“ a รท n to mod
How the modulo calculator works: a รท n in, mod out.

If a mod n = 0, then n divides a exactly.

Negative numbers

For negative numbers there are two common rules. The floored rule, used in maths and Python, always gives a result with the same sign as the divisor, so โˆ’17 mod 5 = 3. The truncated rule, used by the % operator in JavaScript, C and Java, keeps the sign of the dividend, giving โˆ’2. The calculator shows both so you can match the language youโ€™re using.

When both answers agree, youโ€™ll see the same number twice.

Big numbers and checks

Whole numbers of any length are handled exactly using big integer maths, so 123456789012345678901234567890 mod 97 gives the precise answer, 52. The check line, n ร— q + r = a, proves the result. Decimals use normal floating-point maths and are rounded to 12 significant digits to hide tiny rounding errors.

Spaces and commas in long numbers are ignored.

Practical uses

Programmers use modulo to test for even numbers (n mod 2), wrap list indexes and spread items across servers. Check digits on IBANs, ISBNs and many ID numbers are calculated with modulo, often mod 10, 11 or 97. Teachers use it to split pupils into groups and find who is left over.

Example: 25 pupils in groups of 7 gives 3 full groups and 25 mod 7 = 4 left over.

Related tools

For quotient and remainder together, try the Remainder Calculator. For lowest common multiples, use the LCM Calculator.

  • a = n ร— q + r
  • Floored and truncated results differ for negatives
  • Huge whole numbers are exact

Further reading: The modulo operation. It explains the format behind this modulo calculator in more detail.

Popular uses

Programming

Wrap indexes and test parity.

Clock maths

Add hours past midnight.

Check digits

IBAN and ISBN checks.

Homework

Remainder questions.

Quick fixes

โ€œThe divisor canโ€™t be zeroโ€

Division by zero isnโ€™t defined; use a non-zero n.

โ€œEnter valid numbersโ€

Use digits, an optional minus and one decimal point.

Answer differs from my code

Your language may use the truncated rule; see that row.

Decimal result slightly off

Decimals are rounded to 12 significant digits.

Frequently asked questions

What is modulo?

The remainder after dividing one number by another.

What is 17 mod 5?

2.

What is โˆ’17 mod 5?

3 by the floored rule, โˆ’2 by the truncated rule.

Why do languages differ?

They use different conventions for negative numbers.

Can I use decimals?

Yes.

Can I use very large numbers?

Yes, whole numbers of any size are exact.

What does a mod n = 0 mean?

n divides a exactly.

Can the divisor be zero?

No.

Is my data saved?

No.

What is modular arithmetic used for?

Clocks, check digits, programming and cryptography.