Your result will appear here
Fill in the fields and press Calculate.
Modular arithmetic is "clock arithmetic": it wraps numbers around at a fixed value, giving the remainder after division. The clock itself is the everyday example — 3 hours after 11 o'clock is 2, not 14, because time works modulo 12. Beyond clocks, it's the backbone of cryptography, checksums, hashing and any cyclic pattern.
Enter a number (a) and a modulus (n), and a mod n — the remainder, the quotient and the check identity — is calculated instantly.
Modular Arithmetic Calculator: step-by-step worked example
If today is Monday, what day is it in 100 days? 100 mod 7 tells you.
- Number (a)
- 100
- Modulus (n)
- 7
- 1
Integer quotient (floored)
q = ⌊a ÷ n⌋
⌊100 ÷ 7⌋ = ⌊14.2857⌋ = 14
- 2
Multiple of the divisor
n × q
7 × 14 = 98
- 3
Remainder
a mod n = a − n × q (always 0 ≤ result < n)
100 − 98 = 2
- 4
Check
a = n × q + remainder
= 7 × 14 + 2 = 100
- n × q9898%
- Remainder22%
Good to know: The mathematical mod is always between 0 and n − 1: −100 mod 7 = 5, whereas many programming languages’ % returns −2. Days of the week, clock time and check digits all use modular arithmetic.
Modular Arithmetic Calculator — how it works
What a mod n means
a mod n is the remainder when a is divided by n. It satisfies a = n × quotient + remainder, with the remainder between 0 and n−1. So 17 mod 5 = 2, because 17 = 5 × 3 + 2.
The division identity
Every result comes with its check: a = n × q + r. For 17 mod 5, that's 17 = 5 × 3 + 2 — the quotient (3) and remainder (2) reconstruct the original. The tool shows this identity so the answer is verifiable at a glance.
Negative numbers
Conventions differ for negative a. In the common mathematical convention the remainder is kept non-negative: −7 mod 3 = 2 (since −7 = 3 × (−3) + 2). Some programming languages return −1 instead; the tool follows the non-negative convention.
Where it's used
- Clocks and calendars: hours modulo 12 or 24, days of the week modulo 7.
- Cryptography: RSA and Diffie-Hellman are built on modular exponentiation.
- Checksums and hashing: distributing values into buckets, validating IDs.
- Cyclic patterns: anything that repeats on a fixed cycle.
Worked example
Compute 17 mod 5: dividing 17 by 5 gives a quotient of 3 with 2 left over, so 17 mod 5 = 2. The check identity confirms it: 17 = 5 × 3 + 2. As a real-world parallel, "what time is it 17 hours after midnight?" is 17 mod 24 = 17 (5 pm), while 30 hours after midnight is 30 mod 24 = 6 (6 am) — the clock wrapping around is modular arithmetic in action.
Frequently asked questions
How is a mod n calculated?+
It is the remainder when a is divided by n: 17 mod 5 = 2, because 17 = 5 × 3 + 2. The tool shows the remainder, the quotient and the check identity.
What does "mod" mean in everyday terms?+
It is clock arithmetic — numbers wrap around at n. 3 hours after 11 o'clock is 2, because time runs modulo 12. The remainder after division is the result.
How does modular arithmetic handle negative numbers?+
In the common mathematical convention the remainder stays non-negative: −7 mod 3 = 2. Some programming languages return a negative remainder instead; this tool uses the non-negative convention.
What is the division identity in modular arithmetic?+
a = n × quotient + remainder. For 17 mod 5 it is 17 = 5 × 3 + 2 — the quotient and remainder reconstruct the original number, which verifies the result.
Where is modular arithmetic used?+
In clocks and calendars, cryptography (RSA, Diffie-Hellman), checksums and hashing, and any system with a repeating cycle. It is fundamental to computer science.
What is the range of a mod n?+
The result is always between 0 and n−1. For n = 5 the possible results are 0, 1, 2, 3 and 4.
About this page
- Publisher:
- Kalkoro — Teknolojig Bilişim Teknolojileri A.Ş., İstanbul
- Written by:
- Ahmet Tur — Editor (Math, date & time, unit conversion, physics & chemistry, everyday tools)
- Reviewed by:
- Kübra Yıldız — Editor
Parameters come from official sources; the last update date is shown at the bottom of the page.
Spotted a wrong result? Use the "Report a bug" button at the top of the page; every report is reviewed.
How we calculate and our accuracy policy →
Results are for information only. For official matters the relevant authority's calculation prevails.
Last updated: