How this instrument works
aᵇ mod m answers a single question: divide a raised to the b power by m, and keep only what is left over. It is two ordinary operations chained together — exponentiation, then the division algorithm's remainder step — and neither one is exotic on its own. What makes the combination worth its own sheet is that the intermediate number, aᵇ, can be enormous even for small a and b: 3¹⁰ is already 59,049, and doubling the exponent again would produce a number thousands of digits long at the base sizes cryptography actually uses. The remainder, by contrast, always stays small — pinned between 0 and m − 1 no matter how large aᵇ itself grows.
Fix a base and a modulus and let the exponent climb, and the sequence a¹ mod m, a² mod m, a³ mod m and onward does something specific: it eventually repeats. Multiplication modulo a fixed m only ever produces one of finitely many remainders, so the sequence must revisit a value sooner or later, and once it does it cycles forever with the same period. When a and m share no common factor, Euler's theorem pins an upper bound on how long that cycle can run, tied to how many numbers below m are coprime to it; when they do share a factor, the sequence can still settle into a cycle, just not one that theorem covers as neatly.
This sheet does not require the modulus to be prime, unlike the related identity behind Fermat's little theorem, which fixes m to a prime and always lands on a remainder of 1. Here m can be any positive whole number, and the sheet reports whatever remainder the arithmetic actually produces rather than a value guaranteed in advance — the same general operation, called modular exponentiation, that RSA key generation and Diffie–Hellman key exchange perform continuously, though production software reaches the answer by repeated squaring rather than ever writing out the full power the way the formula above does.
- Enter the number being raised to a power into the Base, a field — any whole number from 1 up works.
- Enter the exponent into the Exponent, b field; 0 is allowed and yields 1 before the modulus is applied.
- Enter the modulus into the Modulus, m field — it must be a positive whole number greater than zero.
- Read aᵇ mod m for the remainder: the sheet computes the full power first, then reduces it by the modulus in one pass.
- Change any single field and aᵇ mod m updates at once, so you can watch how the remainder shifts as the exponent climbs.
Worked example — 3 to the 10th power, reduced mod 7
Set Base, a to 3, Exponent, b to 10, and Modulus, m to 7. The sheet raises 3 to the 10th power first: 3¹⁰ = 59,049. Dividing that figure by 7 gives 8,435 with a remainder, since 7 × 8,435 = 59,045 and 59,049 − 59,045 = 4 — so aᵇ mod m reads exactly 4.0, the figure this page is built to reproduce every time those three inputs repeat.
That same operation, raising a base to a large power and then taking a remainder, is the arithmetic core of RSA encryption, run there on numbers with hundreds of digits rather than five. Real systems never form the full power the way this formula does; they use a technique called modular exponentiation, or square-and-multiply, which reduces by the modulus after every squaring step instead of at the very end, keeping every intermediate number no larger than the modulus itself squared.
Questions
What does aᵇ mod m actually compute?
It raises the base a to the whole-number power b, then reports only the remainder left after dividing that result by the modulus m. For a = 3, b = 10, m = 7, the sheet forms 3¹⁰ = 59,049 first and then reduces it, landing on 4 — the same two-step definition behind every modular exponentiation, just carried out on numbers small enough to write out in full.
Does the modulus m have to be a prime number?
No — m can be any positive whole number here, prime or composite. That is what separates this general operation from Fermat's little theorem, a related identity on this site that fixes the modulus to a prime and always returns a remainder of 1; this sheet places no such restriction and simply reports whatever remainder aᵇ actually leaves behind.
Why don't real cryptographic systems compute aᵇ directly, the way this formula does?
Because aᵇ grows explosively — an RSA modulus and exponent each run to hundreds of digits, and writing out the full power before reducing it would take more memory than exists. Production software instead uses modular exponentiation, repeatedly squaring the base and reducing by m after every step, which keeps every intermediate number no larger than m squared and reaches the identical final remainder this sheet computes directly.
What happens when the exponent b is 0?
aᵇ mod m returns 1, for any base a and any modulus m greater than 1, since any nonzero number raised to the power 0 equals 1, and 1 divided by a modulus larger than 1 leaves a remainder of 1. Entering a = 2, b = 0, m = 5 into this sheet returns exactly that.
How is this different from ordinary floor division or a plain mod operation?
Floor division and plain remainder pages on this site take one division and stop there; this sheet chains an exponentiation in front of that same remainder step. aᵇ mod m is mathematically just aᵇ reduced by the mod operation — applied to a number that itself came from exponentiating, rather than to a number already sitting in hand.
Can the remainder aᵇ mod m ever equal or exceed the modulus m?
No — by definition the remainder always satisfies 0 ≤ result < m, regardless of how large aᵇ itself grows. A result of 6 is possible when m = 7; a result of 7 or higher never is, since that would mean the division was not carried far enough, and this sheet always reduces the full power into that range.