Math

Modulo Calculator

Find the remainder of a division using the mathematical (floored) modulo.


Modulo Calculator

Advertisement

Find a mod b — the remainder left over after dividing a by b, using the standard mathematical (floored) definition of modulo.

How it works

The formula is a mod b = a − b × floor(a ÷ b). This “floored” modulo always returns a result with the same sign as the divisor b, which is the convention used in mathematics — some programming languages instead return a result with the same sign as the dividend a, which can look different for negative numbers.

What this does not include

This uses the mathematical convention throughout. If you’re checking a specific programming language’s `%` operator against negative numbers, note that not every language follows this same convention.

How to use this calculator

  1. Enter a.
  2. Enter b, the modulus.

A worked example

17 mod 5 = 2 — the remainder after dividing 17 by 5 three times.

−7 mod 3 = 2 — a negative dividend still returns a non-negative remainder under this convention.

10 mod −3 = −2 — a negative divisor flips the sign of the result.

What the variables mean

Variable Meaning
a The dividend
b The divisor

Edge cases worth knowing

Negative number modulo behaves differently across programming languages — some always return a non-negative result, others match the sign of the divisor. The second and third examples above show this calculator’s specific convention, which is worth checking against whatever system this result needs to match.

A divisor of zero has no defined remainder, so the calculator declines to show a result for that case.

Why is −7 mod 3 equal to 2, not −1?

Floored modulo always returns a result with the same sign as the divisor (here, positive 3), so the result must be a non-negative number less than 3 — 2 fits that requirement, while −1 does not.

What’s modulo used for?

Wrapping values around a fixed range (like clock arithmetic), checking divisibility, and cycling through a repeating sequence of indices are all common uses.

What happens if b is zero?

Modulo by zero is undefined, the same as ordinary division by zero — this calculator returns no result for that input.

Be the first to rate this

Written by

J. Adeyemi

Statistics writer

J. Adeyemi writes the statistics and probability calculators, from descriptive summaries through to distributions and conditional probability. The recurring theme is scope: each page states precisely which question it answers, because most statistical mistakes come from applying a correct formula to the wrong question. Related-but-different measures get separate pages rather than being quietly merged.

Reviewed by

T. Okafor

Calculator reviewer — mathematics

T. Okafor reviews the mathematics calculators, verifying algebraic correctness and, just as importantly, behaviour at the edges — division by zero, undefined results, and the floating-point cases where a formula technically returns a number that should be reported as undefined. Every test case is recomputed independently rather than taken on trust.

How we write and review

Related calculators