Skip to content
Omnikalc

Modulo calculator (a mod n) with the mathematical and the truncated remainder, quotient, sum and product

Enter a, n and an optional b to get a mod n, the truncated remainder, the floor quotient and the sum and product modulo n, including for negative numbers.

Updated on
Your inputs

Value out of range

Value out of range

Value out of range

Results

a mod n (always between 0 and n − 1)

2

Remainder with truncated division (as in most programming languages)
2
Floor quotient ⌊a / n⌋
176
(a + b) mod n
0
(a × b) mod n
3

The modulo operation gives the remainder of a division. The modulo calculator computes a mod n with the mathematical convention, the truncated remainder that programming languages use, the floor quotient and the sum and product modulo n, for positive and negative integers.

How the calculation works

  • Enter the integer a that you divide and the modulus n, which must be a positive integer.
  • Optionally enter a second integer b to compute the sum and the product modulo n.
  • The calculator gives a mod n with the mathematical convention, which is always between 0 and n − 1, even when a is negative.
  • It also shows the truncated remainder used by many programming languages, the floor quotient and the results of (a + b) mod n and (a × b) mod n.

Example

For a = 1,234 and n = 7, the floor quotient is 176 and 1,234 mod 7 = 2, because 1,234 = 7 × 176 + 2. With b = 89, which is 5 mod 7, (a + b) mod 7 is 1,323 mod 7 = 0 and (a × b) mod 7 is 109,826 mod 7 = 3. The same results come from using the residues, 2 + 5 = 7 ≡ 0 and 2 × 5 = 10 ≡ 3.

Why it matters

The calculator helps students of arithmetic and computer science, programmers who need to know how their language handles negative numbers, and puzzle lovers who work with clocks, calendars and cycles. It makes the difference between the mathematical and the truncated remainder clear.

Good to know

The calculator works with integers up to ten million in absolute value, so that the products stay exact. The modulus must be positive. Powers and modular inverses, which need many steps, are not included. Some languages define the modulo of negative numbers differently, so check your own language.

The GCD and LCM calculator finds common divisors and multiples, the remainder calculator divides numbers with a remainder, the factorial calculator multiplies consecutive integers, and the fraction calculator works with ratios of integers.

Frequently asked questions

What does a mod n mean?

The modulo operation gives the remainder when a is divided by n. In mathematics, a mod n is the number r between 0 and n − 1 such that a = n × q + r for an integer q. For example, 17 mod 5 = 2, because 17 = 5 × 3 + 2. Two numbers with the same remainder are called congruent modulo n.

What happens with negative numbers?

The mathematical convention always gives a result between 0 and n − 1, so −47 mod 12 = 1 because −47 = 12 × (−4) + 1. Many programming languages, such as C, Java and JavaScript, give the remainder of the truncated division, which has the sign of a and gives −11 here. Python gives the mathematical result. The calculator shows both.

How do I add and multiply modulo n?

You can reduce the numbers first and then add or multiply: (a + b) mod n = ((a mod n) + (b mod n)) mod n, and the same for products. This is the base of modular arithmetic, used for clocks, calendars, check digits, hashing and cryptography, because the numbers always stay small.

Where is the modulo operation used?

It is used to find the day of the week, to wrap around a clock (15 hours after 10 o’clock is 1 o’clock), to test if a number is even or divisible, to cycle through a list in a program, to compute check digits such as those of ISBN numbers and bank accounts, and in cryptography such as RSA.

Was this calculator helpful?

Thanks for your feedback!

Results are estimates provided for information purposes. They do not replace professional advice.