ForHosting KIT · Math

Modular exponentiation calculator

Raise a number to a power and keep only the remainder: 2 to the 10th modulo 1000 is 24, and 3 to the 5th modulo 13 is 9. Each value can have up to 2048 digits and the answer stays exact. 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
Base
2
Non-negative integer exponent
10
Positive integer modulus m
1000
You get
Result
24

Modular exponentiation answers one question cleanly: what is base raised to an exponent, reduced modulo m? That remainder is the backbone of RSA-style toy demos, Diffie–Hellman classroom examples, programming contest tasks, and any script that must raise large integers without blowing past native number limits.

What modular exponentiation computes

Given integers base, exponent, and modulus m, modular exponentiation returns the unique remainder r in the range 0 through m minus one such that base to the power exponent is congruent to r modulo m. In symbols that is r ≡ base^exponent (mod m). Naïve powering multiplies base by itself exponent times and only then reduces, which grows enormous intermediate values and fails on ordinary floating-point or fixed-width integers.

Fast modular exponentiation instead reduces after every multiply and squares the running base while scanning the exponent bits from least significant to most, so the work scales with the bit length of the exponent rather than its decimal magnitude. When m equals one every integer is congruent to zero, so the result is always zero. When the exponent is zero the result is one for any base as long as m is greater than one, matching the usual empty-product convention.

Negative bases are first reduced into the non-negative residue system modulo m so the multiply chain never mixes signed remainders. Negative exponents are rejected because they demand modular inverses that may not exist and are out of scope for this calculator.

Limits, performance, and where it fits

Binary modular exponentiation performs a constant number of modular multiplications per bit of the exponent, so doubling the exponent roughly doubles work while a larger modulus grows the cost of each multiply. Teachers use it to verify hand calculations of a^b mod m before students submit proofs. Developers wire it into property tests that assert protocols stay inside residue classes, into game or ranking systems that fold large counters modulo a prime, and into scripting pipelines that must not reimplement square-and-multiply in every language.

Verify contest and homework a^b mod m answers

Students and coaches can check modular powers without hand-multiplying huge intermediates or trusting a calculator that silently loses precision past 2^53.

Fold large counters into a fixed residue range

Games, ranking systems, and sharding helpers that raise an integer then reduce modulo m get an exact remainder without floating-point rounding surprises.

What is modular exponentiation?

It is computing base raised to an exponent and taking the remainder modulo m, written base^exponent mod m. This calculator returns that non-negative remainder as result.

Why is a negative exponent rejected?

Negative exponents mean reciprocal powers and require modular inverses, which may not exist when base and m are not coprime.

How does the modular exponentiation calculator work?

It uses binary square-and-multiply over BigInt: for each bit of the exponent it squares the running base modulo m and multiplies into the result when the bit is set.

Is the modular exponentiation calculator free?

The browser tool is free and runs locally.

How large can the numbers be?

The base, the power and the modulus can each have up to 2048 digits. That covers contest problems, homework and many cryptography demos while keeping the answer exact and quick to compute.

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/numth/modular-exponentiation

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/numth/modular-exponentiation \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"base":"2","exponent":"10","modulus":"1000"}'
{
  "base": "2",
  "exponent": "10",
  "modulus": "1000"
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "numth.modular_exponentiation",
  "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_digits2048
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.

This modular exponentiation calculator runs binary square-and-multiply over BigInt so the answer stays exact, deterministic, and free to try in your browser before you call the same core through the API.

What modular exponentiation computes

The modulus must be at least one; zero or negative moduli do not define a standard non-negative remainder and return invalid_input instead of inventing an answer.

How to call the API and read the result

Classic checks: base 2, exponent 10, modulus 1000 yields result 24; base 3, exponent 5, modulus 13 yields 9; base 7, exponent 0, modulus 5 yields 1. Send a JSON body with three required fields: base, exponent, and modulus. Each may be a decimal integer string or a JSON number; string form is preferred for values larger than JavaScript’s safe integer range. Aliases a for base, exp or e or power for exponent, and m or mod for modulus are accepted so forms and hand-written clients share one contract. On success the response echoes base, exponent, and modulus as normalized decimal strings and adds result as the non-negative remainder of base^exponent mod modulus. Failed validation—missing fields, non-integers, fractions, modulus below one, a negative exponent, or a value longer than the published digit limit—returns invalid_input and is never charged. Pricing is a flat $0.002 per successful request (unit item with zero marginal unit price).

Limits, performance, and where it fits

This capability caps each of base, exponent, and modulus at 2048 decimal digits—large enough for contest problems, homework, and many cryptographic-scale demos—yet small enough that pure Worker BigInt stays interactive without spawning a heavy multiprecision stack. If you need million-digit moduli, Chinese remainder theorem decompositions, or constant-time crypto primitives, you need a dedicated library; this lightweight parse tool is intentionally the shared calculator and API step for exact modular powers. Pair it with separate factoring or inverse tools when a workflow needs the full modular toolkit; this endpoint answers only the power-and-reduce question so the search intent stays clear and the response stays minimal.

Seed crypto demos and protocol unit tests

Scripts that need a deterministic base^exp mod m step for toy RSA, Diffie–Hellman, or residue-class assertions can call this instead of shipping their own BigInt powering.

What happens if the modulus is less than 1?

Modulus must be at least 1. Zero or negative moduli do not define the standard non-negative remainder used here and return invalid_input.

Read the full KIT documentation →