Home › Calculators › Modular Inverse Calculator

Modular Inverse Calculator

Enter a number a and a modulus m to find x such that a × x ≡ 1 (mod m). The calculator checks that the inverse exists (gcd(a, m) = 1), shows every step of the extended Euclidean algorithm and works with integers hundreds of digits long.

Last updated:

Whole number, can be negative or huge. Expressions like 2^64+1 work.

Whole number ≥ 2

Enter your values to see the result.
Advertisement
Advertisement

How to use the Modular Inverse Calculator

  1. Enter a, the number you want to invert.
  2. Enter the modulus m (2 or more). Powers like 2^61-1 are accepted.
  3. Press Calculate inverse to get a⁻¹ mod m.
  4. Read the steps: the Euclidean divisions and the back-substitution.
  5. Copy the result or download the algorithm table as CSV.

Extended Euclidean algorithm: worked example

Find 17⁻¹ mod 3120. Divide repeatedly, keeping track of how each remainder is built from 3120 and 17:

DivisionRemainderAs s·3120 + t·17
3120 = 183 × 17 + 991·3120 − 183·17
17 = 1 × 9 + 88−1·3120 + 184·17
9 = 1 × 8 + 112·3120 − 367·17

The gcd is 1, so the inverse exists, and 2·3120 − 367·17 = 1. Reducing mod 3120 gives t = −367 ≡ 3120 − 367 = 2753. Check: 17 × 2753 = 46,801 = 15 × 3120 + 1 ✓.

Small inverse table (mod 11)

Because 11 is prime, every number from 1 to 10 has an inverse modulo 11. Notice that 1 and 10 (≡ −1) are their own inverses.

a12345678910
a⁻¹ mod 1116439287510

Tips

  • To solve a linear congruence a·x ≡ b (mod m) with gcd(a, m) = 1, multiply both sides by the inverse: x ≡ b · a⁻¹ (mod m).
  • The inverse is unique modulo m: there is exactly one answer between 0 and m − 1.
  • For modulus 26 (the alphabet), only the 12 numbers coprime to 26 (1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25) have inverses, which is why affine ciphers restrict their key.

Frequently asked questions

What is a modular inverse?

The modular (multiplicative) inverse of a modulo m is the number x between 0 and m − 1 with a × x ≡ 1 (mod m). For example 3⁻¹ mod 11 = 4, because 3 × 4 = 12 = 11 + 1. It plays the role of division in modular arithmetic.

When does a modular inverse exist?

Exactly when a and m are coprime, i.e. gcd(a, m) = 1. If they share a factor g > 1, every multiple of a leaves a remainder that is a multiple of g, so it can never be 1. For example 6 has no inverse mod 9 because gcd(6, 9) = 3. If m is prime, every a not divisible by m has an inverse.

How does the extended Euclidean algorithm find the inverse?

It runs the ordinary Euclidean algorithm for gcd(a, m) while tracking coefficients s and t so that every remainder equals s·m + t·a. When the remainder reaches gcd = 1 you have s·m + t·a = 1, and reducing this mod m leaves t·a ≡ 1, so t mod m is the inverse.

How is the modular inverse used in RSA?

The private exponent d is the inverse of the public exponent e modulo φ(n) (or λ(n)). In the classic textbook example e = 17 and φ(n) = 3120 give d = 17⁻¹ mod 3120 = 2753, because 17 × 2753 = 46,801 = 15 × 3120 + 1.

Can I use Fermat's little theorem instead?

Yes, when m is prime: a⁻¹ ≡ a^(m − 2) (mod m). For 3 mod 11 that is 3⁹ mod 11 = 4. The extended Euclidean algorithm is faster and also works when m is not prime, which is why this calculator uses it.

What about negative numbers?

A negative a is first reduced to the range 0 to m − 1 (−7 mod 26 = 19), then inverted. The answer is given as the smallest positive inverse; any value that differs by a multiple of m, such as the negative representative shown, is also an inverse.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

