Mathematics · Algebra

Modular Exponentiation Calculator

Calculate base^exponent modulo m without constructing the full power.

Runs locally
Your numbers

Inputs and results stay in this browser. Change one value at a time to explore the relationship.

Your inputCalculatedPassed forward in chains
Modular result3
Squaring rounds4

Calculation steps

  1. Write exponent 13 in binary and square modulo 7.
  2. 3^13 mod 7=3.

Understand Modular exponentiation

One idea, three depths

Choose how deeply to explain Modular exponentiation

Modular exponentiation: Calculate base^exponent modulo m without constructing the full power.

Age 5Explain it to a 5-year-oldStart with a picture

Imagine using Modular exponentiation to answer this question: calculate base^exponent modulo m without constructing the full power? Enter Base, Exponent, Modulus m; the calculator shows Modular result. For example: 3¹³ mod 7=3. The answer tells you Modular result.

Age 15Explain it to a 15-year-oldConnect it to the formula

Binary exponentiation repeatedly squares and reduces, keeping intermediate values small. The rule is Repeated squaring modulo m. Its input values are Base, Exponent, Modulus m, and the main result is Modular result. For example: 3¹³ mod 7=3.

CollegeExplain it at college levelState the model precisely

This calculator evaluates the stated modular exponentiation relation over the valid integer domain stated below. The implemented relation is Repeated squaring modulo m, evaluated from Base, Exponent, Modulus m to produce Modular result. Binary exponentiation repeatedly squares and reduces, keeping intermediate values small. The exponent must be a non-negative whole number and modulus positive.

Inputs and valid domain

  • Base must be an integer.
  • Exponent must be an integer, at least 0, at most 1000000000.
  • Modulus m must be an integer, at least 1.

Important boundary: The exponent must be a non-negative whole number and modulus positive.

The formula

Repeated squaring modulo m

How the calculator works through it

It substitutes Base, Exponent, Modulus m into the formula and exposes every numerical step above. The main output is Modular result, accompanied by Squaring rounds.

Read the result correctly

The Modular result is the direct answer to “calculate base^exponent modulo m without constructing the full power.” Read it with the units shown beside the inputs; a sign, angle, percentage or rate changes what the number means.

A worked check

3¹³ mod 7=3.

Where this model stops being reliable

The exponent must be a non-negative whole number and modulus positive.

Learn it by changing one value

Begin with the worked example, then change one value while keeping the others fixed. Compare the new result and calculation steps to identify which part of the formula changed.

Dictionary terms behind this calculator

Before studying the codeWhat you should know firstUse the calculator immediately, or check the foundations before reading the implementation.

These foundations help you understand why Modular exponentiation works. They never block the calculator, and “optional” means useful context rather than a hidden requirement.

Hard requirements

  • Reading formulas and substituting values

    Modular exponentiation uses Repeated squaring modulo m. You need to recognise what each side represents before substituting the stated inputs or rearranging the relationship.

    Review this foundation about 4 min

Strong support

Optional enrichment

  • Powers and exponents

    Powers are not required for every Modular exponentiation calculation, but they make related algebraic forms and code easier to read.

    Review this foundation about 4 min
Learn the missing foundationsI already know these — show the code

Mathematics → algorithm → program

Implement this calculation in code

These are direct reference implementations of the calculator's principal relationship and first output. They run locally and include a small known-answer check where the language supports it.

Algorithm

  1. Normalize the base modulo m.
  2. Scan the exponent's binary bits.
  3. Multiply on set bits and square the base after every bit, reducing modulo m.
Python
            def modular_power(base: int, exponent: int, modulus: int) -> int:
    base, out = base % modulus, 1 % modulus
    while exponent:
        if exponent & 1: out = out * base % modulus
        base = base * base % modulus
        exponent >>= 1
    return out
assert modular_power(3, 13, 7) == 3
          
Current calculator valuesUpdates when you change an input above.
              
            
C
            #include <assert.h>
#include <stdint.h>
uint64_t modular_power(uint64_t a,uint64_t e,uint64_t m){uint64_t out=1%m;a%=m;while(e){if(e&1)out=out*a%m;a=a*a%m;e>>=1;}return out;}
int main(void){assert(modular_power(3,13,7)==3);}
          
Current calculator valuesUpdates when you change an input above.
              
            
C++
            #include <cassert>
#include <cstdint>
std::uint64_t modular_power(std::uint64_t a,std::uint64_t e,std::uint64_t m){std::uint64_t out=1%m;a%=m;while(e){if(e&1)out=out*a%m;a=a*a%m;e>>=1;}return out;}
int main(){assert(modular_power(3,13,7)==3);}
          
Current calculator valuesUpdates when you change an input above.
              
            
Linux x86-64 assembly

x86-64 NASM · System V ABI · Linux · integer arguments in rdi, rsi and rdx

            ; uint64_t modular_power(uint64_t base, uint64_t exponent, uint64_t modulus)
global modular_power
section .text
modular_power:
    mov r8, rdx
    mov rax, rdi
    xor edx, edx
    div r8
    mov rdi, rdx
    mov eax, 1
    xor edx, edx
    div r8
    mov r9, rdx
