BYTETOOLS

Modulo Calculator

Calculate a mod n and the quotient online, with correct handling of negative numbers. See both the truncated remainder and the floored mathematical modulo.

-1
Truncated (a % n)
2
Floored (mathematical)
-2
Quotient

How it was computed

-7 % 3 = -1 (truncated, keeps sign of dividend)

((-7 % 3) + 3) % 3 = 2 (floored, matches sign of divisor)

What is the Modulo Calculator?

The ByteTools Modulo Calculator computes the remainder of a divided by n, along with the quotient. Crucially, it shows both conventions for negative numbers: the truncated remainder that most programming languages return and the floored, always-non-negative modulo used in mathematics.

  • Remainder and quotient of a ÷ n
  • Truncated remainder (JavaScript % behaviour)
  • Floored mathematical modulo, always non-negative
  • Correct, explicit handling of negative operands
  • Guards against a zero divisor
  • 100% private — runs entirely in your browser

How to use the Modulo Calculator

  1. 1

    Enter the dividend a.

  2. 2

    Enter the divisor n (the modulus).

  3. 3

    Read the truncated remainder as returned by most languages.

  4. 4

    Compare the floored, mathematical modulo and the quotient.

  5. 5

    Click Copy to grab the results.

About the Modulo Calculator

The ByteTools Modulo Calculator computes the remainder of a divided by n, along with the quotient. Crucially, it shows both conventions for negative numbers: the truncated remainder that most programming languages return and the floored, always-non-negative modulo used in mathematics.

It is aimed at programmers, students and anyone who has been caught out by −7 mod 3 giving different answers in different languages. Seeing both results side by side removes the confusion and explains which convention each uses.

Every calculation runs in your browser with JavaScript. No numbers are uploaded, so the tool is private, instant and works offline. Copy the results with one click.

Frequently asked questions

What is the modulo operation?

Modulo gives the remainder after dividing one number by another. For 17 mod 5, seventeen divided by five is three remainder two, so the result is 2. It is widely used for cycles, hashing and checking divisibility.

Why do negative numbers give different modulo results?

There are two conventions. The truncated version, used by JavaScript and C, keeps the sign of the dividend, so −7 % 3 = −1. The floored version, used in Python and mathematics, matches the sign of the divisor, so −7 mod 3 = 2. This tool shows both.

What is the difference between remainder and modulo?

For positive numbers they are identical. They differ only when negatives are involved: the remainder follows truncated division while the mathematical modulo follows floored division. The calculator labels each clearly so you pick the right one.

What happens when you divide by zero?

Modulo by zero is undefined, just like division by zero, because there is no meaningful remainder. The calculator detects a zero divisor and shows a message instead of returning an invalid result.

How do I get an always-positive modulo?

Use the floored convention, which this tool computes as ((a % n) + n) % n. It always returns a value between 0 and n − 1, which is what you usually want for array indexing and clock arithmetic.

Guides for Modulo Calculator

Related tools