Modulo (remainder) calculator

Enter dividend a and divisor b. Modulo is the remainder on division: 17 mod 5 = 2. 10 mod 3 = 1. 8 mod 4 = 0. Fractions go through floor before %. When b = 0 the result stays blank. With a negative dividend the remainder sign follows JavaScript (e.g. −17 mod 5 = −2), not the Euclidean remainder 3.

Inputs

Result

Enter a and b, for example 17 and 5.

Modulo means remainder, not the quotient. Floor prepares for %. Compute floor alone on the floor page.

How it works

How 17 mod 5 is computed
a, b17, 5
floor⌊17⌋, ⌊5⌋
a = q·b + r17 = 3·5 + 2
remainder2

Modulo means the remainder of division: after dividing dividend a by divisor b you get r such that a = q·b + r. In school and in programming this is written a mod b or a % b. Worked example: 17 = 3 · 5 + 2, so 17 mod 5 = 2. The calculator uses the numbers you enter in fields modulo-reszta-a and modulo-reszta-b.

The calculator first takes the integer part of both fields (floor), then the remainder as JavaScript computes it: r = ⌊a⌋ % ⌊b⌋. With 17.9 and 5, floor gives 17 and 5, and 17 % 5 = 2. When b = 0 after floor, the result stays blank — that is not a remainder of zero (zero appears when b divides a, for example 8 mod 4).

The mathematical model is the modulo (remainder) operation from number theory and integer arithmetic, tied to Euclidean division. For non-negative a and b the Euclidean convention (0 ≤ r < |b|) matches the JavaScript remainder %. For a negative dividend, the JavaScript remainder takes the dividend’s sign — this calculator states that openly and shows (−17) mod 5 = −2.

The result panel shows floor(a), floor(b), integer quotient q, and the identity a = q·b + r. The diagram draws full divisor blocks and the highlighted remainder. Comma and period are equivalent.

Worked examples: 17 mod 5 = 2; 10 mod 3 = 1; 8 mod 4 = 0; 17.9 mod 5 = 2; 4 mod 8 = 4; 0 mod 7 = 0; (−17) mod 5 = −2; 23 mod 7 = 2. This is not a 0–100 scale — only the remainder after floor.

Formula

r = ⌊a⌋ % ⌊b⌋ when ⌊b⌋ ≠ 0; otherwise a blank result.

Identity: ⌊a⌋ = q · ⌊b⌋ + r, where q is the integer quotient and r is the remainder (modulo). Fields: modulo-reszta-a, modulo-reszta-b.

Computation: r = ⌊a⌋ % ⌊b⌋ (only when ⌊b⌋ ≠ 0) (blank on NaN/B=0). Model: modulo (remainder) operation — division algorithm / the % operator in JavaScript.

Theory: remainder, Euclidean division, and the JavaScript remainder %

Definition

The modulo (remainder) operation maps a pair (a, b) to the remainder r when a is divided by b. School and programming notation write a mod b or a % b. Intuitively: how much is left after subtracting as many whole portions of b as the sign convention allows. Classic example: 17 = 3 · 5 + 2, so 17 mod 5 = 2. A remainder of zero means b divides a after the chosen reduction to integers — for example 8 mod 4 = 0.

This calculator implements a concrete browser formula: first A = ⌊a⌋ and B = ⌊b⌋; when B ≠ 0 the result is A % B; when B = 0 the result is blank. The mathematical model is the modulo / remainder operation from integer arithmetic, tied to the division algorithm in number theory. Descriptive sources: Wikipedia — Modulo operation; MathWorld — Modulo Operation; JavaScript specification — remainder operator (%).

In teaching practice it helps to separate the mathematical identity from floating-point limits: this calculator shows the browser’s computation (floating-point arithmetic and a remainder with the dividend’s sign), not a paper proof of symbolic identities. For extreme inputs, check the domain (b ≠ 0 after floor) before floating-point range.

Historical and conceptual context

The division algorithm is foundational: for integers a and b ≠ 0 there exist unique q and r with a = q·b + r under a fixed range for r. Euclid used repeated subtraction and remainders in the GCD algorithm — hence the tight link between modulo and greatest common divisor. Modern congruence notation a ≡ c (mod n) means n divides (a − c), i.e. a and c leave the same remainder when divided by n.

In computing, % spread from C/Unix into JavaScript, Java, and C#. Sign conventions for negative operands are not universal: some systems force r ≥ 0 (Euclidean / floored division), others keep the dividend’s sign (truncating division). The same phrase “−17 mod 5” may mean 3 or −2 depending on the tool. CalcBoxer does not hide the difference: it shows floor and % as the browser computes them.

