Compute the remainder when a is divided by n (a mod n)
Result
Quotient
Remainder a mod n
Step-by-Step Derivation
Modulo Formula
a = n × floor(a/n) + (a mod n)
Modulo arithmetic finds the remainder r when a is divided by n, where 0 ≤ r < |n|. Widely used in computer science for circular indexing and in cryptography.
⚠Note: The divisor n cannot be 0. Positive mod positive yields a positive remainder. For negative numbers, the result varies by definition; this tool uses the mathematical convention (positive remainder).
What Is Modulo Arithmetic?
Modulo arithmetic is a fundamental operation in number theory that finds the remainder when one integer is divided by another. It is widely used in computer science, cryptography, and everyday cyclic problems.
Remainder Definition
a mod n is the remainder r when a is divided by n, satisfying a = n×q + r and 0 ≤ r < |n|.
Cyclic Behavior
The result of modulo arithmetic cycles within the range [0, n-1], making it ideal for repeating patterns.
Day-of-Week Calculation
"What day of the week is it?" is a mod 7 application: if you know a day, adding N days gives (day+N) mod 7.
Cryptography
Public-key encryption algorithms like RSA heavily rely on modular exponentiation (ae mod n).
💡 Teaching Example: 17 ÷ 5 = 3 remainder 2, so 17 mod 5 = 2. -7 mod 3 = 2 (mathematical definition), i.e., -7 = 3×(-3) + 2.
Modulo arithmetic (a mod n) finds the remainder when a is divided by n, with the result in the range 0 to |n|-1. For example, 17 mod 5 = 2, meaning 17 ÷ 5 leaves a remainder of 2.
How is modulo calculated for negative numbers?▼
There are multiple definitions for negative modulo. This tool follows the mathematical convention of returning a positive remainder: -7 mod 3 = 2 (because -7 = 3×(-3) + 2).
What is modulo arithmetic used for?▼
Modulo is widely used for: hash table indexing (circular array indices), cryptography (RSA encryption), day/date calculations, and checksums (ISBN, Luhn algorithm).
Can the divisor be 0?▼
No. The divisor n cannot be zero because division by zero is mathematically undefined, making modulo arithmetic also undefined.
Free online calculators and tools covering mathematics, unit conversion, text processing, and daily life. Accurate, fast, mobile-friendly, and completely free to use.