
Long Division Calculator
Use this free long division calculator to find the whole-number quotient, remainder, and Euclidean equation (a = b × q + r) for integers up to 1 billion.
Open toolEnter an integer dividend (a) and a nonzero integer divisor (b) between -1,000,000,000 and 1,000,000,000 into this modulo calculator to evaluate the non-negative Euclidean remainder (0 <= r < |b|) in one click.
Enter the inputs, then select Calculate result.
Result will appear here
The Modulo Calculator is a browser-based modular arithmetic utility that computes the canonical non-negative Euclidean remainder (a mod |b|) for any integer dividend and nonzero integer divisor between -1 billion and 1 billion. Unlike C or JavaScript % operators that return negative values on negative dividends, this modular calculator always returns a remainder r in the range 0 <= r < |b|.
r = ((a % |b|) + |b|) % |b|, where b ≠ 0 and 0 <= r < |b|.
Normalizes the divisor to |b| = Math.abs(b) and shifts negative JavaScript remainders upward into [0, |b|) (see our Long Division Calculator, Modular Exponentiation Calculator, and Diophantine Equation Solver).
Compare 10 benchmark cases showing how this modular arithmetic calculator's Euclidean remainder (0 <= r < |b|) compares against Python's floored % operator and JavaScript/C/Java's truncated % operator.
| Modulo Scenario | Dividend (a) | Divisor (b) | Euclidean Modulo (a mod |b|) | Euclidean Equation (a = b × q + r) | Python Floored (a % b) | JS / C / Java (a % b) |
|---|---|---|---|---|---|---|
| Preloaded positive example | 17 | 5 | 2 | 17 = 5 × 3 + 2 | 2 | 2 |
| Negative dividend (-17 mod 5) | -17 | 5 | 3 | -17 = 5 × (-4) + 3 | 3 | -2 |
| Negative divisor (17 mod -5) | 17 | -5 | 2 | 17 = (-5) × (-3) + 2 | -3 | 2 |
| Both negative (-17 mod -5) | -17 | -5 | 3 | -17 = (-5) × 4 + 3 | -2 | -2 |
| 24-hour clock wrap (-3 mod 24) | -3 | 24 | 21 | -3 = 24 × (-1) + 21 (21:00) | 21 | -3 |
| 7-day weekday shift (100 mod 7) | 100 | 7 | 2 | 100 = 7 × 14 + 2 | 2 | 2 |
| Caesar cipher alphabet wrap (-4 mod 26) | -4 | 26 | 22 | -4 = 26 × (-1) + 22 | 22 | -4 |
| Exact multiple (144 mod 12) | 144 | 12 | 0 | 144 = 12 × 12 + 0 | 0 | 0 |
| Dividend smaller than divisor (3 mod 8) | 3 | 8 | 3 | 3 = 8 × 0 + 3 | 3 | 3 |
| Zero dividend (0 mod 5) | 0 | 5 | 0 | 0 = 5 × 0 + 0 | 0 | 0 |
Follow these three steps to find the non-negative Euclidean remainder for any pair of signed integers.
Type any whole number a from -1,000,000,000 to 1,000,000,000 into the Integer dividend field (17 is preloaded by default).
Specify a nonzero modulus b (5 by default, within ±1 billion) in the Nonzero integer divisor box.
Press Calculate result to compute the non-negative remainder r, then click Copy or Download (result.txt) to save the output.
See how developers and math students use this modulo operator calculator across positive remainders, negative wrap-around indices, and clock or cipher arithmetic.
With the preloaded values Integer dividend = 17 and Nonzero integer divisor = 5, clicking Calculate result returns 2. Because 5 × 3 = 15 is the largest multiple of 5 less than or equal to 17, the remainder is 17 - 15 = 2. Whenever a and b are both positive, Euclidean modulo, Python %, and JavaScript % all return the same remainder 2 (and if you want the quotient 3 displayed alongside the remainder 2, use our Long Division Calculator).

When Integer dividend = -17 and Nonzero integer divisor = 5, truncated division in C, Java, or JavaScript evaluates -17 / 5 = -3 and leaves a negative remainder (-17 - 5 × (-3) = -2). In number theory and cryptography, however, remainders in mod 5 must belong to the canonical residue set {0, 1, 2, 3, 4}. Stepping down to the floor quotient -4 gives 5 × (-4) = -20, so -17 - (-20) = 3. This calculator applies ((-17 % 5) + 5) % 5 and returns 3.

