Math calculator

Modulo Calculator

What is left over, in all three conventions that call themselves mod.

a mod n, all three ways

They only disagree when something is negative.

-7 mod 3

2

This is the Euclidean answer, the one a proof means. Your programming language may well return -1 instead — both are below.

Euclidean (0 ≤ r)

2

number theory, and every proof

Floored

2

Python, Ruby, Excel MOD

Truncated

-1

C, Java, JavaScript, Go

Divides exactly?

no

there is something left over

a = q × n + r, in each convention

Each remainder convention with its quotient, its identity written out, and where it is used
ConventionQuotient qRemainder rThe identityUsed by
Truncated-2-1-7 = -2 × 3 + -1C, Java, JavaScript, Go, Rust, and Excel’s QUOTIENT
Floored-32-7 = -3 × 3 + 2Python, Ruby, and Excel’s MOD
Euclidean-32-7 = -3 × 3 + 2number theory, where a remainder is defined to be non-negative

-7 is negative. Rounding the quotient towards zero leaves -1; rounding it down to -3 leaves 2. The two differ by exactly 3 — the same point on the number line, described from either side.

Where -7 lands on a circle of 3

012

Counting -7 steps around a ring of 3 positions — forwards if positive, backwards if negative — finishes at 2. That is all “mod” means.

Computed on arbitrary-precision integers, so a thirty-digit dividend is exact rather than approximate.

What this tool shows

−7 mod 3 is 2 in Python and −1 in JavaScript. Neither is a bug: they round the quotient in different directions, and the remainder follows. This page gives all three standard answers with the identity each one satisfies.

  • a mod n under every standard convention
  • The quotient each convention implies
  • The identity a = qn + r, checkable by eye
  • Which languages use which
  • Whether n divides a exactly
  • Where the answer lands on a circle of n
All three conventions a = qn + r written out The wrap-around view Any number of digits

Exact on integers of any length.

Updated 7 September 2026 · Works in any browser, no installation

Take away whole copies of n until what is left is smaller than n. For 17 and 5 that is three copies with 2 left over, so 17 mod 5 = 2. The only complication is a negative: −7 mod 3 is 2 if you keep taking copies until the result is non-negative, and −1 if you stop as soon as you cross zero. Both are in use, and both are below.

At a glance

Formula shown
a mod n is whatever is left after taking away whole copies of n. The identity a = qn + r holds in every convention; what changes is how q was rounded. Truncated rounds towards zero, floored rounds towards \u2212\u221e, and Euclidean forces r to be non-negative.
Scenario support
Wrapping an index around the end of an array; finding the day of the week a number of days ahead; matching a Python result from JavaScript, or the reverse.
Educational estimate
Planning support from the values you enter — not professional advice.

Why the answers differ

Every convention agrees on one thing: a = qn + r. The dividend is some whole number of copies of the divisor, plus a remainder. What they disagree about is which whole number.

For −7 and 3, the quotient could be −2 (rounding towards zero), leaving −7 = −2×3 + (−1). Or it could be −3 (rounding down), leaving −7 = −3×3 + 2. Both equations are true. The remainder simply follows whichever quotient you chose.

That is the entire disagreement. It is not about mathematics being unsettled — it is about a rounding decision made when the language was designed, and it only ever shows up when something is negative.

Which one your language uses

Truncated — C, C++, Java, JavaScript, Go, Rust, PHP, Swift. The remainder takes the sign of the dividend, so −7 % 3 is −1.

Floored — Python, Ruby, Perl, and Excel’s MOD function. The remainder takes the sign of the divisor, so −7 % 3 is 2 and 7 % −3 is −2.

Euclidean — number theory, and most proofs. The remainder is always non-negative regardless of either sign, which is the property that makes it useful in arguments.

This is a live source of bugs, and it is worth knowing that Excel disagrees with most of the languages people write next to it: MOD(-7, 3) is 2 in a spreadsheet and −1 in the C-family code reading that spreadsheet.

Clock arithmetic is the whole idea

A twelve-hour clock is arithmetic modulo 12. Nine hours after ten o’clock is seven, because 19 mod 12 = 7 — the numbers wrap.

That picture makes the negative case obvious rather than confusing. Three hours before two o’clock is eleven, and −1 mod 12 = 11. Counting backwards past zero simply continues round the circle; it does not produce a negative hour.

The page draws that circle for any modulus small enough to read. Positive numbers walk forwards round it and negative ones walk backwards, and the position you stop at is the answer.

