NOTACAL logo

Modulo Calculator

Modulo Calculator

Give us your feedback! Was this useful?

Understanding the Modulo Operation

The modulo operation finds the remainder when one integer is divided by another. Represented as a mod b (read "a modulo b"), it answers the question: after dividing a by b, what's left over?

For example, 17 mod 5 = 2 because 17 ÷ 5 = 3 with a remainder of 2. [khan-modulo] While simple on its own, modular arithmetic is one of the most powerful concepts in mathematics — it underpins modern cryptography, computer science calendars, and even the logic behind everyday clocks.

The modulo operation is central to number theory. It describes a system of congruence classes: two numbers are congruent modulo n when they leave the same remainder upon division by n. [mathworld-mod] For instance, 17 mod 5 = 2 and 22 mod 5 = 2, so 17 ≡ 22 (mod 5). This simple equivalence relation unlocks the mathematics of cyclic groups, hash functions, ISBN check digits, and error-correcting codes.

Modular arithmetic predates modern algebra by centuries. The Chinese Remainder Theorem, discovered by Sunzi in the third century CE, was one of the earliest systematic uses of modular reasoning. It states that if you know the remainders of a number when divided by several pairwise coprime moduli, you can uniquely determine that number modulo the product of those moduli. This theorem remains relevant today in computer cryptography, where it is used in RSA decryption to speed up computations by breaking a large modulus into smaller factors and then recombining the results. [rosen-discrete]

The concept of congruence also provides a powerful framework for understanding cyclical phenomena across science and engineering. Any system that repeats after a fixed interval can be modeled using modular arithmetic, whether it is the phases of the moon, the rotation of a gear train, or the scheduling of traffic lights at an intersection. Identifying the modulo structure of a problem often simplifies it dramatically by reducing infinite possibilities to a finite set of residue classes, each behaving identically under the operation of interest.

Unlike most arithmetic operations taught in elementary school, modulo applies not just to positive numbers but to any integer. The operation has two common conventions: floored modulo (used in mathematics) always returns a non-negative remainder for any sign of a, while truncated modulo (used in many programming languages) takes the sign of the dividend. [brit-mod] Our calculator uses floored modulo, which ensures that a mod b always lies in the range [0, b−1].

Understanding which convention is in use matters significantly in practice. A programmer who expects floored modulo behavior but uses a language with truncated modulo will encounter subtle bugs, particularly when the dividend is negative. For this reason, many coding standards explicitly document which modulo variant applies, and some languages provide separate operators or library functions for each convention. The mathematical literature uniformly prefers floored modulo because it preserves the fundamental property that the remainder is always non-negative, which simplifies proofs and guarantees consistent behavior across all integer inputs. [mathworld-mod]

How to Use the Modulo Calculator

Using the modulo calculator requires only two inputs:

  1. Dividend (a) — the number you want to divide
  2. Divisor (b) — the number you divide by (must be positive)

The calculator displays the remainder instantly as you type. For best results, enter whole numbers — while the calculator accepts decimal inputs, integer modulo is the standard application.

Example 1: Basic calculation. Calculate 100 mod 7. Enter 100 as the dividend and 7 as the divisor. The calculator returns a remainder of 2, because 7 × 14 = 98, and 100 − 98 = 2.

Example 2: Large dividend. Calculate 10,000 mod 31. Enter 10000 as the dividend and 31 as the divisor. The remainder is 18 (31 × 322 = 9,982; 10,000 − 9,982 = 18). [crypto-corner] This type of calculation is common in checksum verification, where the remainder confirms that a long number has been transmitted without error.

Example 3: Negative dividend. Calculate −7 mod 3. With floored modulo, the result is 2. The reasoning: −7 ÷ 3 = −3 with remainder 2 (since 3 × (−3) = −9, and −7 − (−9) = 2). By contrast, truncated modulo would give −1 because −7 ÷ 3 = −2.333, truncated to −2, and −7 − (3 × −2) = −7 + 6 = −1. This difference matters whenever negative dividends appear in real-world calculations such as temperature differences or financial adjustments. [cornerstone-arithmetic]

The Modulo Formula

amodb=ab×aba \bmod b = a - b \times \left\lfloor \frac{a}{b} \right\rfloor
[rosen-discrete]

Where:

  • a is the dividend
  • b is the divisor (must be > 0)
  • x⌋ is the floor function, which rounds x down to the nearest integer

The floor function is what distinguishes floored modulo from truncated modulo. It ensures the remainder is always non-negative, which is the standard convention in mathematics and number theory. In programming languages like Python and Ruby, the % operator follows this convention, while languages like C, Java, and JavaScript apply truncated modulo where the remainder takes the sign of the dividend.

Worked example. Find 27 mod 12.

27mod12=2712×2712=2712×2=2724=327 \bmod 12 = 27 - 12 \times \left\lfloor \frac{27}{12} \right\rfloor = 27 - 12 \times 2 = 27 - 24 = 3

This is why 3 PM is three hours past noon on a 12-hour clock — modulo arithmetic governs our daily timekeeping.

Modular Arithmetic Reference Table

The table below shows the results of a mod 12 for various values of a. The 12-hour clock is the most familiar real-world application of modulo arithmetic.

Modulo 12 values for various dividends — all numbers in the same residue class share the same remainder
aa mod 2a mod 5a mod 10a mod 12
51055
120220
171275
2313311
311117
500002
1000004

