Modulo

Compare Calculations

Downloads

Includes your inputs and results for this calculation, plus any additional calculations you've compared.

Finding the Remainder Left Over From Division

Modulo finds the remainder left over after dividing one number by another. Enter a dividend and a divisor, and this calculator returns the remainder — the same value you’d get from long division, on its own.

The Formula

amodn=antrunc ⁣(an)\vC{a \bmod n} = \vA{a} - n \cdot \operatorname{trunc}\!\left(\frac{\vA{a}}{n}\right)

where aa is the dividend and nn is the divisor, and trunc\operatorname{trunc} rounds toward zero — this calculator uses JavaScript’s native % operator, so for a negative dividend the result takes the sign of the dividend (not the divisor), as explained below.

Worked Example

17 mod 5:

    1. 17÷5=317 \div 5 = 3 remainder 2\vC{2} — since 5×3=155 \times 3 = 15, and 1715=217 - 15 = \vC{2}.

Key Factors to Consider

  • Different programming languages and math conventions handle negative numbers differently. This calculator uses the “sign of the dividend” convention common in most programming languages (JavaScript, C, Java) — but Python’s % operator and some math textbooks use a convention where the result always matches the sign of the divisor instead, which can give a different-looking answer for the same negative inputs.
  • The result of a mod n is always between 0 and n-1 (using the non-negative convention), which is exactly why modulo is used for “wrapping” behavior. This bounded-range property is what makes modulo the natural tool for anything cyclical — clock arithmetic, days of the week, array indexing that wraps around, and repeating patterns all rely on this same bounded wraparound behavior.
  • Checking if a number is even or odd is just modulo 2. Any number mod 2 is either 0 (even) or 1 (odd) — this is one of the simplest and most common practical uses of modulo in everyday programming.
  • Modulo is a foundational operation in cryptography, particularly with large prime numbers. Modular arithmetic (working with remainders under a fixed modulus) underlies widely-used encryption schemes like RSA — the same basic remainder concept this calculator computes scales up to numbers hundreds of digits long in real cryptographic applications.

Common Mistakes

  • Assuming modulo always gives a non-negative result. This calculator’s “sign of the dividend” convention means a negative dividend produces a negative (or zero) remainder — confirm which convention you actually need before comparing results across tools.
  • Confusing modulo with plain division. Modulo returns only the leftover remainder, not the quotient — 17 divided by 5 is 3.4, but 17 mod 5 is 2, a very different number used for a very different purpose.
  • Forgetting that a modulus of 0 is undefined. Division by zero has no answer, and neither does a mod 0 — any calculator or program should treat this as an error, not silently return 0 or the dividend unchanged.
  • Mixing up which number is the dividend and which is the divisor. a mod n is not the same as n mod a except in special cases — swapping the two order changes the result entirely, not just its sign.

Useful to Know

Source: Modulo operation.

Frequently Asked Questions

What is the modulo operation?

Modulo (often written "mod" or %) finds the remainder left over after dividing one number by another. For example, 17 mod 5 is 2, because 17 divided by 5 is 3 with 2 left over. It's the same remainder you'd get from long division, just reported on its own.

How does modulo work with negative numbers?

This calculator uses the "sign of the dividend" convention most programming languages use: the remainder takes the same sign as the number being divided. For example, -7 mod 3 is -1 (not 2), because -7 divided by 3 rounds toward zero to -2, leaving -1. Some math classes teach a convention where the remainder is always non-negative -- if you need that version, add the divisor to a negative result.

What is modulo used for?

Modulo shows up anywhere something cycles or wraps around -- telling time on a 12-hour clock (13 mod 12 = 1 o'clock), checking if a number is even or odd (n mod 2), or spacing repeating patterns evenly. It's also a core building block in programming and cryptography.

Why do different calculators or programming languages give different answers for negative modulo?

There are two common conventions: this calculator uses "sign of the dividend" (matching JavaScript, C, and Java), where the remainder's sign matches the number being divided. Python and some math textbooks instead use "sign of the divisor," where the remainder always matches the divisor's sign. Both are mathematically valid conventions -- they just handle negative numbers differently, which is why the same inputs can produce different-looking results across tools.

How is modulo used in cryptography?

Modular arithmetic — repeatedly working with remainders under a fixed modulus — is foundational to widely-used encryption schemes like RSA, which relies on modulo operations with very large prime numbers. The same basic remainder concept this calculator computes for small numbers scales up to numbers hundreds of digits long in real cryptographic systems.

Confirm Your Age

To create an account, please tell us your birth month and year.