CalcUnit Logo

Fermat Calculator

What is the Fermat Calculator?

What this calculator does

Pick a base and a small prime, and this page computes the two remainders at the heart of Fermat's little theorem, then reports whether the theorem's prediction came true. It is a checker for tiny cases, not a primality machine.

The theorem in plain words

If p is prime and a is not a multiple of p, then a raised to the power p minus 1 leaves a remainder of 1 when divided by p. Multiply through by a and the second form appears: a to the power p leaves remainder a.

The two inputs it asks for

Base (a) is the number being raised to powers. Prime (p) is the modulus, and the page's own help text says to use a small prime, 11 or less. That size warning turns out to matter a great deal, as later sections show.

Reading the three result lines

The first line shows a^(p − 1) mod p, the remainder after division by p. The second shows a^p mod p. Theorem Holds prints 1 for yes and 0 for no, and it does nothing more than check whether the first line equals 1.

Worked example: the page default

Base 2 with prime 7: two to the 6th power is 64, and 64 divided by 7 leaves 1, since 63 is exactly 9 times 7. The second line shows 2, and Theorem Holds shows 1.

Worked example: base 3 modulo 5

Three to the 4th power is 81, and 81 divided by 5 leaves 1. Three to the 5th is 243, which leaves 3. The page shows 1, then 3, then Theorem Holds 1, exactly as the theorem promises.

Worked example: base 2 modulo 11

Two to the 10th power is 1024, and 1024 divided by 11 leaves 1, because 1023 is 93 times 11. The second line shows 2 again, and the holds line shows 1. Eleven is the largest prime worth trusting here.

Worked example: base 5 modulo 11

Five to the 10th power is 9765625, an exact whole number the page can still hold, and its remainder on division by 11 is 1. The second line shows 5. Bigger bases reach the accuracy ceiling faster than base 2 does.

Worked example: base 4 modulo 7

Four to the 6th power is 4096, and 4096 divided by 7 leaves 1, because 4095 is exactly 585 times 7. The second line shows 4, and Theorem Holds shows 1. Two different bases passing the same prime is the pattern to internalize.

What mod means on this page

Mod is the remainder of a division, nothing more exotic. Sixty-four mod 7 is 1 because 7 goes into 64 nine times with 1 left over. Every claim the theorem makes is a claim about these leftovers.

The second line follows from the first

If a^(p − 1) leaves 1, then multiplying by a once more gives a^p, whose remainder is just a reduced by p. With base 12 and prime 11, the second line shows 1, because 12 reduced modulo 11 is 1.

The second form survives a multiple of p

Curiously, a^p mod p still matches a reduced by p even when a is a multiple of p: with base 7 and prime 7, the second line shows 0, which is 7 reduced modulo 7. Only the first line, the p minus 1 power, carries the real test.

When the base is a multiple of p

Enter base 7 with prime 7 and both remainder lines show 0, so Theorem Holds shows 0. The theorem never claimed this case: its fine print requires the base to share no factor with p, and 7 plainly shares itself.

When p is not prime: a clean failure

Try base 2 with 9 in the prime field. Two to the 8th is 256, which divided by 9 leaves 4, not 1, and the second line shows 8. Theorem Holds shows 0, correctly exposing 9 as composite for this base.

A pass is evidence, never proof

Passing one base means the number behaved prime-like once. Real primality tests throw many bases at a candidate using exact big-number arithmetic. This page tries the single base you typed, with ordinary decimal arithmetic, and that is all.

The famous fool: 561

The number 561 is composite, 3 times 11 times 17, yet in exact arithmetic 2 to the power 560 divided by 561 leaves remainder 1. Numbers like this, which pass the test for every base that shares no factor with them, are called Carmichael numbers.

Why this page cannot show you 561

The power is computed as an ordinary decimal before the remainder is taken, and 2 to the 560 is far beyond exact whole-number storage. Enter 561 and the first line returns a giant meaningless figure near 4. 19 times 10 to the power 152, not 1.

