Modulo Calculator

The modulo operation gives the remainder after division. It is used in number theory, programming, cryptography and calendar calculations. Enter a dividend and divisor to get the remainder and quotient.

How it is calculated

Enter the dividend a.

Enter the divisor n.

Read the remainder and quotient.

Formula

Division algorithm: a = n × q + r, where 0 ≤ r < |n|

What is the Modulo Calculator?

The modulo operation answers a simple question: when you divide a by n, what is left over? The modulo calculator returns a mod n, the remainder, together with the quotient, and checks the result with a = n × q + r. It follows the mathematical convention, so the remainder is never negative even when a or n is negative.

Remainders are everywhere once you look: finding the day of the week some days ahead, telling the time on a 12-hour clock, checking whether a number is even or divisible by 9, calculating check digits in ISBN and credit card numbers, spreading data across servers by hashing, and in the RSA cryptography that secures online banking. Programmers use the % operator constantly, and number theory at school and in olympiads is built on modular arithmetic.

How to calculate it by hand

1. Write down the dividend a and the divisor n. The divisor cannot be 0.

2. For positive n, find the quotient q = floor(a ÷ n), the largest whole number with n × q not exceeding a.

3. Compute the remainder r = a − n × q.

4. Check that 0 ≤ r < |n| and that a = n × q + r.

5. For a negative dividend, floor rounds down, not towards zero: −7 ÷ 3 = −2.33, so q = −3 and r = −7 − 3 × (−3) = 2.

6. For clock or calendar problems, number the positions from 0, add the offset, and take the result mod 12, 24 or 7.

The division algorithm

For any integer a and any non-zero integer n, there is exactly one pair of integers q and r such that a = n × q + r and 0 ≤ r < |n|. This is called the division algorithm, and a mod n is defined as that r. Uniqueness matters: it means every integer falls into exactly one of |n| remainder classes. For n = 3 those classes are numbers leaving remainder 0, 1 or 2, and every integer belongs to one of them.

Congruence and clock arithmetic

Two numbers are congruent mod n, written a ≡ b (mod n), when they leave the same remainder, or equivalently when n divides a − b. Congruences can be added and multiplied like equations: if a ≡ b and c ≡ d, then a + c ≡ b + d and ac ≡ bd. This lets you find the last digit of 7^100 or a weekday years ahead without handling huge numbers. A 12-hour clock is arithmetic mod 12, and a week is arithmetic mod 7.

Negative numbers and programming languages

Languages disagree about negatives. In C, Java and JavaScript, −7 % 3 is −1, because they round the quotient towards zero. In Python, −7 % 3 is 2, matching the mathematical convention used here. For negative divisors this calculator also keeps the remainder non-negative, so its quotient may differ from what a program prints. The calculator's working line labels the quotient as floor(a ÷ n), but for a negative divisor the value it uses is actually −floor(a ÷ |n|); the remainder and the check line are still correct.

Worked example, step by step

Today is Monday, and Meenal wants to know which day of the week it will be exactly 100 days from now, counting Monday as 0 and Sunday as 6.

Quotient (chosen so the remainder is between 0 and |n| − 1): q = floor(100 ÷ 7) = 14

Remainder: 100 − 14 × 7 = 2

Check: 100 = 7 × 14 + 2

Answer: 100 mod 7 2; Quotient 14

Common mistakes to avoid

Expecting a negative remainder, as programming languages give, when the mathematical answer is non-negative.

Rounding a negative quotient towards zero instead of down, which gives the wrong remainder.

Numbering days or hours from 1 instead of 0, which makes clock answers off by one.

Trying to take a mod 0, which is undefined.

Using the calculator for decimals; the division algorithm is about whole numbers.

Where it is used

Finding the day of the week after a given number of days.

Converting 24-hour time to 12-hour time and adding hours on a clock.

Checking divisibility and finding last digits of large powers in olympiad problems.

Programming tasks such as alternating row colours, wrapping indexes and hashing.

Understanding check digits and the modular arithmetic behind RSA encryption.

Frequently asked questions

Why does −7 mod 3 give 2 and not −1?

Mathematics uses a non-negative remainder. Some programming languages return −1 for the % operator instead.

What is modulo used for?

Checking divisibility, clock and calendar arithmetic, hashing and cryptography.