# What is A modulo B?

Finds the remainder of one number divided by another (A mod B), with the whole-number quotient.

- Page: https://www.acalculator.org/math/mod-calculator
- JSON spec: https://www.acalculator.org/math/mod-calculator.json
- Version: de95bed6b84b

## Default answer

Example with the default inputs (Dividend (A) 17, Divisor (B) 5, Remainder sign Floored): 17 mod 5 = 2.

## Inputs

| Key | Label | Description |
| --- | --- | --- |
| dividend | Dividend (A) | The number being divided: A in A mod B. |
| divisor | Divisor (B) | The number to divide by: B in A mod B. It cannot be 0. |
| mode | Remainder sign | Which sign the result takes when a number is negative: floored follows the divisor, truncated follows the dividend. |

## Outputs

| Key | Label | Description |
| --- | --- | --- |
| remainder | A mod B | The remainder after dividing A by B a whole number of times. |
| whole | Quotient | How many whole times B fits into A: ⌊A ÷ B⌋, or rounded toward 0 when truncated. |

## Method

A mod B = A − B × ⌊A ÷ B⌋ (floored); truncated uses A ÷ B rounded toward 0 instead of ⌊A ÷ B⌋.

## Assumptions

- 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

1. dividend = 17, divisor = 5, mode = floored gives remainder = 2, whole = 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.
2. dividend = -7, divisor = 3, mode = floored gives remainder = 2, whole = -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.
3. dividend = -7, divisor = 3, mode = truncated gives remainder = -1, whole = -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.
4. dividend = 7, divisor = -3, mode = floored gives remainder = -2, whole = -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.
5. dividend = 5.5, divisor = 2, mode = floored gives remainder = 1.5, whole = 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.
6. dividend = 2.4, divisor = 0.2, mode = floored gives remainder = 0, whole = 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.
7. dividend = 1,000,000,000,000,000, divisor = 7, mode = floored gives remainder = 6, whole = 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.

## FAQ

### 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.

## Sources

- 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