Conceptually, modulo is not ordinary floating division, not floor alone, and not GCD. Division returns a quotient; floor truncates one number; GCD seeks a common divisor. Here the question is: what is the remainder after flooring both fields.

Formal properties

For integers A, B with B ≠ 0 we have A = q·B + r where in the JavaScript convention (remainder takes the dividend’s sign) r = A % B and q = (A − r) / B is an integer. For A ≥ 0 and B > 0 usually 0 ≤ r < B. For A < 0 and B > 0, the JavaScript remainder is ≤ 0 (dividend sign). The identity A % B = A − B·trunc(A/B) is close to truncating division; the % result is defined unambiguously in the JavaScript specification.

Congruence: A ≡ r (mod B) in the remainder sense depends on convention. For positive arguments a ≡ b (mod n) ⇔ n | (a − b). Periodic structure appears in clocks and array indices: (i + 1) mod n cycles through 0…n−1. Parity test: n mod 2 = 0 iff n is even (for non-negative integers in this convention).

Floor before %: if a is not an integer, A = ⌊a⌋. That is not the same as (a % b) on floats without flooring — JavaScript allows % on non-integers, but this calculator first reduces both sides to floored integers, matching the adopted formula.

In teaching practice it helps to separate the mathematical identity from floating-point limits: this calculator shows the browser’s floating-point computation (about 15–16 significant digits), not a paper proof of symbolic identities. For extreme inputs, check the domain first, then floating-point range.

Full derivation

Step 1. Enter a and b. The parser accepts comma or period. An empty field leaves a blank result; the calculator does not substitute zero for a missing entry.

Step 2. Compute A = ⌊a⌋ and B = ⌊b⌋. Example: a = 17.9 → A = 17; b = 5 → B = 5.

Step 3. If B = 0, the remainder is undefined — blank result. If B ≠ 0, r = A % B in JavaScript.

Step 4. Recover the integer quotient from the identity: q = (A − r) / B. Check: A = q·B + r. For 17 and 5: q = 3, r = 2 because 17 = 3·5 + 2.

Step 5 (negatives). For a = −17, b = 5: A = −17, B = 5, (−17) % 5 = −2 (as in JavaScript). A Euclidean remainder would be 3 because −17 = (−4)·5 + 3. The calculator shows −2 and explains the difference in theory and FAQ.

Step 6. The diagram stacks |q| full blocks of length |B| plus a segment |r|. That visualizes the same identity, not a separate model.

Special cases

Positive examples: 17 mod 5 = 2; 10 mod 3 = 1; 8 mod 4 = 0; 23 mod 7 = 2; 4 mod 8 = 4 (field order matters); 0 mod 7 = 0. Fractional: 17.9 mod 5 = 2 after floor.

Negative dividend: (−17) mod 5 = −2 in this calculator (as in JavaScript). Positive dividend and negative divisor: the remainder still takes the dividend’s sign, as the JavaScript specification requires — check the live panel instead of guessing another language’s convention.

Division by zero after floor: b = 0.5 yields B = 0 → blank result. b = 0.9 likewise. That is a common trap with fractional divisors smaller than 1.

In teaching practice it helps to separate the mathematical identity from floating-point limits: this calculator shows the browser’s floating-point computation (about 15–16 significant digits), not a paper proof of symbolic identities. For extreme inputs, check the domain first, then floating-point range.

Numerical notes

floor and % operate on floating-point numbers. Above |A| > 2⁵³ not every integer is exactly representable — then “remainder” acts on an already rounded machine value. Typical school examples (17, 5, 10, 3) fit with room to spare.

Comma and period are equivalent. Locale display (en-US) does not change the internal value: 17 mod 5 is exactly 2.

The calculator does not compute GCD, does not solve congruence a ≡ x (mod n) for unknown x, and does not replace cryptographic modular arithmetic on big integers (BigInt). Large RSA-style moduli need separate big-integer tooling.

Related ideas and sources

Related: floor (integer part) — preparatory step; GCD — Euclid’s algorithm based on remainder; signum — does not divide; absolute value — distance, not remainder. Congruences and clock arithmetic are applications of the same remainder idea.

Sources: Wikipedia — Modulo operation; MathWorld — Modulo Operation; ECMAScript — Remainder Operator; Knuth, The Art of Computer Programming (integer arithmetic); standard number-theory texts (division algorithm). Educational tool — not a substitute for a textbook or instructor check.

How to use

  1. Enter a and b, for example 17 and 5.
  2. Click Calculate or wait for the live result. 17 mod 5 gives 2.
  3. Check the panel: floor(a), floor(b), q, and the identity a = q·b + r. The diagram shows divisor blocks and the remainder.
  4. 10 and 3 give 1. 8 and 4 give 0. 17.9 first drops to 17.
  5. When b = 0 the result stays blank. Negative a shows the JavaScript convention for % (for example −17 and 5 → −2).

