Modulo Calculator - Remainder, Modular Power & Modular Inverse
Modulo Calculator
a mod n done right, with negatives, decimals, powers and inverses
Three Conventions
Programming languages disagree on negative operands. See the truncated, floored and Euclidean answers together, with quotients.
Exact Decimals
Decimals are handled as exact numbers, so 0.3 mod 0.1 is 0, not the 0.0999… a float gives.
Modular Power and Inverse
Compute aᵇ mod n for huge exponents in an instant, or find the modular inverse used in cryptography.
Full Privacy
Everything is calculated in your browser.
Why Negative Numbers Cause Confusion
For positive numbers every convention agrees: 7 mod 3 = 1. With a negative dividend they split. In C, Java and JavaScript, −7 % 3 is −1 (the sign follows the dividend). In Python, Ruby and in mathematics, −7 mod 3 is 2 (the sign follows the divisor). The Euclidean remainder is always between 0 and |n|, which is what clock and calendar arithmetic want.
Modular exponentiation uses square-and-multiply, so 4¹³ mod 497 (which is 445) and exponents with hundreds of digits are instant. A modular inverse of a modulo n exists only when a and n share no factor, and it is the number x with a·x ≡ 1 (mod n), the key step in RSA and many other schemes.
Key Takeaways
- Unambiguous: Shows which convention gives which answer, so you can match your programming language.
- Huge numbers: Integers of any size work in the power and inverse modes.
- Clear errors: Division by zero and a missing inverse are explained rather than left blank.