Modular Arithmetic Calculator

Result2
Quotient3
Check17 = 3 x 5 + 2
How this was calculated
  1. A remainder is what is left after dividing by the modulus: a mod m is a minus the largest multiple of m that fits in a, always landing between 0 and m - 1.
  2. With a = 17 and m = 5, 17 divided by 5 gives a quotient of 3 and a remainder of 2.
  3. Check: 17 = 3 x 5 + 2.

A modular arithmetic calculator works out the remainder left when one number is divided by another, and it handles addition, subtraction, multiplication, powers and inverses under a modulus. The rule is simple: do the operation first, then take the remainder on dividing by the modulus. You can also reduce each number first and then operate, which is how the calculation stays small. For example, 17 mod 5 is 2: the quotient is 3, and the check is 17 = 3 x 5 + 2. Likewise, 7^3 mod 13 is 5, since 7 mod 13 is 7 and 3 mod 13 is 3. The inverse of 3 mod 11 is 4, because gcd(3, 11) is 1, and the check is 3 x 4 = 1 (mod 11).

Reducing first is the accepted standard because it keeps every intermediate step small instead of letting the numbers grow. A modular inverse exists only when a and the modulus share no common factor, and the extended Euclidean algorithm finds it. The same reduce-first trick is what makes RSA encryption possible, because huge powers stay small when every step is reduced modulo m. This page shows the formula, step-by-step workings, worked examples and sources, so you can follow each calculation and check the result yourself.

Worked examples

17 mod 5

17 mod 5 is 2 - the quotient is 3, and the check is 17 = 3 x 5 + 2. (17 · 5 · 5 · a mod m)

Result2
Quotient3
Check17 = 3 x 5 + 2

7^3 mod 13

7^3 mod 13 is 5 - 7 mod 13 is 7 and 3 mod 13 is 3. (7 · 3 · 13 · a^b mod m)

Result5
a mod m7
b mod m3

Inverse of 3 mod 11

The inverse of 3 mod 11 is 4 - gcd(3, 11) is 1, and the check is 3 x 4 = 1 (mod 11). (3 · 5 · 11 · Inverse of a mod m)

Result4
gcd(a, m)1
Check3 x 4 = 1 (mod 11)

What modular arithmetic is

Modular arithmetic is the arithmetic of remainders. Instead of asking what a number is, it asks what is left over after you divide that number by a fixed value called the modulus. The phrase "17 mod 5 is 2" says exactly this: divide 17 by 5, get a quotient of 3, and a remainder of 2. The check is simple and worth remembering: 17 = 3 x 5 + 2. Every result in modular arithmetic is a remainder, so every result is smaller than the modulus. That single property is what makes the subject useful.

There are two ways to compute a modular expression, and they give the same answer. One way is to do the operation first and then take the remainder on dividing by the modulus. The other is to reduce each number first and then operate. The second route is the one that keeps the calculation small, and it is why a modular arithmetic calculator can handle expressions that would otherwise involve enormous numbers. You never have to carry a value larger than the modulus from one step to the next.

A worked example shows how little the numbers grow. Consider 7^3 mod 13. Here 7 mod 13 is 7 and 3 mod 13 is 3, so the inputs are already reduced. The point is not that this particular example is hard, but that the same reduce-first habit scales to powers that would be unmanageable if computed in full. Each multiplication can be trimmed back to a remainder below the modulus before the next one begins.

Reduction also controls what operations are possible. Division in modular arithmetic is not ordinary division; it uses a modular inverse. The inverse of 3 mod 11 is 4, because gcd(3, 11) is 1, and the check is 3 x 4 = 1 (mod 11). A modular inverse exists only when a and the modulus share no common factor, and the extended Euclidean algorithm finds it when one does. When the two numbers do share a factor, no inverse exists and the division has no answer.

The same reduce-first trick is what makes RSA encryption possible, because huge powers stay small when every step is reduced modulo m. That is the practical payoff of a concept that starts with a simple remainder. Whether you are checking a homework problem or building a secure system, the modular arithmetic calculator is doing the same thing: keeping every intermediate value below the modulus so the work stays exact and the numbers stay small.

  • 17 mod 5 is 2: the quotient is 3, and the check is 17 = 3 x 5 + 2.
  • 7^3 mod 13 is 5: 7 mod 13 is 7 and 3 mod 13 is 3.
  • The inverse of 3 mod 11 is 4: gcd(3, 11) is 1, and the check is 3 x 4 = 1 (mod 11).
  • A modular inverse exists only when a and the modulus share no common factor; the extended Euclidean algorithm finds it.
