What This Tool Does
This calculator finds a mod n, the remainder after dividing integer a by nonzero integer n. Choose truncated or floored modulo, then review the exact quotient, remainder, formula, and calculation steps.
The Governing Formula
For integers a and n, where n != 0, modulo is defined as:
a mod n = a - n * q
where q is the quotient of a divided by n. How q is rounded determines the convention:
- Truncated convention: q = trunc(a / n) (rounded toward zero). The remainder takes the sign of the dividend a, or is 0. This matches JavaScript's
%, and C, Java, and most other C-derived languages. - Floored / divisor-sign convention: q = floor(a / n) (rounded toward negative infinity). The remainder follows the sign of the divisor n, so it is negative when n is negative (unless the remainder is 0). This matches Python's
%operator.
Both conventions agree when a and n are nonnegative, or when a is exactly divisible by n. The calculator uses exact integer arithmetic for inputs within its 100-digit limit.
Inputs & Supported Values
- Dividend (a): a positive, negative, or zero integer.
- Divisor (n): a positive or negative integer, but not zero.
- Input length: each value may contain at most 100 digits, excluding an optional leading plus or minus sign.
- Signs: an optional leading
+or-is accepted. - Convention: choose truncated or floored (divisor-sign) modulo, which changes only the sign convention of the result, never its magnitude relative to |n|.
- Units: the numbers are plain integers - counts, indices, or any whole-number quantities. The result is a dimensionless whole number, not a currency, weight, or other measured unit.
Input Validation
The calculator trims surrounding whitespace before checking each value. It rejects blank values, decimals, other non-integer text, and inputs longer than 100 digits after an optional sign. It also rejects a divisor of 0 because modulo by zero is undefined.
How to Use the Modulo Calculator
- Enter values in Dividend (a) and Divisor (n).
- Choose Floored (remainder follows divisor sign) or Truncated (sign of dividend) from Modulo convention.
- Click Calculate.
- Review the Result section and its Formula & steps.
- Click Copy result or Download result (.txt) to save the plain-text output.
- Click Reset to clear both inputs, restore Floored (remainder follows divisor sign), hide errors, and hide the result section.
What This Tool Does Not Do
This calculator computes integer modulo only - it does not compute modulo of decimal or rational numbers, modular exponentiation, modular inverses, or congruences over polynomial or matrix values. It does not model units, currency, or real-world context beyond the plain integers entered, and it does not present its output as certified, financial, or professional advice; it is a transparent, deterministic arithmetic tool only.
Privacy & Security
The modulo calculation runs locally in your browser using exact integer arithmetic. The calculation script does not transmit the entered dividend, divisor, or convention values.
Frequently Asked Questions
What does modulo mean?
Modulo (a mod n) gives the remainder left over after dividing an integer a by an integer n. For example, 17 mod 5 = 2, because 17 divided by 5 leaves a remainder of 2.
How is modulo calculated?
Modulo is calculated as a mod n = a - n * q, where q is the quotient of a divided by n. The quotient can be rounded toward zero (truncated convention) or toward negative infinity (floored / divisor-sign convention). Under the floored convention, a negative divisor produces a negative nonzero remainder.
What is the difference between truncated and floored modulo?
Truncated modulo rounds the quotient toward zero, so the remainder has the same sign as the dividend (or is 0) - this matches languages like JavaScript, C, and Java. Floored / divisor-sign modulo rounds the quotient toward negative infinity, so the remainder follows the sign of the divisor (and is therefore negative for a negative divisor, unless it is 0) - this matches Python's % operator.
Can the divisor be negative or zero?
The divisor can be any nonzero integer, positive or negative. Modulo by zero is undefined, so the calculator rejects a divisor of 0.
How many digits can I enter?
Each dividend and divisor can contain up to 100 digits, excluding an optional leading plus or minus sign. Longer values are rejected.
What is modulo used for?
Modulo is used for tasks like checking divisibility, wrapping values within a fixed range (such as clock arithmetic or array indexing), cryptography, and hashing. This calculator performs the arithmetic only; it does not interpret the result for a specific application.