Skip to main content

DigitalCalculators.net

Modulo Calculator

Find a mod n, the remainder after division, with the quotient and steps, and see how negative numbers work in math and in programming languages.

Results

ItemValue

Steps

StepWorking
Whole numbers of any size are exact. Decimals also work. For negative numbers, the two common rules give different answers, so both are shown.

Quick Answer

a mod n is the remainder when a is divided by n. 47 mod 5 = 2, because 47 = 5 × 9 + 2. For negative numbers, math and Python use the floored rule (−7 mod 3 = 2), while JavaScript, C and Java use the truncated rule (−7 % 3 = −1).

Last updated: 3 November 2026 ·How we calculate this: division with remainder

Table of Contents

How This Modulo Calculator Works

Enter the dividend a and the modulus n. The calculator divides a by n, takes the whole-number part of the quotient, and finds what is left over. It shows the floored remainder used in mathematics and Python, and the truncated remainder used by the % operator in JavaScript, C and Java, plus each quotient and the steps. Whole numbers of any length are handled exactly.

Quick explanation: mod is about what is left over.

  • 17 mod 5 = 2: 5 goes into 17 three times with 2 left.
  • Result range: for positive n, the floored result is from 0 to n − 1.
  • Clock math: 15:00 is 3 o'clock because 15 mod 12 = 3.

How to Use the Modulo Calculator

  1. Enter the dividend a.
  2. Enter the modulus n.
  3. Press Calculate.
  4. Read a mod n and both remainder rules.
  5. Check the steps to see the division.

Core Formulas

  • Definition: a = n × q + r
  • Floored: q = ⌊a ÷ n⌋, r = a − n × q (r has the sign of n)
  • Truncated: q = trunc(a ÷ n), r = a − n × q (r has the sign of a)
  • Same answer: both rules agree when a and n are positive

Key Terms

  • Modulo: the operation that finds the remainder after division.
  • Modulus: the number you divide by, n.
  • Dividend: the number being divided, a.
  • Floor: rounding down to the next whole number.
  • Congruent: two numbers are congruent mod n if they have the same remainder.

Worked Example

Find −7 mod 3.

  • −7 ÷ 3 = −2.333...
  • Floored: q = −3, r = −7 − 3 × (−3) = 2
  • Truncated: q = −2, r = −7 − 3 × (−2) = −1, which is what −7 % 3 gives in JavaScript

Real-Life Examples

  • Time: 100 hours from now is 100 mod 24 = 4 hours past this time, plus 4 days.
  • Day of the week: 30 days from Monday is 30 mod 7 = 2 days later, Wednesday.
  • Programming: cycle through a list with index mod length.
  • Check digits: ISBN and other codes use mod 10 or mod 11 checks.

Modulo vs Remainder

  • Modulo (floored): the result takes the sign of the divisor.
  • Remainder (truncated): the result takes the sign of the dividend.
  • For positive numbers: they are the same.

Modulo Examples

anFloored (math)Truncated (JS %)
17522
47522
100722
-732-1
7-3-21
-7-3-1-1
24600
365711

Tips

  • Even or odd: n mod 2 is 0 for even numbers and 1 for odd ones.
  • Divisibility: a mod n = 0 means n divides a evenly.
  • Positive results in code: use ((a % n) + n) % n to get the floored result.
  • Large numbers: this calculator handles long whole numbers exactly.

Modulo is also the heart of modular arithmetic, where numbers wrap around like the hours on a clock. Two numbers are congruent mod n when they leave the same remainder, written 17 ≡ 2 (mod 5). This idea is used in calendars, hashing, cryptography and check digits on barcodes and bank numbers.

Common Mistakes to Avoid

  • Assuming every language gives the same answer. Negative numbers differ.
  • Using the quotient instead of the remainder. Mod gives what is left over.
  • Dividing by zero. a mod 0 is undefined.
  • Forgetting the range. With positive n, a floored result is always less than n.
  • Rounding instead of flooring. The quotient must be floored or truncated, not rounded.

Frequently Asked Questions

It gives the remainder after dividing one number by another. 10 mod 3 = 1.

Divide a by n, take the whole number part, multiply it by n, and subtract from a.

2, because 47 = 5 × 9 + 2.

With the math rule, −7 mod 3 = 2. With JavaScript's %, −7 % 3 = −1.

Python floors the quotient, while JavaScript truncates it toward zero.

Yes. 7.5 mod 2 = 1.5.

To tell even (0) from odd (1) numbers.

For positive numbers, a mod n = a. For example, 3 mod 10 = 3.

No. Division gives the quotient, and modulo gives the remainder.

Math where numbers wrap around after reaching n, like hours on a clock.

Yes. With the floored rule, the result then has the same sign as n.

The fractional part of a, for positive a. 5.25 mod 1 = 0.25.

References & Sources

SourceUsed ForLink
Wikipedia, Modulo Definitions, the floored and truncated rules, and how languages differ. https://en.wikipedia.org/wiki/Modulo
Wikipedia, Modular arithmetic Clock arithmetic and congruence. https://en.wikipedia.org/wiki/Modular_arithmetic