Reduce first, then operate. Taking the remainder at every step keeps every number below the modulus, which is why the calculation stays small.

The six operations

A modular arithmetic calculator handles six basic operations, and each one follows the same rule: do the operation and then take the remainder on dividing by the modulus. Equivalently, you can reduce each number first and then operate, which is how the calculation stays small. That single habit — reduce early, reduce often — is what separates a quick mental answer from a page of long division.

The first operation is the plain remainder, written a mod m. Take 17 mod 5. The quotient is 3, and the check is 17 = 3 x 5 + 2, so 17 mod 5 is 2. Addition, subtraction and multiplication work the same way: combine the two numbers, then reduce. Because you may reduce each input before combining, you never have to carry numbers larger than the modulus itself.

Powers are where the reduce-first trick earns its keep. For 7^3 mod 13, note that 7 mod 13 is 7 and 3 mod 13 is 3; raising and reducing at each step keeps every intermediate value below 13, and the result is 5. The same logic is what makes RSA encryption possible, because huge powers stay small when every step is reduced modulo m. A calculator that reduced only at the end would choke on the exponents real cryptography uses.

The sixth operation, the modular inverse, answers a different question: which number, multiplied by a, gives 1 modulo m? The inverse of 3 mod 11 is 4, since gcd(3, 11) is 1 and the check is 3 x 4 = 1 (mod 11). A modular inverse exists only when a and the modulus share no common factor, and the extended Euclidean algorithm finds it when it does. If the gcd is greater than 1, no inverse exists, and a good tool should say so rather than return a guess.

Run all six through a modular arithmetic calculator and the pattern is consistent: reduce first, keep the numbers small, and verify with the division check. The worked examples above — 17 mod 5, 7^3 mod 13 and the inverse of 3 mod 11 — show the full range, from a single remainder to the inverse that underpins public-key cryptography.

Quick checks: 17 = 3 x 5 + 2, so 17 mod 5 is 2. 7^3 mod 13 is 5. 3 x 4 = 1 (mod 11), so the inverse of 3 mod 11 is 4.

The modular inverse

Division is the one basic operation that modular arithmetic does not hand you directly, and that is where the modular inverse comes in. The inverse of 3 mod 11 is 4, because gcd(3, 11) is 1 and the check is 3 x 4 = 1 (mod 11). In other words, multiplying by 4 undoes multiplying by 3 when you are working modulo 11, so dividing by 3 becomes the same as multiplying by 4. A modular arithmetic calculator uses this idea whenever it has to solve a congruence of the form a x ≡ b (mod m).

The inverse does not always exist. A modular inverse exists only when a and the modulus share no common factor, that is, when gcd(a, m) = 1. When they do share a factor, no number can multiply a back to 1 modulo m, so the calculator should report that the inverse does not exist rather than return a guess. This is also why the modulus is often chosen to be prime: every number from 1 to m - 1 is then coprime to it, so an inverse is always available.

Finding the inverse is a job for the extended Euclidean algorithm. It runs the ordinary Euclidean algorithm on a and the modulus, tracking at each step how the current remainder can be written as a combination of the original two numbers. When the gcd comes out as 1, those tracking coefficients give the inverse directly. For 3 and 11, the algorithm confirms gcd(3, 11) = 1 and produces the coefficient 4, which is the inverse of 3 mod 11. The final check is the one shown above: 3 x 4 = 12, and 12 mod 11 is 1, so 3 x 4 = 1 (mod 11).

The same reduce-first habit that keeps ordinary modular calculations small is what makes the inverse practical at real sizes. Modular arithmetic does the operation first and then takes the remainder on dividing by the modulus, or equivalently reduces each number first and then operates, which is how the calculation stays small. That is exactly the trick behind RSA encryption: huge powers stay small when every step is reduced modulo m, and the modular inverse supplies the matching decryption step.

Quick check: the inverse of 3 mod 11 is 4, since gcd(3, 11) = 1 and 3 x 4 = 12 ≡ 1 (mod 11).

Where modular arithmetic matters

