ForHosting KIT · Math

Multiplicative inverse modulo n

Find the number that undoes multiplication by an integer modulo n: the inverse of 3 modulo 11 is 4, because 3 × 4 = 12 leaves remainder 1. It exists only when the two share no common factor. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Integer
3
Modulus
11
You get
Residue
3
Inverse
4
Gcd
1
Check
1

The multiplicative inverse of an integer modulo n is the residue inverse that satisfies integer times inverse congruent to one modulo n. That inverse exists if and only if the integer and the modulus 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 the integer and the modulus, runs the extended Euclidean algorithm deterministically, and returns the unique non-negative inverse in the range zero through n minus one, together with the reduced residue, the gcd, and a check product so you can verify the result without re-deriving the steps.

What a multiplicative inverse modulo n 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 inverse is a multiplicative inverse of an integer modulo n when integer times inverse leaves remainder one when divided by the modulus.

Because residues wrap around every n steps, not every integer has such an inverse. The obstruction is number-theoretic rather than floating-point: if d equals the gcd of the integer and the modulus and d is greater than one, then the integer times any candidate 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 integer times x plus modulus times y equal to one exactly when that gcd is one, and reducing x modulo n yields the inverse. Engineers meet this condition when they divide in a finite ring, 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. The calculator therefore treats a non-coprime pair as invalid input rather than inventing a placeholder inverse that would break any later check of the defining congruence.

How this calculator runs the extended Euclidean algorithm

Call the capability with integer fields integer and modulus, where the modulus is at least two. The implementation first reduces the integer into the non-negative residue class residue in zero through n minus one, then applies the extended Euclidean algorithm to the pair residue and modulus. Each step records the integer quotient and updates the Bézout coefficients so that at termination the coefficient of residue multiplies residue plus a coefficient of the modulus equals the gcd.

If the gcd is one, the coefficient of residue is reduced into the range zero through n minus one and returned as inverse. Absolute values are bounded by one trillion so every intermediate doubling in the modular product stays inside JavaScript safe-integer range. Negative integers are accepted and reduced before the Euclidean loop, so an input of negative three modulo eleven is treated as residue eight and inverted in that class.

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 whose absolute value is at most one trillion and moduli from two through one trillion. Results are deterministic: the same pair always yields the same inverse and the same check field.

Keep the pair inside the published bounds, treat a not-coprime error as a first-class outcome in your tests, and you get a reproducible inverse for homework, LMS plugins, and edge workers without standing up a computer-algebra system of your own.

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.

What happens if the integer and the modulus are not coprime?

The message includes gcd(integer, modulus) so you know why no multiplicative inverse exists. Failed validation is not charged.

Which algorithm computes the inverse?

The extended Euclidean algorithm. It finds Bézout coefficients for the reduced residue and the modulus; when the gcd is 1, the coefficient of the residue is reduced into the range 0..n−1.

Is the multiplicative inverse modulo n calculator free?

The browser tool runs free on your device.

What ranges of integer and modulus are accepted?

The integer may be any finite integer whose absolute value is at most one trillion. The modulus must be an integer from 2 through one trillion. Non-integers are rejected.

How can I check that the inverse is correct?

Multiply the number, reduced modulo n, by the inverse and divide by n: the remainder must be 1. That check is shown next to the result, together with the reduced number and the greatest common divisor, so you can verify it without redoing the steps.

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.

POSThttps://api.kit.forhosting.com/math/multiplicative-inverse-modulo

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.

curl -X POST https://api.kit.forhosting.com/math/multiplicative-inverse-modulo \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"integer":3,"modulus":11}'
{
  "integer": 3,
  "modulus": 11
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "math.multiplicative_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.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

max_abs1000000000000
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

How this calculator runs the extended Euclidean algorithm

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. The response also echoes integer, modulus, residue, gcd, and check equal to residue times inverse modulo n, which must be one whenever the call succeeds.

Practical use, limits, pricing, and delivery

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-ring 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.

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.

How do I compute a multiplicative inverse modulo n with this API?

Send JSON with integer fields integer and modulus (modulus ≥ 2). On success the response returns inverse in 0..n−1, plus residue, gcd, and check equal to 1.

Read the full KIT documentation →