Symbol glossary

Modulo = remainder of division. 17 mod 5 = 2. The panel also shows q and floor.

a mod b
Remainder (modulo) of a divided by b after floor. Primary result.
a
Dividend — the “Dividend a” field.
b
Divisor — the “Divisor b” field; after floor ≠ 0.
q
Integer quotient: (⌊a⌋ − r) / ⌊b⌋.
r
Remainder = ⌊a⌋ % ⌊b⌋ in JavaScript.
floor
Integer part toward −∞ (floor) before %.

Examples

Example 1

  • a = 17
  • b = 5

2

What is 17 mod 5? 2.

Example 2

  • a = 10
  • b = 3

1

What is 10 mod 3? 1.

Example 3

  • a = 8
  • b = 4

0

What is 8 mod 4? 0.

Example 4

  • a = 17.9
  • b = 5

2

What is 17.9 mod 5? 2 (after floor).

Example 5

  • a = 4
  • b = 8

4

What is 4 mod 8? 4.

Example 6

  • a = 0
  • b = 7

0

What is 0 mod 7? 0.

Example 7

  • a = −17
  • b = 5

−2

What is (−17) mod 5? −2 (JS; Euclidean 3).

Example 8

  • a = 23
  • b = 7

2

What is 23 mod 7? 2.

Related calculators

Frequently asked questions

What does modulo (remainder) mean?

Modulo is the remainder when dividend a is divided by divisor b. The notation a mod b (often a % b in code) means r such that a = q·b + r under the chosen sign convention. Example: 17 = 3 · 5 + 2, so 17 mod 5 = 2.

Which formula does this calculator use?

First the integer part of both fields: A = ⌊a⌋, B = ⌊b⌋. When B ≠ 0, the result is A % B in JavaScript. When B = 0, the result stays blank — that is not a remainder of zero.

How is the remainder different from the quotient?

The quotient a/b is the division result (for example 17/5 = 3.4). The remainder (modulo) is what is left after subtracting a whole number of divisors: 17 − 3·5 = 2. The calculator shows the remainder and also the integer quotient q in the panel.

Why floor before the % operator?

The form also accepts fractional input (for example 17.9). The calculator floors both sides to integers, then applies %. With 17.9 and 5: floor gives 17 and 5, then 17 % 5 = 2.

What if divisor b is 0?

After floor, a divisor of 0 makes the remainder undefined. The calculator clears the result: you see a blank field, not zero. Zero is a valid remainder only when b divides a (for example 8 mod 4 = 0).

How does the JavaScript remainder % behave with negative numbers?

In JavaScript the remainder from % follows the sign of the dividend. Example: (−17) % 5 = −2 because floor(−17) = −17. A Euclidean remainder would be non-negative (3 for divisor 5). This calculator describes and applies that JavaScript convention openly.

How does Euclidean division differ from the JavaScript remainder %?

Euclidean division requires 0 ≤ r < |b|. Many languages (Python //, some libraries) take quotient floor(a/b) and a non-negative remainder. The JavaScript remainder % keeps the sign of a. For non-negative a and b both conventions agree — hence examples like 17 mod 5 = 2.

Do comma and period work the same way?

Yes. 17,9 and 17.9 are the same number. Enter a leading minus on the dividend or divisor when needed. Field order matters: 4 mod 8 = 4, not 0.

Do the currency and unit settings in the page header affect the result?

No. The result depends only on the entered a and b. The currency and unit settings in the page header do not affect this result.

Where do I compute floor alone without a remainder?

On the floor (integer part) page. Here floor is only preparation for modulo. GCD uses remainder in Euclid’s algorithm, but answers a different question.

How do I calculate a remainder (modulo)?

Take dividend a and divisor b ≠ 0. Find r such that a = q·b + r. For 17 and 5: 17 = 3·5 + 2, so 17 mod 5 = 2. This calculator applies floor first, then the % operator.

What is 17 mod 5?

2. Breakdown: 17 = 3 · 5 + 2. That is Example 1 on this page.

What is 100 mod 7?

2, because 7 · 14 = 98 and 2 remains. Enter a = 100 and b = 7.

Is the result with a negative dividend always non-negative?

Not on this page. The JavaScript convention applies: remainder sign follows the dividend. (−17) mod 5 = −2. The Euclidean remainder would be 3.

What if the divisor is zero?

The result stays blank. Modulo by 0 is undefined — the calculator does not substitute zero for an error.

The result is remainder a mod b after floor: for 17 and 5 it is 2; for 8 and 4 it is 0; when b = 0 the field stays blank.

Sources

Remainder definitions, Euclidean division, and the % operator come from recognized references.

Page Updated November 2, 2026.