A Lot Of Tools
Toggle language
Toggle theme

Modulo Calculator

Calculate remainders, perform modular arithmetic, check congruence, and use practical applications like Luhn algorithm validation.

%Modulo Calculator

Calculate the remainder when a is divided by n. Result: a = q × n + r

How to Use the Modulo Calculator

Select an operation type: basic modulo, modular arithmetic, congruence check, or practical applications. Enter your numbers and click Calculate.

Calculator Modes

Basic Modulo

Calculate the remainder when dividing one number by another:

  • a mod n: The remainder when a is divided by n
  • Quotient: How many times n fits into a
  • Division Expression: a = q × n + r

Modular Arithmetic

Advanced modular operations used in cryptography and number theory:

  • Modular Exponentiation (b^e mod m): Calculate large powers efficiently
  • Modular Inverse (a⁻¹ mod m): Find x where a × x ≡ 1 (mod m)

Congruence Check

Two numbers a and b are congruent modulo m (written a ≡ b (mod m)) if they have the same remainder when divided by m. Equivalently, (a - b) is divisible by m.

Applications

Practical uses of modulo arithmetic:

  • Luhn Algorithm: Validate check digits for credit cards, ISBNs, IMEIs
  • Day of Week: Calculate the weekday for any date using Zeller's congruence

What is Modulo?

The modulo operation (mod) returns the remainder after division. For example, 17 mod 5 = 2 because 17 = 3 × 5 + 2. It's fundamental in computer science and mathematics.

Common Applications

  • Cryptography (RSA, Diffie-Hellman)
  • Hash functions and data structures
  • Check digit validation (credit cards, barcodes)
  • Circular buffers and wrap-around logic
  • Calendar calculations
  • Random number generation

Key Properties

  • (a + b) mod n = ((a mod n) + (b mod n)) mod n
  • (a × b) mod n = ((a mod n) × (b mod n)) mod n
  • a ≡ b (mod n) means n divides (a - b)
  • Modular inverse exists only when gcd(a, n) = 1

Worked Example: Modular Exponentiation

Suppose you need 7¹⁰ mod 13. Computing 7¹⁰ = 282,475,249 first would work here, but for cryptographic sizes (hundreds of digits) it is impossible. Instead, reduce at every step: 7² = 49 ≡ 10 (mod 13), 7⁴ ≡ 10² = 100 ≡ 9, 7⁸ ≡ 9² = 81 ≡ 3, and finally 7¹⁰ = 7⁸ × 7² ≡ 3 × 10 = 30 ≡ 4 (mod 13). This square-and-multiply method is exactly what the calculator uses, so it handles very large exponents instantly.

Frequently Asked Questions

What does a mod n mean and how is it calculated?+

a mod n is the remainder left over when a is divided by n. For example, 17 mod 5 = 2 because 17 = 3 × 5 + 2. Enter the dividend and the modulus in Basic mode and the calculator shows the remainder, the quotient, and the full division expression a = q × n + r.

How does modulo work with negative numbers?+

It depends on the convention. In mathematics, -7 mod 3 = 2 because the remainder is always taken in the range 0 to n-1, while many programming languages (C, JavaScript) return -1 because their % operator follows the sign of the dividend. Python follows the mathematical convention. Keep this in mind when comparing the calculator's result with code output.

What is a modular inverse and when does it exist?+

The modular inverse of a modulo m is the number x such that a × x ≡ 1 (mod m). For example, the inverse of 3 mod 11 is 4, since 3 × 4 = 12 ≡ 1 (mod 11). An inverse exists only when gcd(a, m) = 1; if a and m share a common factor, the calculator will tell you no inverse exists.

What is the Luhn algorithm mode used for?+

The Luhn algorithm is a mod-10 checksum used to validate credit card numbers, IMEI numbers, and many ID numbers. It doubles every second digit from the right, sums the digits, and checks whether the total is divisible by 10. Paste any card-style number into the Applications tab to verify its check digit.

Is this modulo calculator free and does it work offline in the browser?+

Yes. It is completely free with no sign-up, and every calculation — including modular exponentiation and inverse — runs entirely in your browser, so no numbers are sent to a server. It works on mobile, tablet, and desktop, and keeps working once the page has loaded even without a connection.