Vol. I a living index of named laws · est. mmxxvi no ads · no account
The Law Tomeindex of named laws

Fermat's Little Theorem

also known as — Fermat's theorem on primes, The a-to-the-p congruence
"For a prime p and any integer a, a raised to the p leaves the same remainder as a itself when divided by p."
In plain English

What does Fermat's Little Theorem mean?

Fermat's little theorem states that if p is a prime number, then for any integer a, the number a raised to the power p minus a is a multiple of p; in the language of modular arithmetic, a to the p is congruent to a modulo p. Equivalently, when a is not divisible by p, a raised to the power p minus one is congruent to one modulo p. Named to distinguish it from Fermat's far deeper last theorem, it is a cornerstone of elementary number theory and modular arithmetic, and it underlies both primality testing and the mathematics of public-key cryptography, most famously the RSA cryptosystem.

In symbols

What is the formula for Fermat's Little Theorem?

a^p \equiv a \pmod{p}
The defining formula as recorded on Wikidata. a^p \equiv a \pmod{p}
Run the numbers

Fermat's Little Theorem calculator

For a prime p, a^(p-1) leaves remainder 1. Sweep the base and watch the answer refuse to move: that invariance is the theorem. When it does not hold, p cannot be prime. Try p = 561, which passes and is composite anyway, and is why this test alone never proves primality.

a^(p-1) mod p = 1 when p is prime

a
Base, not divisible by p
p
The modulus being tested
a^(p-1) mod p —
p is actually prime —

Computed live from a^(p-1) mod p = 1 when p is prime — the law's own arithmetic, nothing fitted or predicted.

Reliability

Rated Empirical: grounded in studies or measurable evidence. The other 608.

Lineage
1640COINED
How it works

How does Fermat's Little Theorem work?

The theorem captures a hidden regularity in how powers behave modulo a prime. Because the non-zero residues modulo a prime form a group under multiplication, raising any of them to the power one less than the prime cycles back to one, which gives the congruence. Multiplying through by a extends it to cover the case where a is divisible by p, where both sides are zero. Euler generalised the result: for any modulus n and any a coprime to it, a raised to the power of Euler's totient of n is congruent to one, with Fermat's theorem the special case of a prime modulus, whose totient is one less than the prime.

Where you'll see it

What are examples of Fermat's Little Theorem?

The primality test If a to the power p minus one is not congruent to one modulo p for some a, then p is definitely composite, the basis of the Fermat primality test.
RSA cryptography The correctness of the RSA cryptosystem rests on Fermat's little theorem and its generalisation, Euler's theorem, which govern how encryption and decryption exponents undo each other.
Carmichael numbers Some composites, the Carmichael numbers, pass the Fermat test for every base coprime to them; the smallest is 561, so passing the test does not prove primality.
Types & variants

What are the types of Fermat's Little Theorem?

Euler's theorem§

The generalisation to any modulus, that a raised to Euler's totient of n is congruent to one when a and n are coprime, of which Fermat's little theorem is the prime-modulus case.

The Fermat primality test§

A fast probabilistic check for primality using the theorem's contrapositive, whose blind spots are the Fermat pseudoprimes and, worst of all, the Carmichael numbers.

Why it matters

Why does Fermat's Little Theorem matter?

Fermat's little theorem is a foundational result of number theory that turns the behaviour of powers modulo a prime into a simple, exploitable identity. It underpins the Fermat primality test and, through Euler's generalisation, the RSA cryptosystem that secures much of digital communication, so a seventeenth-century observation about remainders now protects online commerce. It is also a gateway to the group theory of modular arithmetic and to deeper results, and it stands as a classic example of how an elegant fact about primes can become a workhorse of modern technology.

Working with it

How do you apply Fermat's Little Theorem?

  • Reduce powers modulo a prime — use that a to the p is congruent to a, or a to the p minus one is congruent to one for a coprime to p, to simplify huge powers.
  • Test for compositeness — apply the contrapositive: if the congruence fails for some base, the modulus is certainly composite, a fast primality screen.
  • Generalise with Euler — when the modulus is not prime, reach for Euler's theorem with the totient function in place of one less than the prime.
Where it breaks down

What are the limits of Fermat's Little Theorem?

The converse of the theorem is false: passing the Fermat test does not prove a number prime, because the Carmichael numbers are composite yet satisfy the congruence for every base coprime to them, the smallest being 561. The theorem is a statement about primes, and its primality test is only a probabilistic screen, not a proof of primality, so cryptographic and computational uses pair it with stronger tests. Its power is real but bounded, giving a necessary condition for primality rather than a sufficient one.

What it doesn't say

What are common misconceptions about Fermat's Little Theorem?

Fermat's little theorem is not Fermat's last theorem; the little theorem is a modular-arithmetic identity, while the last theorem is the far deeper claim that no positive integers satisfy the equation for exponents above two. The converse of the little theorem does not hold, so a number passing the Fermat test can still be composite, as the Carmichael numbers show. And the coprime form requires a not to be divisible by the prime, the case handled separately by the more general a-to-the-p congruence.

Is it real?

Is Fermat's Little Theorem real?

Yes, as far as the evidence goes. Fermat's Little Theorem is rated Empirical here: it rests on studies or measurements rather than on a saying.

Rated from two sources. 609 of the 1,116 entries carry this rating. How the scale works.

Occasionally printedin printed books: one of 240 names in its band, of 903 measured
38 of 51entries in mathematics & proof carry the same rating

The best-known laws are the least likely to rest on measurement.

Origin

Where did Fermat's Little Theorem come from?

Stated by Pierre de Fermat in a 1640 letter to Frénicle de Bessy without proof, with the first published proof given by Leonhard Euler in 1736 and generalised by Euler's theorem.

How the name spread

When did people start saying “Fermat's Little Theorem”?

1800coined 16402019
How often “Fermat 's Little Theorem” appears in printed English, which takes hold around 1987 and peaks around 2008. The idea dates to 1640: the phrase took about 347 years to reach print in any quantity, which is the gap this chart measures. Source: Google Books Ngrams.
Known elsewhere as

What is Fermat's Little Theorem called in other languages?

  • Arabicمبرهنة فيرما الصغرى
  • Germankleiner fermatscher Satz
  • SpanishPequeño teorema de Fermat
  • Frenchpetit théorème de Fermat
  • ItalianPiccolo teorema di Fermat
  • Japaneseフェルマーの小定理
  • Portugueseteste de primalidade de Fermat
  • RussianМалая теорема Ферма
  • Chinese费马小定理

9 languages, as recorded on Wikidata. These are names the idea already goes by, not translations we made. The whole index by language.

Sources

Sources & further reading

  1. 1Fermat's little theorem, Wikipedia. — the congruence, the Fermat 1640 and Euler 1736 history, and the Carmichael-number caveat.secondary
  2. 2Fermat's Little Theorem, Wolfram MathWorld. — the statement, Euler's generalisation, and the smallest Carmichael number 561.secondary

Everything above traces to en.wikipedia.org and mathworld.wolfram.com: two secondary sources, accounts of the original rather than the original itself, which has not been located for this entry. Nothing is written from memory, and the method is written down. Spot an error or a better source? Suggest a fix.

What we checked

  • 1,116entries in the tomeListed one by one on the browse page.
  • 1,116of them citing a sourceOpen any entry: its sources sit at the foot of the page.
  • 2,489source references in allEach is named, and linked wherever the source is online.