Modulus Calculator: Quick, Simple, Reliable

Calculate the remainder when dividing two numbers

Worked example: positive numbers

Enter dividend 17, divisor 5. Long division: 17 ÷ 5 = 3 with a remainder — 5 × 3 = 15, and 17 - 15 = 2. So 17 mod 5 = 2. In code this is the same result you'd get from the % operator in JavaScript, Python, C, or most other languages when both operands are positive.

Worked example: negative dividend

This is where implementations diverge, and it's the reason this calculator computes the result in a specific way. Enter dividend -7, divisor 3. JavaScript's native % operator returns -1 for -7 % 3 (it keeps the sign of the dividend), which isn't the mathematical modulus most people expect. The calculator corrects for this using ((number % modulus) + modulus) % modulus: ((-1) + 3) % 3 = 2 % 3 = 2. So the displayed result is -7 mod 3 = 2, matching the mathematical convention where the result always shares the sign of the divisor (or is non-negative for a positive divisor) — while the "Programming Expression" box separately shows the raw -7 % 3 = -1 that JavaScript itself would return, so you can see both answers side by side.

Why this distinction matters

The mathematical modulus (always non-negative for a positive divisor) is what's used in clock arithmetic, hashing, and array-index wraparound. The raw language operator behavior varies — Python's % actually matches the mathematical convention already, while JavaScript, C, and Java's % follow the dividend's sign instead. Code that assumes one behavior while running under the other is a common source of off-by-sign bugs.

Constraints

A divisor of zero is rejected, since division by zero is undefined. Both inputs must be valid numbers; decimals are accepted and processed with the same formula.