Where modulo actually gets used

Wrapping an index. (i + 1) % length steps through a list and returns to the start. It is the standard idiom for a carousel, a ring buffer, or a turn order.

Days of the week. Weekdays repeat every 7, so any date arithmetic reduces to a modulo. It is why an ordinary year shifts the calendar by one day: 365 mod 7 = 1.

Check digits. ISBNs, IBANs and credit card numbers all end in a digit chosen so that a weighted sum comes out to a fixed value modulo 10, 11 or 97. A single mistyped digit changes the sum and the check fails.

Hashing and cryptography. A hash table maps a key to a bucket with a modulo. RSA and Diffie–Hellman are arithmetic modulo a large number and nothing else — which is what makes the exponent page worth reading.

Modulo is not the remainder

In everyday use the two words are interchangeable, and for positive numbers they are. For negatives they come apart, and the difference is worth naming.

The remainder is what a division leaves. Since division normally rounds towards zero, the remainder normally takes the sign of the dividend.

The modulus is a position on a cycle of n. Positions on a cycle are not negative — there is no “minus one o’clock” — so the modulus is normally taken non-negative.

Most languages named their operator % and implemented the remainder. Most textbooks wrote “mod” and meant the modulus. That mismatch is the whole reason this page shows both.

The rules it obeys

Modular arithmetic keeps the ordinary rules of addition, subtraction and multiplication. You can reduce at any point without changing the answer, which is what makes it practical.

(a + b) mod n = ((a mod n) + (b mod n)) mod n. The same holds for subtraction and multiplication. Reduce early and often; the result is identical and the numbers stay small.

Division is the exception. There is no dividing by 3 modulo 26 in the ordinary sense. You multiply by the modular inverse instead, and it only exists when the divisor shares no factor with the modulus — which is what the inverse page is about.

Exponents reduce too, but by a different modulus. akmod n depends on k modulo φ(n), not modulo n. Getting that wrong is a common slip, and it is why the exponent page names Euler’s theorem explicitly.

Sources and methodology

The conventions are language specifications rather than opinions — these are the specifications.

Method. The three conventions are derived from one division rather than computed separately: the truncated quotient comes first, the floored quotient is it adjusted when the remainder and the divisor disagree in sign, and the Euclidean quotient is the floored one corrected for a negative modulus. Each is returned with its own a = qn + r written out, and the suite asserts that identity across twenty thousand random pairs with negatives on both sides. That engine is verified on every change against 69 hand-written assertions, including that a = qn + r holds in all three conventions across twenty thousand random pairs, and that the Euclidean remainder always lands in [0, n). The count and the per-case breakdown are published on the formula verification page.

Related calculators

Where this goes next:

RemainderQuotient, remainder and the multiplication that checks them — plus the repeated subtraction that shows why a division has to stop.
Modular Exponentiation7^128 mod 13 without ever building the 109-digit power. Square-and-multiply is shown one exponent bit at a time, with the count of multiplications it saved.
Modular InverseThe number that undoes a multiplication modulo n, from the extended Euclidean algorithm — or the shared factor that proves no such number exists.
Divisibility TestEvery divisibility rule from 2 to 16 applied to your number, each with its working, the reason it holds, and the true remainder beside it as a check.
GCFThe greatest common factor of two to six numbers with all three routes shown — the shared primes to their lower powers, Euclid line by line, and the full factor lists when they are short enough to be honest.
Prime NumberWhether a number is prime, with a divisor named when it is not and the size of the search stated when it is. Deterministic, not probabilistic.

More in Math, or browse all calculators.

Read the guide

If the question is a school division rather than a congruence — how many times does it go in, and what is left — the Remainder Calculator lays it out that way, with the check and the repeated subtraction.

Educational use disclaimer

This is an educational tool. The arithmetic is exact; which convention your language uses is a fact about that language, and the page reports all three rather than deciding for you.

How we calculate · Found an error? email us

Authorship & verification

Written and maintained by , a business operator who builds spreadsheet-based calculators.

What's changed (3 updates)

Published 7 September 2026

  1. Published the modulo page giving the truncated, floored and Euclidean conventions together, since −7 mod 3 has two defensible answers and which one is right depends on the language you are matching.
  2. Each convention carries its own a = qn + r written out, so the reader can check the row rather than trust it.
  3. A wrap-around strip shows where the answer lands on a circle of n, which makes the negative case obvious instead of confusing.

Add this calculator to your site

Responsive embed — and private: nothing your visitors type leaves their browser.