Carmichael Number Calculator
Number
- Korselt's criterion settles the question: a composite n is a Carmichael number exactly when n is squarefree and p - 1 divides n - 1 for every prime factor p.
- Factoring 561 gives 3 x 11 x 17, so n has 3 distinct prime factors and is squarefree.
- Testing p - 1 against n - 1 = 560 for each prime factor: 2 divides 560; 10 divides 560; 16 divides 560.
- Every condition holds, so 561 is a Carmichael number - it passes the Fermat test for every coprime base.
This Carmichael number calculator checks whether a whole number is a Carmichael number and shows you the reasoning behind the answer. A Carmichael number is a composite n that passes the Fermat test a^(n - 1) congruent to 1 mod n for every base a coprime to n, which is why these numbers are sometimes mistaken for primes. The calculator applies Korselt's criterion: n is Carmichael exactly when n is squarefree and p - 1 divides n - 1 for every prime factor p of n. For example, 561 = 3 x 11 x 17 is the smallest Carmichael number because 2, 10 and 16 all divide 560, and 1105 = 5 x 13 x 17 is Carmichael because 4, 12 and 16 all divide 1104. A number such as 660 = 2^2 x 3 x 5 x 11 fails the test because it is not squarefree: the factor 2 appears squared.
Korselt's criterion is the accepted standard for this kind of calculation because it gives an exact, complete characterization of Carmichael numbers rather than a probabilistic hint. Instead of testing many bases and hoping for a pattern, the calculator factors n, checks that no prime repeats, and confirms that p - 1 divides n - 1 for each prime factor p. That method settles the question for any input. On this page you will find the formula written out, step-by-step workings for each check, worked examples such as 561, 1105 and 660, and the sources behind the method, so you can follow every result yourself.
Worked examples
561, the smallest Carmichael number
(561)
| Carmichael verdict | Yes |
| Prime factorization | 3 x 11 x 17 |
| Distinct prime factors | 3 |
| Squarefree | Yes |
1105, the second Carmichael number
(1105)
| Carmichael verdict | Yes |
| Prime factorization | 5 x 13 x 17 |
| Distinct prime factors | 3 |
| Squarefree | Yes |
660, which fails Korselt's test
(660)
| Carmichael verdict | No |
| Prime factorization | 2^2 x 3 x 5 x 11 |
| Distinct prime factors | 4 |
| Squarefree | No |
What is a Carmichael number?
A Carmichael number is a composite number that passes the Fermat primality test for every base that is coprime to it. The Fermat test checks whether a^(n - 1) is congruent to 1 mod n. For a prime n, this congruence holds for every base a that shares no factor with n. A Carmichael number is the rare composite that satisfies the same congruence for every such base, so the test keeps returning the answer a prime would give. That is why these numbers are often described as numbers that fool the Fermat test.
The classic example is 561 = 3 x 11 x 17, the smallest Carmichael number. For n = 561, the value n - 1 is 560, and 2, 10 and 16 all divide 560. Those are exactly the amounts by which the prime factors fall short: 3 - 1 = 2, 11 - 1 = 10, and 17 - 1 = 16. The next well-known case is 1105 = 5 x 13 x 17. Here n - 1 = 1104, and 4, 12 and 16 all divide 1104, matching 5 - 1, 13 - 1 and 17 - 1. In both cases the pattern behind the definition is visible in plain arithmetic.
That pattern is stated precisely by Korselt's criterion: n is a Carmichael number exactly when n is squarefree and p - 1 divides n - 1 for every prime factor p of n. Squarefree means no prime factor appears more than once. The criterion gives a quick way to check a candidate without testing base after base. A number that fails either condition is not Carmichael. For example, 660 = 2^2 x 3 x 5 x 11 is not Carmichael because it is not squarefree: the factor 2 appears squared.
Why does this matter for primality testing? A test that relied on the Fermat congruence alone could label a Carmichael number as prime, and no choice of coprime base would expose the error. A Carmichael number calculator makes these exceptions easy to spot, but the deeper lesson is about test design. Primality tests used in practice need extra checks, such as testing several bases and confirming the result another way, so that a composite passing one congruence is not automatically accepted as prime.
- Carmichael number: a composite n that passes the Fermat test a^(n - 1) congruent to 1 mod n for every base a coprime to n.
- Korselt's criterion: n is Carmichael exactly when n is squarefree and p - 1 divides n - 1 for every prime factor p of n.
- Smallest example: 561 = 3 x 11 x 17, where 2, 10 and 16 all divide 560.
- Another example: 1105 = 5 x 13 x 17, where 4, 12 and 16 all divide 1104.
- Not Carmichael: 660 = 2^2 x 3 x 5 x 11, because it is not squarefree.
Korselt's criterion, worked examples
Korselt's criterion turns the definition of a Carmichael number into a checklist you can run by hand. The criterion states that a composite n is Carmichael exactly when n is squarefree and p - 1 divides n - 1 for every prime factor p of n. A Carmichael number calculator applies this test factor by factor, and walking through 561, 1105 and 660 shows how each part of the criterion does its job.
Start with 561 = 3 x 11 x 17, the smallest Carmichael number. The factorization is squarefree, since no prime repeats. Now check divisibility against n - 1 = 560 for each prime factor: for p = 3, p - 1 = 2, and 2 divides 560; for p = 11, p - 1 = 10, and 10 divides 560; for p = 17, p - 1 = 16, and 16 divides 560. All three conditions hold, so 561 passes Korselt's criterion. That is why it passes the Fermat test a^(n - 1) congruent to 1 mod n for every base a coprime to n, even though it is composite.
Next take 1105 = 5 x 13 x 17. Again the factorization is squarefree. With n - 1 = 1104, the checks are: for p = 5, p - 1 = 4, and 4 divides 1104; for p = 13, p - 1 = 12, and 12 divides 1104; for p = 17, p - 1 = 16, and 16 divides 1104. Every prime factor clears its divisibility test, so 1105 is Carmichael as well.
Now consider 660 = 2^2 x 3 x 5 x 11. The factor 2 appears squared, so 660 is not squarefree. Korselt's criterion fails at that first requirement, and the divisibility conditions never need to be tested. This is why the order of the checks matters: squarefreeness is a gate, and a number that fails it cannot be Carmichael no matter what its other factors do.
The table below collects the three examples so you can compare them at a glance. Each row lists the factorization, whether the number is squarefree, the relevant divisors of n - 1, and the verdict.
- 561 = 3 x 11 x 17: squarefree, and 2, 10 and 16 all divide 560 — Carmichael.
- 1105 = 5 x 13 x 17: squarefree, and 4, 12 and 16 all divide 1104 — Carmichael.
- 660 = 2^2 x 3 x 5 x 11: not squarefree because the factor 2 appears squared — not Carmichael, and divisibility is never tested.
| n | Factorization | Squarefree? | p - 1 divides n - 1? | Verdict |
|---|---|---|---|---|
| 561 | 3 x 11 x 17 | Yes | 2, 10 and 16 all divide 560 | Carmichael |
| 1105 | 5 x 13 x 17 | Yes | 4, 12 and 16 all divide 1104 | Carmichael |
| 660 | 2^2 x 3 x 5 x 11 | No — factor 2 appears squared | Not tested | Not Carmichael |
Carmichael numbers vs Fermat pseudoprimes
A Carmichael number is a composite n that passes the Fermat test a^(n - 1) congruent to 1 mod n for every base a coprime to n. A Fermat pseudoprime is a weaker thing: it is a composite that passes the same test for one particular base a, or for a handful of bases, while failing it for others. A good Carmichael number calculator makes this distinction visible, because the two categories are often confused. Every Carmichael number is a Fermat pseudoprime to every coprime base, but most Fermat pseudoprimes are not Carmichael numbers.
The practical difference is what happens when you switch bases. If you test a base-a pseudoprime with base a, it slips through and looks prime. Test it with a different base coprime to n and it usually fails, revealing that it is composite. A Carmichael number does not fail on that second test. No coprime base exposes it, so a single-base Fermat test cannot tell you it is composite at all. That is why Carmichael numbers matter to anyone relying on the Fermat test as a quick primality check: they are the composites that the test cannot catch, no matter which coprime base you choose.
Korselt's criterion gives the exact structural test: n is Carmichael exactly when n is squarefree and p - 1 divides n - 1 for every prime factor p of n. Squarefree means no prime factor appears more than once. The smallest example is 561 = 3 x 11 x 17. It is squarefree, and 2, 10 and 16 all divide 560, which is n - 1. The next familiar case is 1105 = 5 x 13 x 17: it is squarefree, and 4, 12 and 16 all divide 1104. Both pass for every base coprime to them, which is exactly what separates them from an ordinary base-a pseudoprime.
The squarefree condition is not a technicality. Consider 660 = 2^2 x 3 x 5 x 11. It is not Carmichael because it is not squarefree: the factor 2 appears squared. A repeated prime factor breaks the Korselt condition, and with it the property of fooling every coprime base. A number can still be a pseudoprime to some base without being squarefree, but it cannot be a Carmichael number. Checking squarefreeness first is therefore the fastest way to rule a candidate out.
When you use a Carmichael number calculator, keep the two concepts separate in your mind. Base-a pseudoprimes are partial impostors: they fool some bases and are caught by others. Carmichael numbers are complete impostors for the Fermat test: they fool every base coprime to them. Korselt's criterion, with 561 and 1105 as clear examples and 660 as the squarefree counterexample, is the reliable way to tell which one you are looking at.
How many are there?
There are infinitely many Carmichael numbers, but they are spread so thinly across the integers that you can search for a long time before meeting one. The smallest is 561 = 3 x 11 x 17. It qualifies because 2, 10 and 16 all divide 560 — exactly the condition Korselt's criterion demands, since the prime factors are 3, 11 and 17 and their predecessors are 2, 10 and 16. The next familiar example is 1105 = 5 x 13 x 17, where 4, 12 and 16 all divide 1104. A Carmichael number calculator makes these checks mechanical: it factors the input, confirms the number is squarefree, and tests each p - 1 against n - 1.
Infinitude does not mean abundance. Carmichael numbers are rare relative to the composites around them, and the gaps between them grow as you move up the number line. That combination — infinitely many in principle, hard to stumble upon in practice — is why they matter. A number that passes a Fermat test looks prime to that test, so a program relying on Fermat alone can be fooled. A Carmichael number is precisely a composite n that passes the Fermat test a^(n - 1) congruent to 1 mod n for every base a coprime to n. It is not prime, yet no choice of coprime base exposes it.
The squarefree requirement is strict, and it is where many near-misses fail. Consider 660 = 2^2 x 3 x 5 x 11. It is not Carmichael because it is not squarefree — the factor 2 appears squared. No amount of checking divisibility by p - 1 rescues it; the criterion fails at the first condition. This is a useful sanity check when you use a Carmichael number calculator: if the factorization shows any repeated prime, the answer is immediately no.
Because Fermat tests cannot detect Carmichael numbers, modern primality testing relies on stronger methods such as Miller-Rabin. Miller-Rabin adds structure that a Carmichael number cannot satisfy for arbitrary bases, so it does not share the Fermat test's blind spot. In practice, a probabilistic Miller-Rabin test with several rounds is the standard way to decide whether a large number is prime, and deterministic variants cover bounded ranges. The role of the Carmichael number calculator is educational and diagnostic: it shows you exactly which composites slip past Fermat and why, using Korselt's criterion rather than trial division alone.
- 561 = 3 x 11 x 17 is the smallest Carmichael number: 2, 10 and 16 all divide 560.
- 1105 = 5 x 13 x 17 is Carmichael: 4, 12 and 16 all divide 1104.
- 660 = 2^2 x 3 x 5 x 11 is not Carmichael because it is not squarefree — the factor 2 appears squared.
FAQs
What is a Carmichael number?
A Carmichael number is a composite number n such that a^(n - 1) is congruent to 1 mod n for every base a coprime to n. In other words, it satisfies the Fermat test for all such bases, even though it is not prime. This property is what makes Carmichael numbers notable.
What is the smallest Carmichael number?
The smallest Carmichael number is 561. It factors as 3 x 11 x 17, and it passes Korselt's criterion. Because it is composite yet satisfies the Fermat test for every base coprime to it, 561 is the classic first example of a Carmichael number.
How does Korselt's criterion work?
Korselt's criterion gives a test for Carmichael numbers. Factor n. The number must be squarefree, meaning no prime factor is repeated. Also, for every prime factor p of n, p - 1 must divide n - 1. If both conditions hold, n is a Carmichael number.
Is 1105 a Carmichael number?
Yes. 1105 = 5 x 13 x 17, which is squarefree. Checking Korselt's criterion, 4, 12 and 16 all divide 1104. Since every prime factor minus one divides n - 1 and the number is squarefree, 1105 qualifies as a Carmichael number.
Why is 660 not a Carmichael number?
Because 660 = 2^2 x 3 x 5 x 11 is not squarefree. A Carmichael number cannot have a squared prime factor, so 660 fails Korselt's criterion right away. The repeated factor of 2 rules it out before any divisibility check is needed.
Are Carmichael numbers prime?
No. Carmichael numbers are composite numbers that behave like primes under the Fermat test, which is exactly what makes them interesting. They pass a test designed to detect primes, yet they factor into smaller numbers. This makes them useful for studying the limits of simple primality tests.