Modulo CalculatorCalculate a mod n and the quotient, with floored, truncated and Euclidean rules.Modular Exponentiation CalculatorCompute a^b mod m for huge numbers with square-and-multiply steps (BigInt).GCF and LCM CalculatorFind the GCF and LCM of two or more numbers with Euclid steps and prime factorization.Big Number CalculatorExact + − × ÷ mod and powers for huge integers with hundreds of digits, plus digit count.Graphing CalculatorPlot multiple functions with zoom, pan, intersections and a value table.Exponent CalculatorRaise any number to a power, including negative and fractional exponents.Logarithm CalculatorCalculate log in any base, ln, log10, log2 and antilog with change-of-base steps.Quadratic Equation SolverSolve ax² + bx + c = 0 with exact roots, steps, vertex and a parabola graph.Matrix CalculatorAdd, multiply, invert and row-reduce matrices up to 5×5 with exact fractions and steps.Prime Number CheckerCheck if a number is prime, factor it with a factor tree and list primes in a range.Cubic Yard CalculatorConvert length, width and depth in any unit to cubic yards, cubic feet, m³ and material weight.Factorial CalculatorExact n! up to 5000! with digit count, trailing zeros and double factorial.Prime Factorization CalculatorFind prime factors in exponent form with a factor tree, divisor count and divisors list.Exponential Growth CalculatorExponential growth and decay: final amount, rate or time, discrete or continuous.Linear Regression CalculatorLeast-squares line of best fit: slope, intercept, r, r², predictions and a scatter plot.System of Equations SolverSolve 2×2, 3×3 and 4×4 linear systems with exact fractions and step-by-step working.Cubic Equation SolverSolve ax³ + bx² + cx + d = 0 for real and complex roots with steps and a graph.Summation CalculatorEvaluate sigma notation: sum any expression in n from a to b with partial sums and a chart.Arithmetic Sequence CalculatorFind the n-th term, sum and full list of an arithmetic sequence, or d from two terms.Geometric Sequence CalculatorFind the n-th term, sum and infinite sum of a geometric sequence, or r from two terms.Fibonacci CalculatorExact n-th Fibonacci number (BigInt), sequence lists, Fibonacci check and golden ratio.Factors CalculatorAll factors and factor pairs of a number, prime factors, divisor count and perfect check.Depth of Field CalculatorNear and far focus limits, depth of field and hyperfocal distance for any camera or lens.Crop Factor CalculatorCrop factor, full-frame equivalent focal length and aperture, and field of view for any sensor.Completing the Square CalculatorRewrite ax² + bx + c in vertex form a(x − h)² + k step by step and solve it.Derivative CalculatorSymbolic derivative of any f(x) up to 5th order, with steps, slope at a point and a graph.Exposure Value CalculatorEV from aperture, shutter and ISO, or solve any missing setting with sunny 16 presets.Factoring Trinomials CalculatorFactor trinomials and polynomials: GCF, ac method, difference of squares, cubes, with steps.Integral CalculatorDefinite integral of f(x) from a to b with adaptive Simpson, area graph and antiderivative.Least Common Denominator CalculatorFind the LCD of two or more fractions and rewrite them as equivalent fractions, with steps.Limiting Reactant CalculatorFind the limiting reactant, theoretical yield and leftover excess from an equation.Parabola CalculatorVertex, focus, directrix, axis, intercepts and graph of a parabola from its equation.Polynomial Root FinderFind all real and complex roots of a polynomial up to degree 10, with the factored form.Prime Number List GeneratorList all primes in a range or the first N primes with a fast sieve; copy or download the list.Quadratic Regression CalculatorFit y = ax² + bx + c (or up to degree 6) to x, y data with R², predictions and a graph.Scatter Plot MakerPaste X,Y pairs for a scatter plot with trendline, equation, r and R². Download PNG.Synthetic Division CalculatorDivide polynomials by x − c (synthetic table) or any polynomial (long division) with steps.3D Graphing CalculatorPlot z = f(x, y) surfaces and 3D parametric curves; rotate, zoom, add contours, save PNG.Stem and Leaf Plot MakerMake stem-and-leaf plots (standard, split stems or back-to-back) with a key; copy or save PNG.Taylor Series CalculatorTaylor and Maclaurin polynomials of any f(x) to order n, with exact coefficients and a graph.Antilog CalculatorInverse logarithm (antilog) in base 10, e, 2 or any base, with steps and scientific notation.Asymptote CalculatorFind vertical, horizontal and slant asymptotes and holes of a function, with graph and reasoning.Cramer's Rule CalculatorSolve 2x2 and 3x3 linear systems by Cramer's rule with every determinant shown step by step.Dot Plot MakerMake a dot plot or line plot from data or a frequency table; download PNG or SVG.Exponential Regression CalculatorFit y = a·bˣ or y = a·e^(kx) to data with r², predictions, residuals and a plot.Extended Euclidean Algorithm CalculatorFind gcd(a, b) and Bézout coefficients x, y with the full step-by-step division table.Factor Tree GeneratorDraw the prime factor tree of any number as a printable diagram, with exponent form and steps.Function Composition CalculatorFind f(g(x)), g(f(x)), f + g, f · g and f / g with values at a point and domains.X and Y Intercept CalculatorFind the x- and y-intercepts of lines, curves and functions with steps and a graph.Line Intersection CalculatorFind where two lines cross from equations, points or slopes, with parallel checks and a graph.Linear Programming SolverSolve max/min linear programs with the simplex method: tableau steps and a 2-variable graph.Nth Term CalculatorFind the nth term formula of a sequence: arithmetic, geometric, quadratic or cubic.Partial Fraction Decomposition CalculatorSplit a rational function into partial fractions with the setup, equations and solution.Perpendicular Line CalculatorEquation of the perpendicular and parallel line through a point, with distance and a graph.Polar Graphing CalculatorGraph polar equations r = f(θ): roses, cardioids, spirals, with a θ range slider and PNG export.Polynomial CalculatorAdd, subtract, multiply, divide and evaluate polynomials; see roots, degree and a graph.Polynomial Long Division CalculatorDivide polynomials with the full long division layout, quotient, remainder and steps.Scale Factor CalculatorScale factor between similar figures, plus scaled lengths, areas (k²) and volumes (k³).Set CalculatorUnion, intersection, difference and complement of up to 4 sets, with a Venn diagram and counts.Table of Values CalculatorMake an x/y table for any function with a start, end and step, then plot it or copy CSV.Algebra CalculatorSimplify, expand and factor algebraic expressions with exact answers and step-by-step working.Determinant CalculatorDeterminant of a 2×2 to 8×8 matrix with exact fractions and cofactor or row-reduction steps.Differential Equation SolverSolve first- and second-order ODEs step by step, with initial conditions, an RK4 check and a graph.Domain and Range CalculatorFind the domain and range of a function in interval notation, with steps and a graph.Eigenvalue and Eigenvector CalculatorEigenvalues (real or complex), eigenvectors and the characteristic polynomial of a square matrix.Equation SolverSolve any equation for x: exact roots, complex roots, numeric answers, steps and a graph.Inequality CalculatorSolve linear, quadratic, rational and absolute value inequalities with steps and a number line.Inverse Function CalculatorFind the inverse f⁻¹(x) of a function with steps, domain restrictions and a graph.
See all 74 Algebra & Calculus Calculators →