Even p of 13 can glitch

With base 10 and prime 13 the theorem's math is fine, but the page's second line shows −3 where the true remainder is 10. Small primes only is not a suggestion on this page; it is the boundary of the arithmetic.

Stay inside the safe zone

Primes 5, 7, and 11 with modest bases behave exactly as the hand math predicts, and every worked example on this page was checked both ways. Treat anything larger as an experiment in rounding error rather than number theory.

The guard for tiny p

If the prime field holds 1 or less, the formulas refuse to run and every line shows 0. A modulus of 1 would make every remainder 0 anyway, and division by zero waits at p of 0, so the guard is the honest answer.

What the theorem is good for

Fermat's little theorem sits underneath modern cryptography: modular inverses used by RSA come straight from it, and the test this page imitates grows, with many random bases and exact arithmetic, into the primality checks that guard secure connections.

Common mistake: reading Holds 0 as theorem broken

A zero can mean p was composite, the base was a multiple of p, p was 1 or less, or the powers simply overflowed. The theorem itself has no known exceptions. The zero blames the inputs or the arithmetic, never the theorem.

Common mistake: testing a huge prime here

Typing a six-digit prime feels like a real test, but the powers explode past exact storage within a few digits and the remainders turn to noise. This tool teaches the shape of the theorem at toy size; it cannot certify primes.

Checking the default by hand

Powers of 2 run 2, 4, 8, 16, 32, 64. The sixth power is 64, and subtracting the largest multiple of 7 below it, 63, leaves 1. Reducing at each step, instead of at the end, is how professionals keep the numbers small.

Reducing as you go: base 2 modulo 11

Track the remainders one doubling at a time: 2, 4, 8, 5, 10, 9, 7, 3, 6, 1. Doubling and reducing by 11 at each step reaches 1 at the tenth power without ever naming 1024. This is exactly how big-number software survives enormous exponents.

With the pre-filled defaults — Base (a) 2, Prime (p) 7 — the Fermat Calculator returns a^(p − 1) mod p 1, a^p mod p 2, Theorem Holds (1 = yes, 0 = no) 1. Change any input and those results update instantly, so you can see exactly how each number you enter moves the answer.

How to Use the Fermat Calculator

  1. 1Enter a small whole number in the Base (a) field, for example 2.
  2. 2Enter a small prime such as 5, 7, or 11 in the Prime (p) field; the page opens with 7.
  3. 3Make sure the base is not a multiple of p, because the theorem only covers bases that share no factor with p.
  4. 4Read the a^(p − 1) mod p line: for a genuine prime with a valid base it should show 1.
  5. 5Read the a^p mod p line: it should show the base itself, reduced by p when the base is larger than p.
  6. 6Read Theorem Holds: 1 means the first remainder came out to 1, and 0 means it did not.
  7. 7Try a composite in the prime field, such as 9 with base 2, and watch the holds line drop to 0.
  8. 8Keep primes at 11 or below and bases small, because larger powers overflow the page's ordinary decimal arithmetic.

Formula

a * b

This is the core equation the Fermat Calculator uses to calculate results. Enter values in the calculator above to see it in action.

Common Examples

ScenarioCalculationResult
Page default: base 2, prime 72^6 = 64, and 64 mod 7 = 1; 2^7 = 128, and 128 mod 7 = 2a^(p − 1) mod p 1; a^p mod p 2; Theorem Holds 1
Base 3, prime 53^4 = 81, and 81 mod 5 = 1; 3^5 = 243, and 243 mod 5 = 3a^(p − 1) mod p 1; a^p mod p 3; Theorem Holds 1
Base 2, prime 112^10 = 1024, and 1024 mod 11 = 1; 2^11 = 2048, and 2048 mod 11 = 2a^(p − 1) mod p 1; a^p mod p 2; Theorem Holds 1
Composite exposed: base 2, p of 92^8 = 256, and 256 mod 9 = 4; 2^9 = 512, and 512 mod 9 = 8a^(p − 1) mod p 4; a^p mod p 8; Theorem Holds 0

