Modulo Calculator
a mod n (all conventions), modular power and modular inverse.
About this tool
Enter a and n to see the remainder under all three conventions and the quotient. The second section computes bα΅ mod m, and the third finds aβ»ΒΉ mod m. All three accept integers of any size.
How modulo works
a mod n is the remainder after dividing a by n: 17 mod 5 = 2, because 17 = 3 Γ 5 + 2. It powers clock arithmetic (15:00 is 3 o'clock), days of the week, hash tables, check digits and cryptography. For negative numbers, definitions differ. Truncated division, used by the % operator in C, C++, Java and JavaScript, gives β7 % 3 = β1. Floored division (Python, Ruby) gives 2, taking the sign of n. The Euclidean definition preferred in maths always gives a remainder between 0 and |n| β 1, so here also 2. Modular exponentiation, bα΅ mod m, uses repeated squaring, so even 3^200 mod 13 (= 9) takes only a handful of steps; it's the core operation of RSA and DiffieβHellman. The modular inverse aβ»ΒΉ is the number that gives a Γ aβ»ΒΉ β‘ 1 (mod m), found with the extended Euclidean algorithm. It exists only when a and m are coprime: 3β»ΒΉ mod 11 = 4, but 4 has no inverse mod 8. The GCD and LCM calculator and the prime number checker are related.
Frequently asked questions
What is β7 mod 3?
2 in maths and Python (Euclidean or floored); β1 with the % operator in C, Java and JavaScript (truncated).
What is modular exponentiation?
Computing b^e mod m efficiently by repeated squaring, without calculating the huge number b^e.
When does a modular inverse exist?
Only when a and m share no common factor other than 1 (gcd = 1).
What is the modular inverse of 3 mod 11?
4, because 3 Γ 4 = 12 β‘ 1 (mod 11).
Is my data sent anywhere?
No. Everything is calculated in your browser, and nothing is stored or sent.