Remainder After Division
Last reviewed: January 2026
A modulo calculator computes the remainder when one integer is divided by another. The modulo operation (often written as a mod b) is fundamental in computer science, cryptography, and number theory, and is used for tasks like determining even/odd numbers and cyclic patterns.
The modulo operation (mod) returns the remainder after integer division. For example, 17 mod 5 = 2 because 17 = 3×5 + 2. Modular arithmetic is fundamental to computer science, cryptography, and number theory.[1] In programming, the modulo operator (% in most languages) is used constantly: checking if a number is even (n % 2 == 0), wrapping array indices, implementing circular buffers, and generating hash values. Every programming language supports it natively.[2] Modular arithmetic powers RSA encryption — the most widely used public-key cryptography system relies on the difficulty of computing modular inverses for large prime numbers, securing nearly all internet commerce and communication.[3] Use the GCD/LCM Calculator for related number theory operations.
Clock arithmetic: 3:00 PM + 11 hours = 14 mod 12 = 2 (2:00 AM). Calendar: day of week for any date uses modulo 7. Cryptography: the RSA encryption algorithm relies on modular exponentiation. Programming: checking if a number is even (n mod 2 == 0), cycling through array indices, generating bounded random numbers, and hash functions all use modulo. Checksums (credit card numbers, ISBNs, barcodes) use modular arithmetic to detect transcription errors. The last digit of a credit card is a Luhn check digit calculated via modulo 10.
| Expression | Result | Explanation |
|---|---|---|
| 17 mod 5 | 2 | 17 = 3×5 + 2 |
| 24 mod 6 | 0 | 24 = 4×6 + 0 (evenly divisible) |
| 100 mod 7 | 2 | 100 = 14×7 + 2 |
| -7 mod 3 | 2 (math) or -1 (CS) | Convention varies |
The modulo operation (mod) returns the remainder after integer division. 17 mod 5 = 2 because 17 ÷ 5 = 3 with remainder 2 (since 3 × 5 = 15 and 17 − 15 = 2). In programming, the modulo operator is typically written as % (17 % 5 = 2 in JavaScript, Python, C, and Java). The result of a mod b always falls between 0 and b−1 (inclusive) when both operands are positive. This bounded output is what makes modulo so useful — it wraps values into a fixed range, creating cyclic patterns that appear throughout computing, mathematics, and everyday life.
Clock arithmetic is the most familiar modulo application. Hours cycle from 0 to 11 (or 1 to 12), so adding 5 hours to 10:00 gives 3:00, not 15:00 — that is 15 mod 12 = 3. Days of the week cycle modulo 7: if today is Wednesday (day 3 of 0-indexed week), then 10 days from now is (3 + 10) mod 7 = 6, which is Saturday. Calendar calculations, scheduling algorithms, and time-zone conversions all rely on modular arithmetic to handle the cyclical nature of time measurement. The same wrapping behavior applies to compass bearings (mod 360), color wheel positions (mod 360), and musical intervals (mod 12 for the chromatic scale).
Programmers use modulo constantly for tasks that require cyclic behavior or divisibility testing. Determining whether a number is even or odd is simply n % 2 — if the result is 0, the number is even; if 1, it is odd. Cycling through array indices uses index % array.length to wrap around to the beginning when the index exceeds the array size. Stripe patterns in UI tables alternate row colors using rowIndex % 2. Hash tables distribute entries across buckets using hash(key) % numberOfBuckets. Rate limiting uses timestamp % interval to determine when actions are allowed. Pagination calculates the number of pages as ceil(totalItems / itemsPerPage) and the items on the last page as totalItems % itemsPerPage.
Negative numbers introduce a subtlety: different programming languages handle negative modulo differently. In Python, −7 % 3 = 2 (the result always has the same sign as the divisor), while in C and Java, −7 % 3 = −1 (the result has the same sign as the dividend). This difference can cause bugs when porting code between languages. The mathematical definition favors Python's approach (the result is always non-negative when the divisor is positive), but C's approach is more consistent with truncated integer division. Being aware of this language-specific behavior prevents subtle errors in date calculations, circular buffer implementations, and cryptographic code where modular arithmetic must produce specific results.
Modern encryption relies heavily on modular arithmetic with extremely large numbers. RSA encryption computes c = m^e mod n, where m is the message (represented as a number), e is the public exponent (commonly 65537), and n is the product of two large primes (typically 2048+ bits). Decryption computes m = c^d mod n, where d is the private exponent. The security comes from the fact that computing d from e and n requires factoring n into its prime components — a problem believed to be computationally infeasible for sufficiently large n. Modular exponentiation (computing a^b mod n efficiently) uses the square-and-multiply algorithm, which performs at most 2 × log₂(b) modular multiplications rather than b−1 multiplications, making it practical even for exponents with thousands of digits.
Modular arithmetic powers the error-detection systems embedded in identification numbers you use daily. The last digit of a credit card number is a Luhn checksum calculated modulo 10: double every second digit from the right (subtracting 9 if the result exceeds 9), sum all digits, and the check digit makes the total divisible by 10. This catches 100% of single-digit transcription errors and most transposition errors (swapping two adjacent digits). ISBN-13 book codes use a similar weighted-sum modulo 10 check. UPC barcodes, bank routing numbers, and national identification numbers in many countries all use modular check-digit algorithms because they are computationally trivial yet catch the most common data-entry mistakes with high reliability.
See also: GCD & LCM Calculator · Prime Number Checker · Factorial & Combinations Calculator
→ Modulo is the "remainder" operation: 17 mod 5 = 2 because 17 ÷ 5 = 3 remainder 2. The result is always between 0 and (divisor − 1) for positive numbers. 100 mod 7 = 2. 365 mod 7 = 1 (which is why your birthday shifts by one day of the week each non-leap year).
→ Clock arithmetic is modular arithmetic. Hours work mod 12 (or mod 24 for military time). 15:00 in 12-hour time: 15 mod 12 = 3 PM. Days of the week work mod 7. Months work mod 12. If today is Wednesday (day 3) and you add 10 days: (3+10) mod 7 = 6 = Saturday.
→ Modulo is essential in programming and cryptography. Hash tables, checksums, and encryption algorithms all use modular arithmetic. ISBN check digits, credit card validation (Luhn algorithm), and even simple "is this number even?" checks (n mod 2 = 0) rely on modulo. Try related operations with our Number Base Converter.
→ Negative number modulo behavior varies by language. In Python, -7 mod 5 = 3 (result has the sign of the divisor). In C/Java, -7 % 5 = -2 (result has the sign of the dividend). Both are mathematically valid definitions, but they give different answers. Know which convention your language uses. See our Long Division Calculator for step-by-step division.
See also: Long Division Calculator · Number Base Converter · GCD/LCM Calculator · Prime Checker