mod
✓ Editorially reviewed by Derek Giordano, Founder & Editor · BA Business Marketing

Modulo Calculator

Remainder After Division

Last reviewed: January 2026

🧮
500 calculators, no signup required
Finance · Health · Math · Science · Business
nnng.com

What Is a Modulo Calculator?

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.

Understanding the Modulo Operation

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.

Where Modulo Is Used

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.

Modulo Operation Examples

ExpressionResultExplanation
17 mod 5217 = 3×5 + 2
24 mod 6024 = 4×6 + 0 (evenly divisible)
100 mod 72100 = 14×7 + 2
-7 mod 32 (math) or -1 (CS)Convention varies

Understanding the Modulo Operation

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).

Modulo in Programming

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.

Modular Arithmetic in Cryptography

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.

Check Digits and Error Detection

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.

What is modular arithmetic?
Modular arithmetic treats numbers as "wrapping around" after reaching a modulus — like a clock that resets to 0 after 12. In mod 7 arithmetic: 5 + 4 = 9 ≡ 2 (mod 7). 6 × 6 = 36 ≡ 1 (mod 7). Two numbers are "congruent modulo n" (written a ≡ b mod n) if their difference is divisible by n. Modular arithmetic is the foundation of number theory and modern cryptography, and appears in everything from computer hashing to the Chinese Remainder Theorem used in secure communications.
Where is modular arithmetic used in everyday life?
Clock arithmetic is the most familiar example: 15:00 is 3:00 PM because 15 mod 12 = 3. Calendars use mod 7 to determine what day of the week a date falls on. Check digits in credit card numbers, ISBN codes, and barcodes use modulo operations to detect entry errors. Cryptographic systems (including the encryption securing your web browser right now) rely heavily on modular exponentiation. In programming, the modulo operator determines whether numbers are even or odd (n mod 2), distributes items across columns or rows, and implements circular buffers. Try it in our Scientific Calculator.
What is the modulo operator used for in programming?
Common uses include: checking even/odd (n % 2), cycling through array indices (index % array_length), formatting time (seconds % 60 for remaining seconds), hash table indexing, determining leap years ((year % 4 == 0) && (year % 100 != 0 || year % 400 == 0)), and distributing work across parallel processes. The modulo is one of the most frequently used operators after basic arithmetic.
How does modulo handle negative numbers?
It depends on the language. In Python, -7 % 3 = 2 (mathematical convention — result has same sign as divisor). In C/C++/Java/JavaScript, -7 % 3 = -1 (result has same sign as dividend). Both are valid definitions of remainder. This difference can cause bugs when porting code between languages, so always test modulo behavior with negative inputs.
What is modular arithmetic in cryptography?
RSA encryption relies on modular exponentiation: computing (message^e) mod n, where e and n are parts of the public key. The security comes from the fact that reversing this operation (finding the message from the encrypted value) requires factoring n into its two prime components, which is computationally infeasible for large n (2048+ bits). All HTTPS web traffic uses modular arithmetic for key exchange.

See also: GCD & LCM Calculator · Prime Number Checker · Factorial & Combinations Calculator

How to Use This Calculator

  1. Enter the dividend — Type the number being divided. This can be any integer — positive, negative, or zero.
  2. Enter the divisor (modulus) — Type the number to divide by. The modulo operation returns the remainder after integer division.
  3. Review the remainder — The calculator shows a mod b = r, where r is the remainder. For example, 17 mod 5 = 2 because 17 = 3×5 + 2.
  4. Understand the quotient relationship — The calculator also shows the integer quotient: a = q×b + r. This makes it clear how the remainder relates to the division.

Tips and Best Practices

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

📚 Sources & References
  1. [1] Khan Academy. Modular Arithmetic. KhanAcademy.org
  2. [2] NIST. Cryptographic Standards. NIST.gov
  3. [3] Wolfram MathWorld. Modular Arithmetic. MathWorld
  4. [4] MIT OCW. Mathematics for Computer Science. OCW.MIT.edu
Editorial Standards — Every calculator is built from peer-reviewed formulas and official data sources, editorially reviewed for accuracy, and updated regularly. Read our full methodology · About the author