.loop:
    test rsi, rsi
    jz .done
    test sil, 1
    jz .square
    mov rax, r9
    mul rdi
    div r8
    mov r9, rdx
.square:
    mov rax, rdi
    mul rdi
    div r8
    mov rdi, rdx
    shr rsi, 1
    jmp .loop
.done:
    mov rax, r9
    ret
          
Current calculator valuesUpdates when you change an input above.
              
            
MATLAB
            function result = modular_power(a, n, b)
    modulus = abs(round(b)); exponent = round(n);
    result = 1; base = mod(round(a), modulus);
    while exponent > 0
        if mod(exponent, 2) == 1, result = mod(result * base, modulus); end
        base = mod(base * base, modulus); exponent = floor(exponent / 2);
    end
end
          
Current calculator valuesUpdates when you change an input above.
              
            
Wolfram Language
            ClearAll[mwCalculate];
mwCalculate[a_Integer, n_Integer?NonNegative, b_Integer] /; b != 0 := PowerMod[a, n, Abs[b]];
          
Current calculator valuesUpdates when you change an input above.
              
            

Continue in mathematical software

The downloaded file includes your current inputs and first calculated result. It is created locally.

Floating-point answers can differ slightly by language, compiler and processor. Compare within a suitable tolerance rather than assuming every decimal representation will be identical.

Supporting sourcesAcademic referencesPrimary standards, textbooks and complete citations

Standards, reading and academic references

Use the calculator as the worked interaction, then consult the primary standards and academic textbooks listed below. MW SysArc links to the original sources; the explanation on this page is original and does not reproduce them.

Algebra and Trigonometry 2e

Read the related free OpenStax mathematics chapters
Cite this book
APA 7
Abramson, J. (2021). Algebra and trigonometry 2e. OpenStax. https://openstax.org/books/algebra-and-trigonometry-2e/pages/1-introduction-to-prerequisites
MLA 9
Abramson, Jay. Algebra and Trigonometry 2e. OpenStax, 2021, https://openstax.org/books/algebra-and-trigonometry-2e/pages/1-introduction-to-prerequisites.
Chicago author-date
Abramson, Jay. 2021. Algebra and Trigonometry 2e. Houston, TX: OpenStax. https://openstax.org/books/algebra-and-trigonometry-2e/pages/1-introduction-to-prerequisites.

OpenStax entries are free to read online. Follow the licence shown on each linked source before redistributing or adapting its content.

Reuse the page responsiblyCite this pageAPA, MLA, Chicago, Harvard, BibTeX and RIS

These formats cite this calculator page itself. They are separate from the academic references above, which support the mathematical method and terminology.

APA 7

MW SysArc. (2026, July 21). Modular Exponentiation Calculator. MW SysArc Tools. https://math.mwsysarc.com/algebra/modular-exponentiation

MLA 9

MW SysArc. “Modular Exponentiation Calculator.” MW SysArc Tools, 21 July 2026, https://math.mwsysarc.com/algebra/modular-exponentiation. Accessed 31 Aug. 2026.

Chicago 17

MW SysArc. “Modular Exponentiation Calculator.” MW SysArc Tools. Published July 21, 2026. Accessed August 31, 2026. https://math.mwsysarc.com/algebra/modular-exponentiation.

Harvard

MW SysArc (2026) ‘Modular Exponentiation Calculator’, MW SysArc Tools. Published 21 July 2026. Available at: https://math.mwsysarc.com/algebra/modular-exponentiation (Accessed: 31 August 2026).

BibTeX and RIS records

BibTeX

@misc{mwsysarc_modular_exponentiation_2026,
  author = {{MW SysArc}},
  title = {Modular Exponentiation Calculator},
  howpublished = {MW SysArc Tools},
  year = {2026},
  url = {https://math.mwsysarc.com/algebra/modular-exponentiation},
  note = {Published July 21, 2026; accessed August 31, 2026}
}

RIS

TY  - ELEC
AU  - MW SysArc
TI  - Modular Exponentiation Calculator
T2  - MW SysArc Tools
PY  - 2026
DA  - 2026-07-21
Y2  - 2026-08-31
UR  - https://math.mwsysarc.com/algebra/modular-exponentiation
N1  - Published July 21, 2026
ER  -

Clear answers

Frequently asked questions

What does the Modular exponentiation do?

Calculate base^exponent modulo m without constructing the full power.

How does the Modular exponentiation work?

The calculator applies Repeated squaring modulo m. Binary exponentiation repeatedly squares and reduces, keeping intermediate values small.

What can I learn from the Modular exponentiation?

It connects the mathematical rule to your chosen numbers and shows each calculation step. Change one input at a time to see how the result responds.

Does MW SysArc receive or store what I enter?

No. The calculation runs locally in your browser. MW SysArc does not receive or store your calculation inputs.

How should I use the result?

Use the steps to understand the method, then verify important school or professional work using the notation and rounding rules required in your setting.

Last reviewed . Calculations tested .

MW SysArc Certified