Intermediate

Modulo of Negative Numbers Calculator

Enter any dividend and divisor — including negatives — and compare the truncated, floored, and Euclidean remainders side by side with a full step-by-step breakdown of each convention.
Try a negative value to see the conventions differ
Cannot be zero; try negative values too
Euclidean remainder
3

Always ≥ 0 — the mathematically preferred convention

Truncated remainder (JS / C / Java)
-2
Floored remainder (Python / Ruby)
3
Euclidean remainder (number theory)
3
Truncated quotient
-3
Floored quotient
-4
Step-by-step: all three conventions
1

Truncated: quotient rounds toward zero

q = trunc(-17 / 5) = -3
2

Truncated remainder (sign = sign of dividend a)

rT = -17 − 5 × -3 = -2
3

Floored: quotient rounds toward −∞

q = floor(-17 / 5) = -4
4

Floored remainder (sign = sign of divisor b)

rF = -17 − 5 × -4 = 3
=

Euclidean: remainder always ≥ 0

rE = -17 − |5| × floor(-17 / |5|) = 3
00.61.31.92.53.13.84.45Euclidean remainder always lands in [0, |b|)
Step by step
  1. 1

    Absolute value of divisor

    |5| = 5
  2. 2

    Floor quotient

    floor(-17 ÷ 5) = -4
    Using |b| ensures the remainder is always non-negative.
  3. 3

    Euclidean remainder

    -17 − 5 × -4 = 3
Results are estimates for general information only and are not professional advice — always verify important results independently before relying on them. Read the full disclaimer.
Quick answer

How does this calculator work?

Modulo with negative numbers depends on the rounding convention. Truncated (JS/C/Java): remainder sign matches the dividend. Floored (Python/Ruby): remainder sign matches the divisor. Euclidean: remainder is always ≥ 0 (range [0, |b|)). All three agree when both inputs are positive.

Formula
rT = a − b·trunc(a/b) • rF = a − b·floor(a/b) • rE = a − |b|·floor(a/|b|)
How this is calculated

The three modulo conventions agree for positive inputs but diverge when a or b is negative — the difference lies in how the quotient is rounded before the remainder is extracted.

Truncated division rounds the quotient toward zero (trunc(a/b)), so the remainder rT = a − b·trunc(a/b) always carries the sign of the dividend a. This is the behaviour of % in C, C++, Java, JavaScript, Go and most compiled languages. Floored division rounds toward negative infinity (floor(a/b)), so rF = a − b·floor(a/b) carries the sign of the divisor b — this is Python's % and Ruby's % operator. Euclidean division forces the remainder to always be non-negative by using the absolute value of b for rounding: rE = a − |b|·floor(a/|b|), keeping 0 ≤ rE < |b| regardless of the signs of either operand.

For programming use, match the convention of your target language. For mathematical modular arithmetic (e.g. group theory, RSA, clock arithmetic) the Euclidean remainder is canonical because a non-negative remainder means a and a + k·|b| are always in the same congruence class without surprises.

Frequently asked questions

JavaScript uses truncated division (quotient = trunc(−17/5) = −3), giving −17 − 5×(−3) = −2. Python uses floored division (quotient = floor(−17/5) = −4), giving −17 − 5×(−4) = 3. The Euclidean remainder is also 3 in this case.

The Euclidean remainder (always non-negative) is the standard in number theory and modular arithmetic because it preserves the congruence relation cleanly. Use it whenever you write a ≡ b (mod n) in a mathematical context.

Yes. For a negative divisor the three conventions can produce three distinct remainders. The Euclidean convention uses |b| internally, so the remainder range is always [0, |b|) regardless of the sign of b.

Also known as

modulo negative numbers
negative modulo remainder
python modulo negative integer
javascript percent sign negative
euclidean modulo non-negative
floored division remainder sign
truncated remainder negative dividend
mod negative calculator

APA

TG we-Calculate Editorial Team. (2026). Modulo of Negative Numbers Calculator [Online calculator]. TG we-Calculate. https://we-calculate.com/calculator/modulo-of-negative-numbers-calculator

Chicago

TG we-Calculate Editorial Team. "Modulo of Negative Numbers Calculator." TG we-Calculate. 2026. https://we-calculate.com/calculator/modulo-of-negative-numbers-calculator.

IEEE

TG we-Calculate Editorial Team, "Modulo of Negative Numbers Calculator," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/calculator/modulo-of-negative-numbers-calculator

BibTeX

@misc{wecalculate_modulo_of_negative_numbers_calculator, title = {Modulo of Negative Numbers Calculator}, author = {{TG we-Calculate Editorial Team}}, howpublished = {\url{https://we-calculate.com/calculator/modulo-of-negative-numbers-calculator}}, year = {2026}, note = {TG we-Calculate} }

Did this calculator help you?