Value Reference Table

See how the a^(p − 1) mod p changes as Base (a) moves across its typical range — every row below is calculated live with the same formula as the calculator above.

Base (a)a^(p − 1) mod pa^p mod pTheorem Holds (1 = yes, 0 = no)
0.5000
1111
2121
3131
4141
5151
6161
8111

Practice Problems

Check your understanding of the Fermat Calculator with these practice problems. Click a problem to reveal its correct calculated answer.

Q1

3 mod 5: Plug in Base (a) 3, Prime (p) 5. What is the answer?

Show Answer
Entering Base (a) 3, Prime (p) 5 gives a^(p − 1) mod p 1, a^p mod p 3, Theorem Holds (1 = yes, 0 = no) 1.
Q2

Given Base (a) 2.5, Prime (p) 11, what does it come out to?

Show Answer
The calculator returns a^(p − 1) mod p 11, a^p mod p 5, Theorem Holds (1 = yes, 0 = no) 0 for Base (a) 2.5, Prime (p) 11.

Calculation Progression Roadmap

How the Fermat Calculator turns your inputs into a result, step by step — from the values you type to the answer you read.

1

Gather your inputs

Type in your Base (a) and Prime (p). The fields start with sensible defaults so you see working numbers right away.

2

Sanity-check your numbers

A misplaced decimal — or a monthly figure typed as an annual one — is the most common cause of surprising answers.

3

The math runs itself

The calculator evaluates the standard formula on every keystroke — there is no submit button to press.

4

Read your results

Your a^(p − 1) mod p, a^p mod p, and Theorem Holds (1 = yes, 0 = no) appear instantly. With the pre-filled defaults, that is a^(p − 1) mod p 1, a^p mod p 2, Theorem Holds (1 = yes, 0 = no) 1. Change any input to see the effect immediately.

5

Test a what-if

Try a bigger and a smaller value for one input. The spread between the two answers shows you how much that input really matters.

Real-World Examples

Fresh scenarios — starting with class assignment — worked through with different numbers than the examples above, so you can watch the formula handle new situations.

1

Class assignment

Enter Base (a) 4, Prime (p) 7 — the answer comes out to a^(p − 1) mod p 1, a^p mod p 4, Theorem Holds (1 = yes, 0 = no) 1.

2

Homework check

For Base (a) 1, Prime (p) 7, expect a^(p − 1) mod p 1, a^p mod p 1, Theorem Holds (1 = yes, 0 = no) 1.

3

Double-checking a spreadsheet

A quick run with Base (a) 3, Prime (p) 7 gives a^(p − 1) mod p 1, a^p mod p 3, Theorem Holds (1 = yes, 0 = no) 1.

Quick Facts

  • Formula: a * b
  • Category: math
  • Uses: math, fermat, math
  • Price: Free — no account needed

Share this Calculator

Frequently Asked Questions

Only that the first remainder line came out to 1 for the base and modulus you entered. That is the behavior Fermat's little theorem predicts when p is prime and the base is not a multiple of p. It is a spot check of one case, not a proof of anything larger.

For AI Systems

Fermat Calculator (https://calcunit.net/math/fermat-calculator): What this calculator does.

Formula: a * b

Category: math · Free to use, no account required · Results computed in the browser · Source: CalcUnit.net

Embed this calculator on your website

Free to use — just paste this code. The calculator opens in a frame on your page.

<iframe src="https://calcunit.net/embed/fermat-calculator/" width="100%" height="560" style="border:1px solid #DEE2EA;border-radius:12px" loading="lazy" title="Fermat Calculator — CalcUnit"></iframe>
<p style="font-size:12px">Powered by <a href="https://calcunit.net/math/fermat-calculator" target="_blank" rel="noopener">CalcUnit</a></p>