Modulo Calculator
Find a mod b, the remainder and the quotient, and see how negative numbers differ between Python and Excel and C, Java or JavaScript.
Was this tool helpful?
Thanks for the feedback!
This calculator finds a mod b: the remainder left when one number is divided by another, along with the quotient. It shows both conventions side by side, the floored modulo used by Python and Excel and the truncated remainder used by C, Java and JavaScript, so you can see exactly why the same sum gives different answers with negative numbers. It suits programmers, students learning modular arithmetic and anyone working out clock or calendar sums.
The fields
- Dividend (a): the number being divided, such as 17.
- Divisor (b): the number you divide by, such as 5.
Type plain digits with an optional minus sign and decimal point. Commas are not accepted here, so enter 1000 rather than 1,000, otherwise you see "Enter two numbers, the dividend and the divisor." Spaces at either end are ignored.
Floored modulo and truncated remainder
Every division can be written as a = b × q + r. The question is how q is rounded when the result is not whole.
- The floored version rounds q down, towards minus infinity. The remainder then has the same sign as the divisor. Python's
%operator and Excel'sMOD()work this way. - The truncated version cuts q towards zero. The remainder then has the same sign as the dividend. The
%operator in C, C++, Java and JavaScript works this way.
For two positive numbers the two agree. The tool's big result is the floored modulo, and the rows below list the floored modulo, the truncated remainder, both quotients and a check line that rebuilds the dividend. When either number is negative a note explains that the two conventions differ.
Worked examples
| Inputs | Floored (Python, Excel) | Truncated (C, Java, JS) | Quotients (floored / truncated) |
|---|---|---|---|
| 17 mod 5 | 2 | 2 | 3 / 3 |
| -17 mod 5 | 3 | -2 | -4 / -3 |
| 17 mod -5 | -3 | 2 | -4 / -3 |
| -17 mod -5 | -2 | -2 | 3 / 3 |
| 5.5 mod 2 | 1.5 | 1.5 | 2 / 2 |
Take -17 mod 5. Floored division gives q = -4, because -3.4 rounded down is -4, and the check line reads 5 × -4 + 3 = -17, so the modulo is 3. Truncated division gives q = -3 and a remainder of -2. If code ported from Python to JavaScript suddenly returns negative indices, this difference is usually the cause.
Some everyday uses:
- Days of the week: 100 mod 7 is 2, so 100 days after a Monday is a Wednesday.
- Clock time: 45 mod 24 is 21, so 45 hours after midnight is 9 pm.
- Even or odd: a number is even when n mod 2 is 0.
- Divisibility: 2026 mod 4 is 2, so 2026 is not divisible by 4 and is not a leap year. The full leap-year rule also treats century years separately.
Very large numbers and decimals
When both inputs are whole numbers and either has more than 15 digits, the tool switches to exact integer arithmetic so no digits are lost. In that mode it shows the floored modulo, the truncated remainder and the truncated quotient. For example, 123456789012345678901 mod 97 is 31, with a quotient of 1272750402189130710. Mod 97 on long numbers is the kind of sum used to check IBAN bank account numbers.
Decimals are handled in normal floating-point maths, which cannot store most decimal fractions exactly. That is why 0.3 mod 0.1 shows 0.1 instead of 0: the computer holds 0.3 as slightly less than three lots of 0.1. Python gives the same kind of result. For money, convert to paise first and use whole numbers.
A divisor of 0 gives "You cannot divide by zero." If you only want the plain decimal result of a division, the fraction to decimal calculator is quicker. For powers, including the large ones used in modular arithmetic, see the exponent calculator. Everything runs in your browser.
Frequently asked questions
What is 17 mod 5?
Why does -17 mod 5 give 3 in Python but -2 in JavaScript?
Does Excel MOD work like Python or like Java?
What is the difference between modulo and remainder?
Can I use modulo with decimal numbers?
How do I find what day it will be in 100 days?
Related guides
- Best Free Online Tools for Students in India (No Signup, 2026) Free browser tools for Indian students, sorted by task: essays, marks and CGPA, exam-form photos and PDFs, and study timers, with what each one can't...
- Age Limit for Exams: How to Calculate Your Age on the Cut-off Date Your age is checked on the cut-off date in the notice, not the day you apply. UPSC CSE 2026: 21–32 on 1 August 2026. How to check, relaxations, mistak...
- BMI for Indians: Why the Standard Chart Can Mislead You Indian expert guidelines put overweight at BMI 23 and obesity at 25, not 25 and 30. Read your BMI against Asian cut-offs, waist limits and the 2025 ch...