Modulo Calculator
The remainder of a division. Shows both the maths answer and what a computer % gives for negatives.
How it works
The modulo operation gives the remainder after dividing a by n. For positive numbers it is simple: 17 mod 5 = 2. For negatives, mathematics and programming languages disagree, so the tool shows both: the maths answer (always 0 or positive for a positive n) and the result of % in C, Java and JavaScript (which keeps the sign of the dividend).
Worked example
-7 mod 3 is 2 in maths (because -7 = 3 x -3 + 2) but -7 % 3 is -1 in JavaScript. Python gives 2.
Good to know
- Modulo is how clocks wrap: 15 hours on a 12 hour clock is 15 mod 12 = 3.
- Even numbers are those with n mod 2 = 0.
- Used in hashing, circular arrays, check digits and cryptography.
Common questions
- Why is -7 % 3 negative in JavaScript?
- JavaScript truncates the quotient toward zero, so the remainder takes the sign of the dividend.
- What is the result of a mod 1?
- Always 0 for whole numbers.
- Can the divisor be negative?
- Yes. The tool shows the floor based result.
More in Utilities.
Find the date that is some days, weeks, months, years or working days from a date, and see the weekday and week number.
OPEN →Age CalculatorYour exact age in years, months and days, the day you were born, your next birthday, and the age gap with another person.
OPEN →Area ConverterConvert square metres, square feet, acres, hectares and more.
OPEN →