Inverse modulo calculator
The inverse of 3 modulo 11 is 4, because 3 times 4 is 12, which leaves remainder 1. Enter a and the modulus to get the unique inverse from 0 to m minus one, or a clear notice when none 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
- M
- 11
- A mod
- 3
- Inverse
- 4
- Gcd
- 1
- Check
- 1
Inverse modulo answers a single exact-arithmetic question: given integers a and m, which residue x in the range zero through m minus one satisfies a times x congruent to one modulo m? That residue is the multiplicative inverse of a modulo m, and it exists if and only if a and m are coprime — their greatest common divisor is one. Cryptography notes, contest solutions of linear congruences, modular division, and cyclic-group homework all ask for this inverse, yet many languages expose only a binary gcd and leave Bézout coefficients to you. This inverse modulo calculator accepts integers a and m, runs the extended Euclidean algorithm, and returns the unique non-negative inverse together with a check product you can verify without re-deriving the steps.
What inverse modulo means and when the residue exists
Inverse modulo names the integer x that undoes multiplication by a inside the residue ring of integers modulo m. In symbols we write a times x congruent to one modulo m, or a x ≡ 1 (mod m), and we call x the modular multiplicative inverse of a modulo m. Ordinary arithmetic always has an inverse for every non-zero number because dividing by that number yields one.
Modular arithmetic is stricter. Residues wrap every m steps, so a times any integer is a multiple of gcd(a, m). If that gcd is greater than one, the product can never be congruent to one, which is not a multiple of the gcd.
Conversely Bézout's identity guarantees integers x and y such that a x plus m y equals one exactly when gcd(a, m) equals one, and reducing x into the range zero through m minus one yields the unique inverse that this calculator returns. Students meet the same condition when they divide in a finite field, when they invert a public RSA exponent modulo Euler's totient, when they undo a modular multiply in a hash pipeline, or when they solve the linear congruence a x ≡ 1 (mod m) in contest programming.
Searching for inverse modulo is the everyday phrasing of that question: given a and m, what residue multiplies a back to one.
Where an inverse modulo calculator earns its keep
Classrooms and tutoring platforms use a dedicated inverse modulo tool so learners can check a inverse modulo m without hand-running Euclidean steps or trusting a handheld calculator that silently loses precision past two to the fifty-three. Exam generators and learning-management graders need a deterministic oracle that marks a non-coprime pair as invalid instead of accepting a sentinel a buggy student script might also emit. Failed validation and non-coprime pairs do not consume balance.
Keep requests inside the published magnitude limits, pin the inverse in tests, and you get reproducible residues for homework, LMS plugins, and edge workers without standing up symbolic math infrastructure of your own. The capability does not solve general linear congruences a x ≡ b (mod m) for b other than one, does not compute discrete logarithms, and does not invert real numbers without a modulus; those are different search intents served by other catalog entries.
What you can do with it
Crypto labs and modular-division helpers
Invert public exponents modulo φ(n), undo modular multiplies, or replace ad-hoc extended-gcd snippets with one exact call inside documented bounds.
FAQ
What happens if a and m are not coprime?
The message includes gcd(a, m) so you know why no inverse exists. Failed validation is not billed.
Which algorithm computes inverse modulo?
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.
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.
How do I check that an inverse modulo is correct?
Multiply a by the inverse and divide the result by m: the remainder must be 1. With a of 3 and m of 11, the inverse 4 gives 12, which leaves remainder 1. The calculator shows that check next to the result.
What is a modular inverse used for?
It lets you divide in modular arithmetic, solve linear congruences, work in finite fields or invert a public RSA exponent modulo Euler's totient. It turns up in cryptography notes, contest programming and cyclic-group homework.
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/math/inverse-modulo \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"a":3,"m":11}'const res = await fetch("https://api.kit.forhosting.com/math/inverse-modulo", {
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/math/inverse-modulo",
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/math/inverse-modulo", 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/math/inverse-modulo", 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": "math.inverse_modulo",
"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
When a and m are not coprime the task fails with invalid_input instead of inventing a residue.
What inverse modulo means and when the residue exists
Returning a typed invalid_input error when the pair is not coprime is more useful than a silent zero: the client learns that no inverse exists and can branch on the gcd instead of guessing which library returned a wrong residue. The modulus must be an integer of at least two so that the residue system is non-trivial; a modulus of one collapses every integer to the same class and is rejected as invalid_input rather than a hollow success.
Input contract, extended Euclidean algorithm, and errors
Classic checks: a equals three and m equals eleven yields inverse four because three times four is twelve, which leaves remainder one; a equals seven and m equals twenty-six yields inverse fifteen. POST a JSON body with two required integers: a, the integer whose inverse modulo m is sought, and m, a modulus of at least two. Each field may arrive as a JSON number or as a decimal integer string; missing fields, empty strings, fractions, and non-numeric values fail with invalid_input naming the field. Absolute values may not exceed one trillion so every intermediate product stays inside a Worker isolate. 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 and states that a and m are not coprime; 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, check equal to a_mod times inverse modulo m (always one on success), and a formula string restating the identity (a times inverse) congruent to one modulo m. Pair the response with your own typesetting if you need a rendered superscript minus one; this endpoint computes the inverse only and does not emit plots or step-by-step prose beyond the formula field.
Where an inverse modulo calculator earns its keep
Programming-contest coaches, RSA teaching sandboxes, finite-field demos, and modular-division helpers all invert an integer inside a fixed residue range; calling a tiny parse API avoids reimplementing extended gcd in every language and avoids pulling a computer-algebra system for two integers.
Integration use cases
Classroom inverse-modulo checks
Let students submit a and m and verify the unique residue x with (a · x) ≡ 1 (mod m), or see a clear invalid_input when the pair is not coprime.
Contest oracles and LMS auto-grading
Mark inverse-modulo items with a deterministic inverse and reject non-coprime inputs as invalid_input instead of silently returning a hollow zero.
Technical questions
How do I compute the inverse of a modulo m?
Send JSON with integer fields a and m (m ≥ 2). On success the response returns inverse in 0..m−1, plus a_mod, gcd (always 1), check (always 1), and the identity formula.
What does the inverse modulo calculator cost?
The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid or non-coprime input is not billed.