# invmod() Function & Examples

Use the invmod() arithmetic function in Calcul.io. Review its syntax, edit working examples, understand the result, and explore related math functions.

## invmod

#### invmod(a, b)

Try it yourself:

```calculio
invmod(8, 12)
invmod(7, 13)
invmod(15151, 15122)
```

[gcd](https://calcul.io/function/gcd/index.md)

[xgcd](https://calcul.io/function/xgcd/index.md)

---

## invmod(): modular multiplicative inverse

**invmod(a, m)** finds a number x such that `a × x ≡ 1 (mod m)`. For example, `invmod(3, 11)` is 4 because 3 × 4 leaves remainder 1 after division by 11.

## When an inverse exists

An inverse exists exactly when a and m are coprime: their greatest common divisor is 1. This condition is central to modular arithmetic and cryptographic algorithms.

## Related number tools

Check coprimality with [gcd()](https://calcul.io/function/gcd/index.md). Use [mod()](https://calcul.io/function/mod/index.md) to verify the remainder, [pow()](https://calcul.io/function/pow/index.md) for powers, and [isPrime()](https://calcul.io/function/isPrime/index.md) when considering prime moduli. [factorial()](https://calcul.io/function/factorial/index.md) is not a substitute for modular inversion.

## Input caution

Use integer arguments and a positive modulus greater than one. If gcd(a, m) is not 1, no multiplicative inverse exists.

[All functions](https://calcul.io/functions/index.md)
