a mod n in both conventions — the % your language returns AND the math mod that is never negative, plus floor quotient, modular power and inverse
- Runs locally
- Category Calculator
- Best for Getting a realistic range before a purchase, plan, workout, or schedule decision.
Truncated remainder (a % n)
-1
The % operator in JS, C, Java, Go, Rust. Sign follows the dividend a.
Euclidean / math mod
2
Always in [0, |n|). What number theory, clocks and crypto use.
Floor quotient ⌊a / n⌋
-3
Check: -7 = (-3)·3 + 2
Pairs with the Euclidean mod: a = q·n + r.
Modular inverse a⁻¹ mod n
a⁻¹ ≡ 2 (mod n), because a·2 ≡ 1
What this tool does
A modulo calculator that finally answers the question that trips up every programmer the first time they hit a negative number: what is -7 mod 3? Your language's % operator says -1; a number theorist says 2. Both are correct under their own convention, and this tool computes BOTH side by side so you never guess again. The "truncated" result is what JavaScript, C, Java, Go and Rust return from %, where the sign follows the dividend. The "Euclidean" result is the mathematician's residue, always in the range [0, |n|), which is what clock arithmetic, ring-buffer indexing and cryptography actually want. Alongside the two remainders you get the floor quotient that makes the division identity a = q·n + r hold exactly, modular exponentiation aᵇ mod n by fast square-and-multiply (so 2^1000000 mod 97 is instant and never builds the giant intermediate), and the modular multiplicative inverse via the extended Euclidean algorithm — with a clear "no inverse exists" when a and n share a factor. Every value is computed with JavaScript BigInt, so 40-digit operands stay exact instead of silently rounding the way doubles would. Inputs round-trip through the URL, so a share link reproduces the exact calculation.
Tool details
- Input
- Form fields
- The page exposes text boxes, numeric controls, file pickers, or structured inputs depending on the tool.
- Output
- Live result + Copy
- The result area focuses on usable output, with copy, download, or preview actions when supported.
- Privacy
- Browser-side processing
- The main tool logic does not call an external API, so inputs normally stay in the current tab.
- Save / share
- Shareable URL state
- Key settings are encoded in the URL so another person can reopen the same setup.
- Performance budget
- Initial JS <= 10 KB
- No WASM budget is declared, keeping the tool quick to open on mobile.
- Best fit
- Calculator · Developer
- Category and role tags drive related tools, internal links, and quick fit checks.
How to use
-
1. Input
Paste or drop your content into the tool panel.
-
2. Process
Click the button. All processing is local in your browser.
-
3. Copy / Download
Copy the result or download to disk in one click.
How Modulo Calculator fits into your work
Use it for fast estimates, comparisons, and planning numbers before you make the final call.
Calculation jobs
- Getting a realistic range before a purchase, plan, workout, or schedule decision.
- Comparing scenarios by changing one input at a time.
- Turning rough assumptions into a number you can discuss.
Calculation checks
- Double-check units, dates, rates, and rounding assumptions.
- Treat health, finance, tax, and legal outputs as planning aids, not professional advice.
- Save the inputs that produced an important result so you can reproduce it later.
Good next steps
These links move the current task into a more complete workflow.
- 1 GCD & LCM Calculator GCD + LCM of any list of integers — Euclidean steps, prime factorization, prime-factor table — exact BigInt math, browser-only Open
- 2 Number Base Converter Number base converter — binary, octal, decimal, hex, and any base 2-36. Bitwise too. Open
- 3 Scientific Calculator Scientific calculator — sin / cos / log / sqrt / power, with full keyboard input + history, deg/rad mode. Open
Real-world use cases
Wrap an array index that can go negative
You move a cursor left through a list of length 8 and want it to wrap to the end: index -1 should become 7. In JavaScript -1 % 8 is -1, which throws or returns undefined when you index with it. Paste a = -1, n = 8 and read the Euclidean result: 7. That is the formula ((i % n) + n) % n your code needs, confirmed in one place instead of debugging an off-by-one wrap in production.
Compute a day of the week
Zeller-style date math lands you on "day number" 17 and you want it mod 7 to pick a weekday. For positive inputs both conventions agree (17 mod 7 = 3), but when an offset calculation goes negative — say -4 mod 7 — you need 3, not -4. The calculator shows the Euclidean 3 so your weekday lookup table never indexes out of bounds.
Hash into a bucket without negative slots
A string hash returns a signed 32-bit value that can be negative, and you bucket it into a table of 1009 slots with hash mod 1009. With the truncated % a negative hash gives a negative bucket index and a crash. Drop the hash and 1009 in here, take the Euclidean column, and you get a valid 0..1008 slot every time.
Find an RSA private exponent by hand
For a teaching RSA example with e = 17 and φ(n) = 3120, the private key d is the modular inverse of e mod φ(n). Enter a = 17, n = 3120 and the tool returns d = 2753 via the extended Euclidean algorithm, then you can sanity-check it with the modular power field: 17·2753 mod 3120 should be 1. No paper-and-pencil Euclidean back-substitution required.
Verify a modular exponentiation in a crypto exercise
A Diffie–Hellman walkthrough asks for 5^117 mod 23. Typing 5^117 into a normal calculator overflows or rounds; here you enter a = 5, n = 23, exponent 117 and read the exact answer instantly, because the tool uses square-and-multiply with BigInt and never forms the 80-digit power.
Common pitfalls
Assuming -7 % 3 is 2 in C-family languages. It is -1 — the % operator there takes the sign of the dividend. If you need the always-non-negative result, use the Euclidean column or write ((a % n) + n) % n in your code.
Indexing an array directly with a raw % result. A negative dividend gives a negative index in most languages, which is out of bounds. Wrap with the Euclidean mod before indexing a ring buffer or hash bucket.
Expecting every number to have a modular inverse. The inverse of a mod n exists only when gcd(a, n) = 1. If a and n share a factor there is no inverse, and any value you get from a careless formula is simply wrong.
Privacy
Every calculation — both remainders, the floor quotient, modular exponentiation and the extended Euclidean inverse — is plain JavaScript that runs in your browser tab. No number you enter ever leaves the page, nothing is logged, and there is no external API call. One thing to know: the shareable URL encodes your inputs in the query string (e.g. ?a=-7&n=3), so pasting a share link records those numbers in the destination server's access log. For homework that is harmless; if a value is sensitive — say an RSA private exponent — copy the result manually instead of sharing the URL.
FAQ
Tool combos
Folks in your role tend to reach for these alongside this tool.
- Add Line Numbers Number every line of pasted text — set start, step and separator, zero-pad to align, skip blanks, or strip numbers back off — browser-only
- AES Text Encryptor Encrypt & decrypt text with a password — AES-256-GCM + PBKDF2 via WebCrypto — 100% in your browser, nothing uploaded
- Affine Cipher Encoder & Decoder Encrypt and decrypt the ax+b affine cipher with live modular-inverse check, browser-only
- AI Eval Planner Generate eval cases, pass criteria, and edge cases from an AI feature, risks, and user path.