Modular Arithmetic CalculatorFree online math calculator — instant results, no sign-up
Calculate the nonnegative remainder for an integer modulus.
Sign in to save results and favorites.
About the Modular Arithmetic Calculator
The Modular Arithmetic Calculator finds the nonnegative remainder when an integer is divided by a positive integer modulus. It handles negative integers by returning a result from zero up to, but not including, the modulus. With the default integer -17 and modulus 5, the result is 3.
- Integer
- The unitless whole number to reduce modulo the positive modulus; the default is -17.
- Positive modulus
- The unitless positive whole-number divisor that sets the remainder range; the default is 5.
Formula and method
q = floor(a / m); r = a - m × q. For a = -17 and m = 5: q = floor(-17 / 5) = -4, so r = -17 - 5 × (-4) = 3.
- aThe input integer.
- mThe positive integer modulus.
- qThe integer quotient obtained by rounding a / m down toward negative infinity.
- rThe nonnegative remainder, satisfying 0 ≤ r < m.
- floorThe floor function, which returns the greatest integer less than or equal to its argument.
Divide the integer by the positive modulus and take the floor of the quotient. Multiply that quotient by the modulus, then subtract the product from the original integer. Using floor rather than truncation toward zero ensures that negative input integers also produce a nonnegative remainder.
Worked example
These are the calculator's starting values and the results it actually produces for them.
Inputs
- Integer-17
- Positive modulus5
Results
- Result3
How to use the Modular Arithmetic Calculator
- 1Enter the whole number in Integer; keep -17 to follow the worked example.
- 2Enter a positive whole number in Positive modulus; keep 5 for the worked example.
- 3Run the calculation to reduce the integer modulo the chosen modulus.
- 4Read the Result row: the default inputs produce 3.
- 5Check that the result is nonnegative and less than the modulus: 0 ≤ 3 < 5, and -17 = 5 × (-4) + 3.
Reading your result
The Result row shows r, the nonnegative remainder, not the quotient. A result of 3 for -17 modulo 5 means that -17 differs from 3 by an integer multiple of 5. In congruence notation, -17 ≡ 3 (mod 5).
Limitations
This tool assumes an integer input and a strictly positive integer modulus. Zero and negative moduli, fractional inputs, and nonnumeric values are outside its stated scope. The mathematical formula is exact, but the largest integer that the calculator can handle exactly depends on its implementation; no supported precision range is specified here.
Common questions
Why does -17 modulo 5 give 3 instead of -2?+
This calculator uses the nonnegative-remainder convention. Since -17 = 5 × (-4) + 3, the remainder is 3. A remainder of -2 can arise from truncating the quotient toward zero, but it does not meet this tool's requirement that the remainder be nonnegative.
Can the result equal the positive modulus?+
No. The result always satisfies 0 ≤ r < m. If the integer is exactly divisible by the modulus, the result is zero.
Can I enter zero or a negative number as the modulus?+
No. This calculator requires a strictly positive integer modulus. Division by zero is undefined, and negative moduli are outside the tool's supported convention.
Does a result of 3 mean that -17 divided by 5 is 3?+
No. The result is the remainder after removing an integer multiple of 5. Here, the floor quotient is -4, and the decomposition is -17 = 5 × (-4) + 3.
Does the calculator save my information?+
Calculations run in your browser. While signed in, inputs and results are automatically recorded in account history; saving a result creates a separate saved record.
You might also like
Scientific Calculator
Full scientific calculator with trig, logs, powers, memory and degree/radian modes.
Fraction Calculator
Add, subtract, multiply and divide fractions.
Percentage Calculator
Percent of a number, what percent, and percent change.
Random Number Generator
Generate random integers in a range.
Percent Error Calculator
Error between an observed and true value.
Exponent Calculator
Raise a base to any power.
Results are estimates for informational purposes and are not financial, medical or legal advice.