Modular wrap-around keeps cyclic indices inside fixed bounds [0, m - 1]. Subtracting 5 hours from 02:00 on a 24-hour clock gives a = 2 - 5 = -3; entering -3 and 24 returns 21 (21:00, or 9:00 PM). Likewise, shifting letter index 0 (A) backward by 4 positions in a 26-letter alphabet (-4 mod 26) returns index 22 (W), which is the exact modular wrap used in our Caesar Cipher Decoder.

Programming languages and mathematics textbooks define the modulo operation in three different ways when negative numbers are involved:
First, Euclidean modulo (0 <= r < |b|, used by this tool) chooses the integer quotient q so the remainder r = a - b × q is always non-negative and strictly smaller than |b|, regardless of the signs of a and b. Thus 17 mod 5 = 2, -17 mod 5 = 3, 17 mod -5 = 2, and -17 mod -5 = 3.
Second, floored modulo (used by Python and R) uses q = floor(a / b), which matches Euclidean modulo when b > 0 (-17 % 5 == 3) but returns a negative remainder when b < 0 (17 % -5 == -3). Third, truncated remainder (used by JavaScript, C, C++, Java, and Rust %) rounds q toward zero, so -17 % 5 returns -2.

Check these three constraints before running a calculation:
First, entering 0 in Nonzero integer divisor (#b) is mathematically undefined and triggers 'The divisor cannot be zero.' Both Integer dividend (#a) and Nonzero integer divisor (#b) require whole numbers (step=1) between -1,000,000,000 and 1,000,000,000.
Second, to evaluate large powers a^e mod m up to 100 digits, open our Modular Exponentiation Calculator. To solve linear congruences ax ≡ c (mod m) or check coprimality gcd(a, m) = 1, use our Diophantine Equation Solver, GCF Calculator, LCM Calculator, and Continued Fraction Calculator.


Use this free long division calculator to find the whole-number quotient, remainder, and Euclidean equation (a = b × q + r) for integers up to 1 billion.
Open toolCalculate a large-integer modular power using repeated squaring.
Open toolFree Diophantine equation solver for ax + by = c over the integers with 100-digit BigInt precision. Returns gcd(a,b), one (x,y) pair, and all integer solutions.
Open toolChoose another tool for your next calculation, conversion, or text task.

Find the greatest common factor of the supplied integers.
Open tool
Use this free LCM calculator to find the least common multiple of 2 to 100 positive integers (like 12, 18, 30 = 180) in your browser with BigInt precision.
Open toolUse this free continued fraction calculator to expand fractions and decimals into simple continued fractions and convergents p/q with 100-digit BigInt.
Open tool
Decrypt or encrypt Caesar shift ciphers with a chosen key (1 to 25) or inspect all 25 brute-force rotations ranked by English letter frequency.
Open toolAnswers about using Modulo Calculator and understanding its results.
Divide the dividend a by the positive divisor b (17 ÷ 5 = 3.4) and take the floor integer q = floor(a / b) (q = 3). Multiply q × b (3 × 5 = 15) and subtract that product from a (17 - 15 = 2) to get the remainder r = 2.
Divide -17 by 5 (-3.4) and round down toward negative infinity to get the floor quotient q = -4. Since 5 × (-4) = -20, the distance upward from -20 to -17 is -17 - (-20) = 3, which means -17 mod 5 = 3.
JavaScript's % operator is a truncated remainder operator: it rounds the quotient -17 / 5 = -3.4 toward zero (-3) and computes -17 - 5 × (-3) = -2. This calculator uses the Euclidean modulo formula ((a % |b|) + |b|) % |b|, which adds 5 to -2 so the remainder always lies in [0, |b|).
When a non-negative dividend a is strictly smaller than |b| (for example, 3 mod 8 or 0 mod 5), the floor quotient is 0 (3 = 8 × 0 + 3). Subtracting 0 leaves a unchanged, so a mod b simply equals a (3 mod 8 = 3).
The modulo operation a mod b is defined as the remainder of dividing a by b (a = b × q + r). Because division by 0 is undefined and no multiple 0 × q can ever reach a nonzero dividend a, a divisor of 0 is rejected with 'The divisor cannot be zero.'
Choose another tool for your next calculation, conversion, or text task.