What is A modulo B?
Free online modulo calculator. Fast, accurate, and easy to use math tool.
- A mod B
- 2
17 mod 5 = 2.
- Quotient
- 3
A mod B: 2. 17 mod 5 = 2.
How to calculate
Finds the remainder of one number divided by another (A mod B), with the whole-number quotient.
Example with the default inputs (Dividend (A) 17, Divisor (B) 5, Remainder sign Floored): 17 mod 5 = 2.
Method: A mod B = A − B × ⌊A ÷ B⌋ (floored); truncated uses A ÷ B rounded toward 0 instead of ⌊A ÷ B⌋.
- The divisor B cannot be 0.
- Floored (the default) gives a result with the sign of B, as in Python and in mathematics. Truncated gives the sign of A, as in C, Java and JavaScript. Both agree when neither number is negative.
- Decimals are taken exactly as typed: 5.5 mod 2 = 1.5 and 2.4 mod 0.2 = 0.
Worked examples
Each example is checked against the calculator on every build.
- Dividend (A) 17, Divisor (B) 5, Remainder sign Floored gives A mod B 2, Quotient 3.Source: Ted Sundstrom, Mathematical Reasoning: Writing and Proof, §3.5 The Division Algorithm and Congruence (for integers a and b with b > 0 there are unique q and r with a = bq + r and 0 ≤ r < b, −17 = 5(−4) + 3). https://math.libretexts.org/Bookshelves/Mathematical_Logic_and_Proof/Book:_Mathematical_Reasoning__Writing_and_Proof_(Sundstrom)/03:_Constructing_and_Writing_Proofs_in_Mathematics/3.05:_The_Division_Algorithm_and_Congruence
- Dividend (A) -7, Divisor (B) 3, Remainder sign Floored gives A mod B 2, Quotient -3.Source: Ted Sundstrom, Mathematical Reasoning: Writing and Proof, §3.5 The Division Algorithm and Congruence (for integers a and b with b > 0 there are unique q and r with a = bq + r and 0 ≤ r < b, −17 = 5(−4) + 3). https://math.libretexts.org/Bookshelves/Mathematical_Logic_and_Proof/Book:_Mathematical_Reasoning__Writing_and_Proof_(Sundstrom)/03:_Constructing_and_Writing_Proofs_in_Mathematics/3.05:_The_Division_Algorithm_and_Congruence
- Dividend (A) -7, Divisor (B) 3, Remainder sign Truncated gives A mod B -1, Quotient -2.Source: Ted Sundstrom, Mathematical Reasoning: Writing and Proof, §3.5 The Division Algorithm and Congruence (for integers a and b with b > 0 there are unique q and r with a = bq + r and 0 ≤ r < b, −17 = 5(−4) + 3). https://math.libretexts.org/Bookshelves/Mathematical_Logic_and_Proof/Book:_Mathematical_Reasoning__Writing_and_Proof_(Sundstrom)/03:_Constructing_and_Writing_Proofs_in_Mathematics/3.05:_The_Division_Algorithm_and_Congruence
- Dividend (A) 7, Divisor (B) -3, Remainder sign Floored gives A mod B -2, Quotient -3.Source: Ted Sundstrom, Mathematical Reasoning: Writing and Proof, §3.5 The Division Algorithm and Congruence (for integers a and b with b > 0 there are unique q and r with a = bq + r and 0 ≤ r < b, −17 = 5(−4) + 3). https://math.libretexts.org/Bookshelves/Mathematical_Logic_and_Proof/Book:_Mathematical_Reasoning__Writing_and_Proof_(Sundstrom)/03:_Constructing_and_Writing_Proofs_in_Mathematics/3.05:_The_Division_Algorithm_and_Congruence
- Dividend (A) 5.5, Divisor (B) 2, Remainder sign Floored gives A mod B 1.5, Quotient 2.Source: Ted Sundstrom, Mathematical Reasoning: Writing and Proof, §3.5 The Division Algorithm and Congruence (for integers a and b with b > 0 there are unique q and r with a = bq + r and 0 ≤ r < b, −17 = 5(−4) + 3). https://math.libretexts.org/Bookshelves/Mathematical_Logic_and_Proof/Book:_Mathematical_Reasoning__Writing_and_Proof_(Sundstrom)/03:_Constructing_and_Writing_Proofs_in_Mathematics/3.05:_The_Division_Algorithm_and_Congruence
- Dividend (A) 2.4, Divisor (B) 0.2, Remainder sign Floored gives A mod B 0, Quotient 12.Source: Ted Sundstrom, Mathematical Reasoning: Writing and Proof, §3.5 The Division Algorithm and Congruence (for integers a and b with b > 0 there are unique q and r with a = bq + r and 0 ≤ r < b, −17 = 5(−4) + 3). https://math.libretexts.org/Bookshelves/Mathematical_Logic_and_Proof/Book:_Mathematical_Reasoning__Writing_and_Proof_(Sundstrom)/03:_Constructing_and_Writing_Proofs_in_Mathematics/3.05:_The_Division_Algorithm_and_Congruence
- Dividend (A) 1,000,000,000,000,000, Divisor (B) 7, Remainder sign Floored gives A mod B 6, Quotient 142,857,142,857,142.Source: Ted Sundstrom, Mathematical Reasoning: Writing and Proof, §3.5 The Division Algorithm and Congruence (for integers a and b with b > 0 there are unique q and r with a = bq + r and 0 ≤ r < b, −17 = 5(−4) + 3). https://math.libretexts.org/Bookshelves/Mathematical_Logic_and_Proof/Book:_Mathematical_Reasoning__Writing_and_Proof_(Sundstrom)/03:_Constructing_and_Writing_Proofs_in_Mathematics/3.05:_The_Division_Algorithm_and_Congruence
How it works
For a dividend A and a divisor B (not 0), the calculator uses the floored definition:
A mod B = A − B × ⌊A ÷ B⌋
where ⌊A ÷ B⌋ is A ÷ B rounded down to a whole number (the quotient). The result has the sign of B (or is 0) and is smaller than B in size.
With the truncated option, the quotient is A ÷ B rounded toward 0 instead, and the result has the sign of A. This is what the % operator does in C, Java and JavaScript. When A and B are both positive, the two agree.
Assumptions
- The divisor B cannot be 0.
- Decimals are allowed, and the same formula applies: 5.5 mod 2 = 1.5.
- Decimals are taken exactly as typed. Both numbers are multiplied by the same power of ten to make them whole, the whole-number division gives the quotient and the remainder, and the remainder is divided by that power of ten again. So 2.4 ÷ 0.2 is exactly 12 remainder 0. Whole numbers of any size up to about 1.8 × 10³⁰⁸ are exact; the remainder and the decimal quotient are then shown as 64-bit floats.
Worked examples by hand
17 mod 5. 17 ÷ 5 = 3.4, rounded down to 3. 17 − 5 × 3 = 2.
−7 mod 3, floored. −7 ÷ 3 = −2.33…, rounded down to −3. −7 − 3 × (−3) = −7 + 9 = 2.
−7 mod 3, truncated. −2.33… rounded toward 0 is −2. −7 − 3 × (−2) = −7 + 6 = −1.
7 mod −3, floored. 7 ÷ (−3) = −2.33…, rounded down to −3. 7 − (−3) × (−3) = 7 − 9 = −2.
5.5 mod 2. 5.5 ÷ 2 = 2.75, rounded down to 2. 5.5 − 2 × 2 = 1.5.
2.4 mod 0.2. Multiply both by 10: 24 mod 2 = 0, so 2.4 mod 0.2 = 0 (quotient 12).
10¹⁵ mod 7. 7 × 142,857,142,857,142 = 999,999,999,999,994, so 10¹⁵ mod 7 = 1,000,000,000,000,000 − 999,999,999,999,994 = 6.
Other questions people ask
What is modulo (mod) operation?
The modulo operation finds the remainder when one number is divided by another. For example, 17 mod 5 = 2, because when 17 is divided by 5, the remainder is 2. The modulo operation is also known as the remainder operation and is fundamental in number theory, computer science, and cryptography.
How do I calculate A mod B?
To calculate A mod B, divide A by B and find the remainder. The formula is: A mod B = A - (B × ⌊A/B⌋), where ⌊A/B⌋ is the floor division (integer division) of A by B. For example, to calculate 23 mod 7: 23 ÷ 7 = 3.285..., floor division gives 3, so 23 mod 7 = 23 - (7 × 3) = 23 - 21 = 2.
What is the difference between dividend and divisor in modulo?
In modulo operations, the dividend is the number being divided (A in A mod B), and the divisor is the number you're dividing by (B in A mod B). The result is the remainder after division. For example, in 17 mod 5, 17 is the dividend and 5 is the divisor, giving a remainder of 2.
What is this calculator useful for?
This modulo calculator is perfect for programming tasks, cryptography, clock arithmetic, determining even/odd numbers, hash functions, cyclic operations, and any mathematical operations that require finding remainders. It's essential for computer science, discrete mathematics, and number theory applications.
Can I use negative numbers in modulo calculations?
Yes, the calculator supports negative numbers. By default the result follows the mathematical (floored) definition, where the remainder has the same sign as the divisor (B). For example, −17 mod 5 = 3, and 17 mod −5 = −3. Some programming languages (C, Java, JavaScript) truncate instead, so the remainder has the sign of the dividend: -17 % 5 = -2. Pick truncated under Negative numbers to get that result.
What happens when the divisor is zero?
Division by zero is undefined in mathematics, so the calculator will show an error when the divisor (B) is zero. Always ensure the divisor is a non-zero number. This is a fundamental mathematical rule that applies to all division and modulo operations.
How is modulo used in programming and computer science?
Modulo is commonly used for: determining if a number is even (n mod 2 = 0), wrapping around arrays (index mod array_length), clock arithmetic (time mod 12), hash table implementations, cyclic buffers, random number generation, and many other applications in algorithms and data structures.
What are some real-world applications of modulo operations?
Modulo operations are used in: cryptography and encryption algorithms, digital signatures, hash functions, cyclic redundancy checks (CRC), time calculations (12-hour and 24-hour clocks), calendar calculations, music theory (octave relationships), and many other practical applications in science and engineering.
How does modulo relate to congruence in number theory?
In number theory, two numbers are congruent modulo n if they have the same remainder when divided by n. This is written as a ≡ b (mod n). For example, 17 ≡ 2 (mod 5) because both 17 and 2 have remainder 2 when divided by 5. This concept is fundamental in cryptography and abstract algebra.