Modular multiplicative inverse
Find the number that undoes a multiplication modulo m: the inverse of 3 modulo 11 is 4, because 3 times 4 leaves the remainder 1. You also see the gcd and a check value, and a clear message when no inverse exists. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- A
- 3
- Modulus m ≥ 2
- 11
- A mod
- 3
- Inverse
- 4
- Gcd
- 1
- Check
- 1
The modular multiplicative inverse of an integer a modulo m is the residue x that satisfies a times x congruent to one modulo m. That inverse exists if and only if a and m are coprime—their greatest common divisor is one. Cryptography tutorials, RSA private-key steps, modular division in contest programming, and cyclic-group calculations all need this operation, yet many languages only expose a binary GCD and leave the Bézout coefficients to you. This calculator takes a and m, runs the extended Euclidean algorithm deterministically, and returns the unique non-negative inverse in the range zero through m minus one, together with the gcd and a check product so you can verify the result without re-deriving the steps.
What a modular inverse is and when it exists
In ordinary arithmetic every non-zero number has a multiplicative inverse: divide by it and you get one. In modular arithmetic the same idea becomes a congruence. We say x is a modular inverse of a modulo m when a times x leaves remainder one when divided by m.
Because residues wrap around every m steps, not every a has such an x. The obstruction is number-theoretic rather than floating-point: if d equals gcd of a and m and d is greater than one, then a times any integer is a multiple of d, so the product can never be congruent to one, which is not a multiple of d.
Conversely, Bézout’s identity guarantees integers x and y with a x plus m y equal to one exactly when that gcd is one, and reducing x modulo m yields the inverse. Engineers meet this condition when they divide in a finite field, when they choose RSA decryption exponents that invert the public exponent modulo phi of n, when they undo modular multiplications in hash pipelines, or when they solve linear congruences in competitive programming.
Returning an explicit error when the pair is not coprime is more useful than a silent failure: the client learns that no inverse exists and can branch on the gcd instead of guessing which of several libraries returned a wrong residue.
What you can do with it
Crypto and RSA teaching labs
Instructors and students can invert public exponents modulo φ(n) on demand and inspect the gcd when a sample modulus is not coprime to the exponent.
Contest programming and modular division
Competitive programmers can replace ad-hoc extended-GCD snippets with a single deterministic call when verifying modular division under prime or composite moduli.
FAQ
What happens if a and m are not coprime?
The message includes gcd(a, m) so you know why no modular multiplicative inverse exists. Failed validation is not charged.
Which algorithm computes the inverse?
The extended Euclidean algorithm. It finds Bézout coefficients for a mod m and m; when the gcd is 1, the coefficient of a is reduced into the range 0..m−1.
Is the modular inverse calculator free?
The browser tool runs free on your device.
What ranges of a and m are accepted?
m must be an integer from 2 through 1,000,000,000,000. a must be an integer whose absolute value is at most that same bound. Values outside those limits are rejected.
What is the inverse of 3 modulo 11?
It is 4. Multiplying 3 by 4 and dividing by 11 leaves the remainder 1, which is exactly what an inverse must do. The check value shown next to the answer is that 1.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/numth/modular-inverse \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"a":3,"m":11}'const res = await fetch("https://api.kit.forhosting.com/numth/modular-inverse", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"a": 3,
"m": 11
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/numth/modular-inverse",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"a": 3,
"m": 11
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/numth/modular-inverse", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"a":3,"m":11}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"a":3,"m":11}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/numth/modular-inverse", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"a": 3,
"m": 11
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "numth.modular_inverse",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Limits
max_abs | 1000000000000 |
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
How this calculator runs the extended Euclidean algorithm
Call the capability with integer fields a and m, where m is at least two. Absolute values are bounded by one trillion so every intermediate product stays inside JavaScript safe-integer range. The implementation first reduces a into the non-negative residue class a_mod in zero through m minus one, then applies the extended Euclidean algorithm to the pair a_mod and m. Each step records the integer quotient and updates the Bézout coefficients so that at termination the coefficient of a_mod multiplies a_mod plus a coefficient of m equals the gcd. If that gcd is not one, the request fails with invalid_input and a message that names both inputs and the gcd; nothing is charged. If the gcd is one, the coefficient of a_mod is reduced into the range zero through m minus one and returned as inverse. The response also echoes a, m, a_mod, gcd, and check equal to a_mod times inverse modulo m, which must be one whenever the call succeeds.
Practical use, limits, pricing, and delivery
Use the browser tool when you want a quick inverse while reading a crypto note, checking a homework congruence, or debugging a modular multiplication step. Accepted inputs are integers a with absolute value at most one trillion and moduli m from two through one trillion. Results are deterministic: the same pair always yields the same inverse and the same check field. Use the API when a script, grader, or educational platform needs many inverses without embedding an extended-GCD routine. Each successful request is one billable item at $0.002; validation failures and non-coprime pairs do not consume balance. Wire the endpoint into RSA teaching sandboxes, finite-field demos, contest-programming helpers, or any integer pipeline that already prefers exact arithmetic over approximate heuristics. Because the unit is a single item and the engine is pure parse, latency stays low and the free web channel mirrors the paid API without a second code path that could drift.
Integration use cases
Homework checkers and number-theory pipelines
Automated graders and scripts can confirm inverses, detect non-coprime inputs via invalid_input, and keep every intermediate product inside documented bounds.
Technical questions
How do I compute a modular inverse with this API?
Send JSON with integer fields a and m (m ≥ 2) to numth.modular_inverse. On success the response returns inverse in 0..m−1, plus a_mod, gcd, and check equal to 1.