Key observations. The mod 2 column tells you whether a number is even (remainder 0) or odd (remainder 1). The mod 10 column reveals the last digit of each number. These patterns make modulo arithmetic indispensable for digit-sum checks, divisibility rules, and data validation.

Practical Tips for Using Modulo Arithmetic

Leverage cyclical patterns. Modulo creates cycles of length b. If you need to repeat an action every b steps, use a mod b = 0 as your trigger. This is how scheduling algorithms, circular buffers, and round-robin load balancers work.

Use mod for validation. Credit card numbers, ISBN codes, and bank account numbers all incorporate a check digit computed via modulo arithmetic. The Luhn algorithm, for instance, uses mod 10 to detect single-digit errors and most adjacent digit swaps. [rosen-discrete]

Apply modulo to large-number problems. When only the remainder matters — such as determining whether a large number is divisible by another — modulo eliminates the need for full division. To test divisibility by 9, simply sum the digits repeatedly until a single digit remains; if that digit is a multiple of 9, the original number is too.

Understand clock arithmetic. The 12-hour clock is modulo 12 arithmetic applied to daily life. If it is 9 AM now, the time 8 hours later is 9 + 8 = 17 mod 12 = 5 PM. [khan-cryptography] This same principle extends to computing rotation periods, gear ratios, and modular exponentiation in cryptography.

Use modulo for calendar calculations. Determining the day of the week for any given date relies heavily on modulo arithmetic. The standard algorithm computes the number of days since a reference date and applies mod 7 to find the weekday. Leap year calculations also use modulo: a year is a leap year if it is divisible by 4 but not by 100, unless it is also divisible by 400 — a set of modular conditions that has governed the Gregorian calendar since 1582.

Apply modulo in game development. Video game programmers use modulo constantly for cyclic animations, looping backgrounds, and circular progress indicators. When a character's health bar should wrap around from full to empty and back, the underlying logic is a modulo operation. The classic game programming pattern for creating an array-based circular buffer — a fixed-size queue where elements wrap around to the beginning — is implemented entirely through modulo indexing: buffer[index % size]. [crypto-corner]

Combine modulo with exponentiation for cryptography. Modular exponentiation — computing a^ e mod n — is the core operation in the RSA and Diffie-Hellman cryptographic systems. These algorithms rely on the fact that while computing a^ e mod n is tractable even for enormous values (thousands of digits), reversing the operation to find e given a, n, and the result (the discrete logarithm problem) is computationally infeasible. This asymmetry is the foundation of secure communication on the internet. [khan-cryptography]

Limitations of the Modulo Operation

Divisor must be positive. The standard mathematical definition of modulo requires b > 0. When b = 0, division by zero is undefined, and negative divisors produce inconsistent results across different conventions.

Decimal inputs are non-standard. While our calculator accepts decimals, modulo is fundamentally an integer operation. The mathematical literature nearly always defines a mod b for integer a and positive integer b. Decimal modulo may produce floating-point rounding artifacts.

Two conventions exist. Floored modulo (our convention) and truncated modulo give different results for negative dividends. Always verify which convention your programming language or system uses before translating mathematical expressions into code.

Not a substitute for full division. Modulo tells you only the remainder, not the full result of division. If you need both quotient and remainder, perform integer division separately.

Frequently Asked Questions

What is the difference between mod and remainder?
In mathematics and in this calculator, 'mod' and 'remainder' are the same operation when using floored division. However, in some programming languages, the % operator returns a remainder with the sign of the dividend, which can differ from the floored modulo result for negative inputs.
Why does negative modulo give a positive result?
In floored modulo (the mathematical convention), the remainder is always in the range [0, b−1]. For -7 mod 3, we get 2 because -7 = -3 × 3 + 2. The result stays non-negative, which simplifies many proofs and algorithms in number theory.
How is modulo used in cryptography?
Modular arithmetic forms the backbone of RSA encryption, Diffie-Hellman key exchange, and elliptic curve cryptography. These systems rely on modular exponentiation — computing a^e mod n — which is tractable even when a, e, and n are enormous (hundreds of digits), while the reverse operation (discrete logarithm) remains computationally infeasible.
What does a ≡ b (mod n) mean?
The congruence a ≡ b (mod n) means that a and b differ by a multiple of n; in other words, a mod n = b mod n. It defines an equivalence relation that partitions the integers into n residue classes: 0, 1, 2, ..., n−1.
Can I use modulo with large numbers?
Yes — this calculator accepts up to ±999,999. For larger numbers, modular arithmetic remains efficient because the operation depends only on the remainder, not the size of the original number.
What is the difference between modulo and division?
Division gives both the quotient and remainder. Modulo gives only the remainder. For example, 17 ÷ 5 = 3 remainder 2. Division returns 3 and 2; modulo returns just 2.

References

  1. [1]Khan Academy — Intro to Modular Arithmetic
  2. [2]Weisstein, Eric W. — Congruence
  3. [3]Crypto Corner — Modular Arithmetic
  4. [4]Khan Academy — What is Modular Arithmetic?
  5. [5]Britannica — Modulo Operation
  6. [6]Rosen, K. H. — Discrete Mathematics and Its ApplicationsBuy on Amazon
  7. [7]Cornerstone Math — Remainders Explained

Last updated: July 28, 2026

1b

UnByte — Independent Software Engineering

Every calculator references authoritative sources — Editorial policy