Modulo Calculator
The modulo (or “mod”) operation returns the remainder after integer division: 17 mod 5 = 2 because 17 = 3·5 + 2. It’s the heart of clock arithmetic, cryptography, hash functions and the “every Nth row” pattern in SQL. This calculator accepts integer or decimal operands, shows the quotient and remainder explicitly, and handles the sign-convention differences between languages (Python’s % ≠ C’s % for negatives).
How to compute a mod b
-
1
Enter dividend (a) and divisor (b)
Any numbers; decimals and negatives OK.
-
2
Pick sign convention
Truncated division (C, Java, Go), floored division (Python, Ruby, math convention).
-
3
Read quotient and remainder
a = q·b + r, with the chosen rule for sign of r.
-
4
See the math expression
Substituted values make each step visible.
Two conventions for negative numbers
For positive operands, all conventions agree: 17 mod 5 = 2. For negatives, languages differ:
| Language | -17 mod 5 |
Convention |
|---|---|---|
| Python, Ruby | 3 | Floored |
| C, Java, Go, JS | -2 | Truncated |
| Math textbooks | 3 | Floored (usually) |
Floored division: quotient rounds toward −∞. Remainder always has the sign of the divisor: same-sign as b.
Truncated division: quotient rounds toward zero. Remainder has the sign of the dividend: same-sign as a.
For a = -17, b = 5:
- Truncated: q = -3 (rounded toward 0), r = -17 − (-3)·5 = -2.
- Floored: q = -4 (rounded toward -∞), r = -17 − (-4)·5 = 3.
Both are correct given the convention. Pick to match your language.
Where modulo shows up
- Time. Minutes in an hour, days of the week, seconds in a day, all mod arithmetic.
- Hash tables.
hash(key) mod table_sizepicks a bucket. - Round-robin scheduling.
task_i mod worker_countassigns work. - Cryptography. RSA and Diffie-Hellman are built on mod
nwith huge primes. - Every Nth row. In SQL:
WHERE id % 3 = 0. - Even/odd check.
n mod 2 == 0means even. - Alternating patterns. Row striping, coloring every other item.
- Circular buffers.
(index + 1) mod sizewraps around.
Useful identities
(a + b) mod n = ((a mod n) + (b mod n)) mod n(a · b) mod n = ((a mod n) · (b mod n)) mod n(a^k) mod ncan be computed by fast modular exponentiation in O(log k), critical for large-number crypto.a mod 1 = 0for any integer a.a mod a = 0.
Decimal modulo
For real numbers, the natural definition is a mod b = a − b · floor(a/b). 7.5 mod 2.5 = 0 because 7.5 is an exact multiple. 7.6 mod 2.5 = 0.1.
JavaScript’s % operator works on real numbers; Python’s fmod does truncated real mod; Python’s % does floored real mod.
Worked examples
100 mod 7: 100 = 14·7 + 2, so remainder 2.25 mod 4: 25 = 6·4 + 1, so remainder 1.-10 mod 3(floored):-10 = -4·3 + 2, remainder 2. (Truncated would give-1.)17.5 mod 5: 17.5 = 3·5 + 2.5, remainder 2.5.
Frequently Asked Questions
Most of the time they’re synonyms. Formally, “modulo” often implies the mathematical (floored) convention, while “remainder” often refers to the truncated (C-style) variant. The names leak into language docs; when it matters, spell out the convention.
Python follows the math convention (floored), which keeps the remainder’s sign matching the divisor. C follows the hardware ALU convention (truncated), where the remainder’s sign matches the dividend. Neither is wrong; they’re different choices.
No, division by zero is undefined. The calculator returns an error for b = 0.
Usually, yes. Check your language’s spec for negative-number handling, Python and Ruby differ from C, Java, Go and JavaScript.
For RSA-style math with 2048-bit numbers, use a dedicated library (Python’s pow(a, b, n), Java’s BigInteger.modPow). This calculator handles everyday values, not crypto-grade ones.
Related Tools
BMI Calculator
Calculate body mass index from height and weight. Shows WHO category, healthy-weight range and limitations of BMI.
Social Security Calculator
Estimate a US Social Security retirement benefit from your PIA and claiming age. Compare monthly and annual amounts at 62, FRA 67 and 70.
Age Calculator
Calculate exact age in years, months and days from a birth date, plus total days, hours and the next birthday countdown.
Dog Age Calculator
Convert your dog's age to human years using modern veterinary research. Breed-size aware: small, medium and large dogs age differently.
Fahrenheit to Celsius Converter
Convert Fahrenheit temperatures to Celsius with the exact formula, Kelvin output and common reference points for weather, cooking and health.
Time Zone Converter
Convert a time between any two time zones, with daylight-saving shifts applied automatically.
Tool available in other languages
- Calculadora de Módulo [ES]
- Calculateur de Modulo [FR]
- 剰余計算機 [JA]
- Calculadora de Módulo [PT]
- Modulokalkylator [SV]
- เครื่องคำนวณโมดูโล (Modulo) [TH]
- Máy tính modulo [VI]
- حاسبة باقي القسمة (Modulo) [AR]
- Modulo-Rechner [DE]
- 모듈로 계산기 [KO]
- Kalkulator Modulo [ID]
- Modulo-calculator [NL]
- Kalkulator modulo [PL]
- Калькулятор остатка от деления [RU]
- Modulo Hesaplayıcı [TR]
- 取模计算器 [ZH]
- Calcolatore Modulo [IT]