On this page
You probably met Fermat's little theorem as a fact about primes: if p is prime, then a^(p−1) leaves remainder 1 when divided by p, for every a that p does not divide. Turn it around and you get a quick test: if 2^(n−1) does not leave remainder 1 on division by n, then n is certainly composite. The trouble is the other direction. Some composite numbers pass the check for every base coprime to them. They are called Carmichael numbers, and the first one is only 561.
What are Carmichael numbers?
Carmichael numbers are composite numbers k such that a^(k−1) ≡ 1 (mod k) for every a coprime to k, as defined in the OEIS entry A002997. Coprime means a and k share no prime factor. The smallest Carmichael numbers are 561, 1105, 1729, 2465, 2821, 6601 and 8911, from the same entry.
They are named after the American mathematician Robert Daniel Carmichael (1879 to 1967), who pointed out in 1910 that 561 = 3 × 11 × 17 divides a^561 − a for every integer a, as the introduction to Alford, Granville and Pomerance's 1994 paper recounts (Carmichael's own 1910 note is in the Bulletin of the American Mathematical Society). The OEIS entry adds that Václav Šimerka found the first seven 25 years before Carmichael.
How do you check 561 with Korselt's criterion?
There are 320 bases coprime to 561, too many to test by hand. In 1899 Korselt noted a shortcut, stated in the 1994 paper: n divides a^n − a for all integers a if and only if n is squarefree and p − 1 divides n − 1 for all primes p dividing n. Squarefree means no prime appears twice in the factorisation.
Here is the whole check for 561:
Factorise: 561 = 3 × 11 × 17. Three different primes, none repeated, so 561 is squarefree.
Write n − 1 = 560.
For p = 3, p − 1 = 2, and 560 ÷ 2 = 280. It divides.
For p = 11, p − 1 = 10, and 560 ÷ 10 = 56. It divides.
For p = 17, p − 1 = 16, and 560 ÷ 16 = 35. It divides.
Every check passes and 561 is composite, so 561 is a Carmichael number.
Why this works: if a is coprime to 561, Fermat's little theorem gives a^2 ≡ 1 (mod 3), a^10 ≡ 1 (mod 11) and a^16 ≡ 1 (mod 17). Raise them to the powers 280, 56 and 35, and a^560 ≡ 1 modulo 3, 11 and 17 separately. Because the three primes are different, a^560 ≡ 1 (mod 561). Our post on Lagrange's theorem and Fermat's little theorem shows where a^(p−1) ≡ 1 comes from.
Now try 1729 = 7 × 13 × 19: 1728 is divisible by 6, 12 and 18, so 1729 passes too.
A near miss shows what makes Carmichael numbers special: 91 = 7 × 13. Here 90 is divisible by 6 but not by 12, so 91 is not a Carmichael number. Yet 3^90 ≡ 1 (mod 91), because 3^6 ≡ 1 (mod 7) and 3^3 = 27 ≡ 1 (mod 13). So 91 fools base 3. It does not fool base 2: 2^6 ≡ −1 (mod 13), so 2^90 ≡ −1 (mod 13). A number like 91 is a pseudoprime to one base; a Carmichael number fools every coprime base at once.
Why is the Fermat test alone unsafe?
A Fermat test picks a base a and computes a^(n−1) mod n. A remainder other than 1 proves n composite; a remainder of 1 only says n is probably prime. For 561, every coprime base says probably prime, so by the OEIS definition only a base sharing a factor 3, 11 or 17 with 561 can catch it: 240 of the 560 bases from 1 to 560.
Such a base is really a factor of n in disguise. When a Carmichael number's prime factors are all large, almost every base is coprime to it and passes, so a test that trusts Fermat alone would declare the number prime.
This matters outside the classroom. Encryption schemes such as RSA need large primes, as our RSA worked example with tiny primes shows, so practical primality tests add checks beyond Fermat's condition.
How many Carmichael numbers are there?
They are rare at first. Richard Pinch's tables count 1 Carmichael number below 1,000, 7 below 10,000, 16 below 100,000 and 1,401,644 below 10^18.
Carmichael wrote that his list might be indefinitely extended, but for decades no one could prove it. In 1994 W. R. Alford, Andrew Granville and Carl Pomerance proved there are infinitely many Carmichael numbers, showing that the count up to x is greater than x^(2/7) for all large x (Annals of Mathematics, 1994).
That paper asked whether Carmichael numbers obey something like Bertrand's postulate for primes, which says there is always a prime between n and 2n. Daniel Larsen answered yes in a 2021 paper, proving that for every large enough x there are Carmichael numbers between x and 2x, and in fact in a much shorter interval.
Practise the check yourself
Run the Korselt checklist on these three numbers before reading the answers:
1105 = 5 × 13 × 17: 1104 is divisible by 4, 12 and 16, so it is a Carmichael number.
2465 = 5 × 17 × 29: 2464 is divisible by 4, 16 and 28, so it is one too.
105 = 3 × 5 × 7: 104 is divisible by 2 and 4 but not by 6, so it is not.
If modular powers or the order of an element still feel shaky, the Fermi Concept Library has a lesson for every concept in mathematics, each with its place in the map. For more practice, the Fermi Problem Library has worked problems with a step-by-step solver that explains the reasoning rather than printing an answer.
Next time a number passes a Fermat test, factorise it before you call it prime.



