Modulo Calculator
Calculate the remainder when one number is divided by another, including the mathematical (always non-negative) convention.
What modulo means
The modulo operation returns the remainder after division — 17 mod 5 equals 2, since 17 divided by 5 is 3 with a remainder of 2. Modulo is fundamental to concepts like clock arithmetic (where hours wrap around after 12 or 24), checking if a number is even or odd (n mod 2), and cyclical patterns in programming.
This calculator shows two results because different systems handle negative numbers differently, and the distinction genuinely matters for some applications.
Why negative numbers give two different answers
Programming languages like JavaScript compute a 'remainder' that can be negative when the dividend is negative — for example, -7 % 3 equals -1 in JavaScript. Pure mathematics typically defines modulo to always return a non-negative result — the same operation would give 2 under the mathematical convention.
This distinction matters in programming when working with array indices or cyclical values, where a negative result can cause unexpected bugs — the 'mathematical modulo' formula shown here (adding the divisor and taking the remainder again) is a common technique to force a non-negative result in code.
Frequently asked questions
Why are there two different results shown?
Programming languages often return a negative remainder when the dividend is negative, while the pure mathematical definition of modulo always returns a non-negative result — both are 'correct' under their respective conventions, so this calculator shows both.
How is modulo used in programming?
Modulo is commonly used to check even/odd status, wrap array indices or angles within a fixed range, generate cyclical patterns, and implement hashing algorithms, among many other applications.