Power modulo calculator
Get the remainder of a huge power without ever computing the power: 2 to the 10th mod 1000 leaves 24, and 3 to the 5th mod 13 leaves 9. Exact whole numbers for homework, contest problems and cyclic counters. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Base
- 2
- Exponent
- 10
- Modulus
- 1,000
- Remainder
- 24
- Expression
- 2^10 mod 1000
Power modulo answers one everyday arithmetic question: what remainder is left when a base is raised to an exponent and then divided by a positive integer modulus? Students write that remainder as base to the exponent, mod m; contest judges, cyclic counters, hash toy examples, and modular-arithmetic homework all need the same unique value in the range zero through m minus one, without ever materializing the huge intermediate power. This power modulo calculator accepts three integers — base, exponent, and a positive integer modulus — evaluates the power with fast binary exponentiation while reducing after every multiply, and returns that remainder together with a short display expression.
What power modulo computes and why fast exponentiation matters
Given integers base, exponent, and modulus m, power modulo returns the unique remainder r in the range zero 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 the base by itself exponent times and only then divides, which grows enormous intermediate values and overflows ordinary floating-point or fixed-width integers long before a contest-sized exponent finishes.
Fast exponentiation instead scans the bits of the exponent from least significant to most, squares the running base after every bit, multiplies into the running remainder when the bit is set, and reduces modulo m after every multiply so intermediates stay smaller than m squared. When m equals one every integer is congruent to zero, so the remainder is always zero.
When the exponent is zero the remainder is one for any base as long as m is greater than one, matching the empty-product convention that any finite number to the power zero equals one. 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 a different search intent than remainder-of-a-power.
Where a power modulo calculator earns its keep
Classrooms and tutoring platforms use a dedicated power modulo tool so learners can check a to the b, reduced modulo m, without hand-multiplying huge intermediates 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-positive modulus as invalid instead of accepting a sentinel a buggy student script might also emit. Failed validation does not consume balance.
Keep requests inside the published magnitude limits, pin the remainder 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 compute modular inverses, does not solve discrete logarithms, and does not raise a real number without reducing modulo m; those are different search intents served by other catalog entries.
What you can do with it
Classroom and homework remainder checks
Let students submit base, exponent, and modulus and verify the unique remainder of a^b mod m without overflowing a handheld calculator or a spreadsheet cell.
Cyclic counters, hashes, and sharding scripts
Fold a large integer power into a fixed residue range for games, ranking systems, or toy hash steps without reimplementing square-and-multiply in every language.
FAQ
What does the power modulo calculator return?
It returns the unique remainder r in 0 … m−1 such that base^exponent ≡ r (mod m), plus an expression string and the identity formula remainder = base^exponent mod modulus.
What happens if the modulus is not a positive integer?
Zero, a negative modulus, and a non-integer modulus do not define the standard non-negative remainder used here and are not billed.
Why is a negative exponent rejected?
Negative exponents mean reciprocal powers and require modular inverses, which may not exist when base and modulus are not coprime. Those cases are out of scope.
How does fast exponentiation compute the remainder?
Binary square-and-multiply scans the bits of the exponent, squares the running base modulo m each step, and multiplies into the remainder when a bit is set, so work scales with the bit length of the exponent.
Can the base of a power modulo be negative?
Yes. A negative base is first brought into the range from zero to m minus one, so the remainder always comes out zero or positive. Only the exponent has to be zero or more, and the modulus a positive whole number.
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/power-modulo \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"base":2,"exponent":10,"modulus":1000}'const res = await fetch("https://api.kit.forhosting.com/math/power-modulo", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"base": 2,
"exponent": 10,
"modulus": 1000
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/math/power-modulo",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"base": 2,
"exponent": 10,
"modulus": 1000
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/math/power-modulo", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"base":2,"exponent":10,"modulus":1000}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"base":2,"exponent":10,"modulus":1000}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/math/power-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
{
"base": 2,
"exponent": 10,
"modulus": 1000
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "math.power_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_base | 1000000000000000 |
max_exponent | 1000000 |
max_modulus | 1000000000000000 |
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
If the modulus is not a positive integer the task fails with invalid_input instead of inventing a remainder.
What power modulo computes and why fast exponentiation matters
The modulus must be a positive integer; zero, a negative value, or a fraction does not define the standard non-negative remainder and the calculator returns invalid_input instead of inventing an answer.
Input contract, algorithm, response shape, and errors
The algorithm is binary square-and-multiply over exact integers: for each bit of the exponent the running base is squared modulo m and, when the bit is set, multiplied into the running remainder modulo m. On success the body echoes the cleaned base, exponent, and modulus, returns remainder as the non-negative residue of base^exponent mod m, includes an expression string such as two caret ten mod one thousand for display, and restates the identity formula remainder equals base to the exponent, mod modulus. Classic checks: base two, exponent ten, modulus one thousand yields remainder twenty-four; base three, exponent five, modulus thirteen yields remainder nine; base seven, exponent zero, modulus five yields remainder one. POST a JSON body with three required integers: base, the integer being raised; exponent, a non-negative integer power; and modulus, a positive integer m. Each field may arrive as a JSON number or as a decimal integer string; the aliases a for base, exp or e or power for exponent, and m or mod for modulus are accepted and resolved in that order. Missing fields, empty strings, fractions, and non-numeric values fail with invalid_input naming the field. Absolute value of the base may not exceed one quadrillion, the exponent may not exceed one million, and the modulus may not exceed one quadrillion; those limits keep every modular multiply inside a Worker isolate. A modulus that is not a positive integer — zero, a negative integer, or a non-integer — is invalid_input and is never billed. Pair the response with your own typesetting if you need a rendered superscript; this endpoint computes the remainder only and does not emit plots or step-by-step prose beyond the formula field.
Where a power modulo calculator earns its keep
Programming-contest coaches, hashing demos, cyclic game counters, and sharding helpers all raise an integer and fold it into a fixed residue range; calling a tiny parse API avoids reimplementing square-and-multiply in every language and avoids pulling a computer-algebra system for three integers.
Integration use cases
Contest oracles and LMS auto-grading
Mark power-modulo items with a deterministic remainder and reject a non-positive modulus as invalid_input instead of silently returning a hollow zero.
Technical questions
What does the power modulo calculator cost?
The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.