Modulo in the Order of Operations

Enter a three-term expression (A, operator, B, operator, C) to see how modulo's precedence — equal to multiplication and division — decides which operation runs first.

Quick Facts

Precedence tier
mod, ×, ÷ rank above +, −
Modulo shares precedence with multiplication and division — all three outrank addition and subtraction.
Tie-break rule
Left to right
Operators at the same precedence level evaluate left to right, the same way × and ÷ do.
Sign convention
a % b keeps the sign of a
This calculator uses the truncated-remainder convention (JavaScript, C, Java, C++), not the always-nonnegative floored mod.

Your Results

Calculated
Final Result
-
A op1 B op2 C, evaluated with order of operations
Step 1 (higher precedence)
-
Evaluated first
Step 2 (final combination)
-
Combines with the remaining number
Evaluation Order
-
Which pair was grouped first, and why

Ready

Enter three numbers and two operators, then press Calculate.

How Modulo Fits in the Order of Operations

The standard order of operations — PEMDAS/BODMAS (parentheses, exponents, multiplication/division, addition/subtraction) — usually skips over the modulo operator, but it isn't a special case: % is a form of division, so it sits at the same precedence tier as multiplication and division, above addition and subtraction. This calculator takes a three-term expression, A op1 B op2 C, and evaluates it using that exact rule, showing you which pair of numbers is grouped first and why.

Where % ranks in PEMDAS

In an expression like 17 + 5 % 3, the modulo runs before the addition because it shares the multiplication/division tier: 5 % 3 = 2 first, then 17 + 2 = 19. Without that rule you might expect (17 + 5) % 3 = 22 % 3 = 1 — a completely different, and incorrect, answer. The only way to force that alternate grouping is to add explicit parentheses.

Evaluating a three-term expression

For A op1 B op2 C, compare the precedence of op1 and op2. If op2 outranks op1 (for example + then %), evaluate B op2 C first, then combine that result with A using op1. If op1 outranks op2, or the two operators share a precedence tier (both from {×, ÷, %} or both from {+, −}), evaluate strictly left to right: (A op1 B) op2 C. This calculator applies that rule automatically and displays both intermediate steps.

Common mistakes

  • Treating % as the lowest-precedence operator: a % b + c means (a % b) + c, not a % (b + c) — modulo binds exactly as tightly as multiplication and division.
  • Assuming mod always returns a nonnegative number: in JavaScript, C, Java, and most calculators, the sign of a % b matches the sign of a (the dividend), so -7 % 3 = -1, not 2.
  • Forgetting parentheses when you want a different grouping: if you want (A + B) % C instead of A + (B % C), you must write the parentheses — default precedence always groups % with its neighboring × / ÷ first.

Where this shows up

Order-of-operations questions involving modulo come up constantly in programming and everyday math: hashing (index = key % tableSize), parity checks (n % 2), clock and calendar arithmetic (hour % 12), cyclic array indexing, and checksum digits. Misjudging when % actually fires relative to the surrounding + or − can silently shift an index or a wrapped value by the wrong amount.

Frequently Asked Questions

Where does modulo (%) rank in the order of operations?
Modulo shares the same precedence tier as multiplication and division — all three outrank addition and subtraction. Among operators of equal precedence, evaluation proceeds left to right, exactly like × and ÷.
Does 17 + 5 % 3 equal (17 + 5) % 3 or 17 + (5 % 3)?
It equals 17 + (5 % 3). Because % has the same precedence as multiplication and division, it is evaluated before the addition: 5 % 3 = 2, then 17 + 2 = 19. (17 + 5) % 3 = 22 % 3 = 1 is a different number — you would need explicit parentheses to get that result.
How does this calculator's mod differ from the mathematical "mod" used in number theory?
This calculator uses the truncated-remainder convention that JavaScript, C, Java, and C++ use for %: the result takes the sign of the dividend, so -7 % 3 = -1. The floored modulo used in number theory and some languages (like Python) always returns a result with the same sign as the divisor, so -7 mod 3 = 2 in that convention. Both are valid — just know which one your context expects.
What happens if I divide or use modulo by zero?
Both division and modulo by zero are undefined, so the calculator flags the input as invalid instead of returning a result. Change the number acting as the divisor to any nonzero value.