Modular arithmetic is not an abstract curiosity. It is the arithmetic behind some of the most familiar systems you use every day, and a modular arithmetic calculator makes those systems easy to check by hand. The core idea is simple: do the operation first and then take the remainder on dividing by the modulus — or, equivalently, reduce each number first and then operate, which is how the calculation stays small. Both routes give the same answer, and the second is what keeps real-world computations from growing out of control.

Clocks and calendars are the most visible examples. A 12-hour clock wraps around at 12, so "4 hours after 11" is 3, not 15. That is arithmetic modulo 12. Calendars work the same way: days of the week repeat every 7, so a date 100 days from now falls on the same weekday as a date 2 days from now, because 100 mod 7 is 2. The same wrap-around logic handles months and leap-year cycles. When you ask what day of the week a future date lands on, you are really asking a modular question.

Checksums and hash functions rely on modular arithmetic to compress data into a short, fixed-size value. A checksum takes the digits or bytes of a message, combines them with addition or multiplication, and reduces the result modulo some chosen number. The remainder is a compact fingerprint: if a single digit changes, the remainder usually changes too, which is how errors are caught. Hash functions do something similar at a larger scale, mixing input data and reducing modulo a large value so that the output stays a fixed width no matter how long the input is.

Public-key encryption is where modular arithmetic becomes essential. RSA works with a modulus that is the product of two large primes, and its security rests on the difficulty of factoring that product. The same reduce-first trick is what makes RSA encryption possible, because huge powers stay small when every step is reduced modulo m. Raising a number to a large exponent directly would produce an astronomically large integer; reducing after every multiplication keeps every intermediate value below the modulus. The modular inverse is the other half of the story: decryption needs the inverse of the encryption exponent, and a modular inverse exists only when a and the modulus share no common factor. The extended Euclidean algorithm finds it. For a small taste, the inverse of 3 mod 11 is 4 — gcd(3, 11) is 1, and the check is 3 x 4 = 1 (mod 11).

You can verify each of these ideas with a modular arithmetic calculator. Check that 17 mod 5 is 2 — the quotient is 3, and the check is 17 = 3 x 5 + 2. Try 7^3 mod 13, which is 5, since 7 mod 13 is 7 and 3 mod 13 is 3. Then confirm the inverse of 3 mod 11 is 4. Working through small examples by hand builds the intuition that makes the large-number applications — checksums, hashes and RSA — easier to understand.

Reduce first, operate second: keeping every intermediate value below the modulus is what lets clocks, checksums and RSA all use the same arithmetic.

FAQs

What is 17 mod 5?

17 mod 5 is 2. The quotient is 3, and the check confirms it: 17 = 3 x 5 + 2. Modular arithmetic gives the remainder after division, so you subtract the largest multiple of 5 that fits into 17, which is 15, leaving 2.

What is 7^3 mod 13?

7^3 mod 13 is 5. You can work it step by step: 7^3 is 343, and dividing 343 by 13 leaves a remainder of 5. The modular result is that remainder, so the answer to 7^3 mod 13 is 5.

What is the inverse of 3 mod 11?

The inverse of 3 mod 11 is 4, because 3 x 4 = 1 (mod 11). Multiplying 3 by 4 gives 12, and 12 mod 11 is 1. A modular inverse is the number that, multiplied by the original, produces a remainder of 1 under the modulus.

When does a modular inverse exist?

A modular inverse exists only when a and the modulus share no common factor, meaning their gcd is 1. If the two numbers have a common factor greater than 1, no number multiplied by a will leave a remainder of 1 under that modulus, so the inverse cannot exist.

How do you find a modular inverse?

You find a modular inverse with the extended Euclidean algorithm. This method works backward through the Euclidean algorithm's steps to express the gcd of the two numbers as a combination of them, which yields the inverse when the gcd is 1.

Where is modular arithmetic used?

Modular arithmetic is used in clocks and calendars, checksums, hash functions and RSA encryption. Clock time wraps around after 12 hours, checksums and hash functions rely on remainders to detect or summarize data, and RSA encryption depends on modular exponentiation and modular inverses.

Sources

Related calculators

Percentage Calculator
Four percentage jobs in one tool: X% of Y, X as a % of Y, percentage change, and increasing or decreasing a number by a percent.
Roman Numerals Calculator
Convert any number from 1 to 3,999 into Roman numerals, with the symbol-by-symbol breakdown — including the subtractive pairs like CM, XC and IV.
Number Base Converter
Number base converter: a decimal number in binary, octal and hexadecimal, with the bits and bytes it needs.