Modulo Calculator (Modular Arithmetic, Inverse and Power)
Calculate a mod n, modular exponentiation (aᵉ mod n) and the modular inverse for whole numbers of any size, with the quotient and remainder.
How to use this calculator
Enter a whole number a, a positive modulus n and an exponent. The calculator gives the mathematical remainder (always between 0 and n − 1), the truncated remainder that many programming languages return for negative numbers, aᵉ mod n by fast exponentiation, and the modular inverse of a when it exists. Numbers can have hundreds of digits.
Formula
a mod n = a − n⌊a ÷ n⌋, in the range 0 to n − 1. Truncated remainder (C, Java, JavaScript %) = a − n × trunc(a ÷ n). aᵉ mod n uses repeated squaring. The inverse a⁻¹ satisfies a × a⁻¹ ≡ 1 (mod n); it exists only when gcd(a, n) = 1 and is found with the extended Euclidean algorithm.
Calculator credits
Calculator developmentJulia Edwards
Editorial supervisionSamad Aslam Khan
Expert reviewIfrahMSc Mathematics
Published byThe Calculatorz
Last updated
Read how we research, test, review and correct our calculators in our editorial policy.
Frequently asked questions
What does mod mean?
a mod n is the remainder when a is divided by n. 17 mod 5 = 2 because 17 = 3 × 5 + 2.
Why do calculators give different answers for negative numbers?
Mathematics uses a remainder between 0 and n − 1 (−17 mod 5 = 3), but many programming languages truncate toward zero (−17 % 5 = −2).
What is a modular inverse?
A number x such that a × x leaves remainder 1 when divided by n. It exists only if a and n share no common factor other than 1.
What is modular exponentiation used for?
Cryptography such as RSA and Diffie–Hellman, hashing and primality tests all compute huge powers modulo n efficiently.
Where is modular arithmetic used in daily life?
Clocks (hours mod 12), days of the week (mod 7), check digits in ISBNs and bank account numbers.
How large can the numbers be?
Any whole number; the calculator uses exact big-integer arithmetic.
References & methodology sources
These sources support the calculator’s formula, definitions, thresholds, units or result interpretation.
- Hardy, G. H., Wright, E. M., Heath-Brown, D. R., & Silverman, J. H. (2008). An introduction to the theory of numbers (6th ed.). Oxford University Press. View source
- Graham, R. L., Knuth, D. E., & Patashnik, O. (1994). Concrete mathematics (2nd ed.). Addison-Wesley. View source
- Olver, F. W. J., Lozier, D. W., Boisvert, R. F., & Clark, C. W. (Eds.). (2024). NIST Digital Library of Mathematical Functions. National Institute of Standards and Technology. View source
- OEIS Foundation. (n.d.). A000142: Factorial numbers. The On-Line Encyclopedia of Integer Sequences. View source