Calculate modulo operations (a mod b) with step-by-step explanations. Perfect for programmers, math students, and anyone working with remainder calculations.
Where a is the dividend and b is the divisor
The number being divided (can be negative)
The number to divide by (cannot be zero)
Basic positive modulo
Clock analogy (1 o'clock)
Multiple circles
Programming example
Large number modulo
Small divisor
The modulo operation finds the remainder after division of one number by another. It's denoted as a mod b or a % b in programming.
Remember: The mathematical definition ensures the result is always non-negative when the divisor is positive.
Array index wrapping: i % array.lengthEven/odd check: n % 2 == 0Circular buffer: (index + 1) % bufferSizeHash table indexing: hash % tableSizeModular arithmetic: (a + b) mod mCryptography: RSA encryptionNumber theory: GCD calculationsCongruence relations: a ≡ b (mod m)Clock arithmetic: (hour + n) % 12Day of week: day % 7Circular patterns: step % cycleRemainder calculationsIn modular arithmetic, numbers repeat after the modulus. For example, with modulus 12, values 0 and 12 are equivalent, as are 1 and 13. This equivalence is why modular math is foundational in scheduling, cryptography, and hashing. It compresses an unbounded integer line into a predictable cycle.
Example: suppose your app displays items in pages of 8 cards. If the global item index is 27, the in-page slot is. That means item 27 appears in slot 4 (zero-based index 3). Another example: if a recurring task runs every 14 days, checking quickly tells you whether you're on run day (remainder 0) without date-heavy logic.
The biggest pitfall is negative numbers. Some languages return negative remainders, others return non-negative modulo values. If you're building cross-language systems, normalize with when so results stay inside . This avoids off-by-one bugs in arrays, game loops, and encryption code.
For manual checks, always verify with . If remainder falls outside the expected range, either the quotient or sign handling is wrong. Practicing this verification step makes debugging modulo-heavy algorithms much faster.