In mathematics, a Fermat number, named after Pierre de Fermat (1601–1665), the first known to have studied them, is a positive integer of the form: Fn=22n+1, where n is a non-negative integer. The first few Fermat numbers are: 3, 5, 17, 257, 65537, 4294967297, 18446744073709551617, 340282366920938463463374607431768211457, ... (sequence A000215 in the OEIS). If 2k + 1 is prime and k > 0, then k itself must be a power of 2, so 2k + 1 is a Fermat number; such primes are called Fermat primes. As of 2026, the only known Fermat primes are F0 = 3, F1 = 5, F2 = 17, F3 = 257, and F4 = 65537 (sequence A019434 in the OEIS).
Basic properties The Fermat numbers satisfy the following recurrence relations:
Fn=(Fn−1−1)2+1 Fn=F0F1⋯Fn−1+2 for n ≥ 1,
Fn=Fn−1+22n−1F0F1⋯Fn−2 Fn=(Fn−1−2Fn−2+1)2+(2(Fn−2−2)(Fn−3−1))2+(2Fn−2−3)2 Fn=Fn−12−2(Fn−2−1)2 for n ≥ 2. Each of these relations can be proved by mathematical induction. From the second equation, we can deduce Goldbach's theorem (named after Christian Goldbach): no two Fermat numbers share a common integer factor greater than 1. To see this, suppose that 0 ≤ i < j and Fi and Fj have a common factor a > 1. Then a divides both
F0F1⋯Fj−1 and Fj; hence a divides their difference, 2. Since a > 1, this forces a = 2. This is a contradiction, because each Fermat number is clearly odd. As a corollary, we obtain another proof of the infinitude of the prime numbers: for each Fn, choose a prime factor pn; then the sequence {pn} is an infinite sequence of distinct primes.
Further properties No Fermat prime can be expressed as the difference of two pth powers, where p is an odd prime. With the exception of F0 and F1, the last decimal digit of a Fermat number is 7. The sum of the reciprocals of all the Fermat numbers (sequence A051158 in the OEIS) is irrational. (Solomon W. Golomb, 1963)
Primality Fermat numbers and Fermat primes were first studied by Pierre de Fermat, who conjectured that all Fermat numbers are prime. Indeed, the first five Fermat numbers F0, ..., F4 are easily shown to be prime. Fermat's conjecture was refuted by Leonhard Euler in 1732 when he showed, by dividing by 641 that
F5=225+1=232+1=4294967297=641×6700417 Euler proved that every factor of Fn must have the form k 2n+1 + 1 (later improved to k 2n+2 + 1 by Lucas) for n ≥ 2. That 641 is a factor of F5 can be deduced, in hindsight, as follows: From the equalities 641 = 27 × 5 + 1 and 641 = 24 + 54. It follows from the first equality that 27 × 5 ≡ −1 (mod 641) and therefore (raising to the fourth power) that 228 × 54 ≡ 1 (mod 641). On the other hand, the second equality implies that 54 ≡ −24 (mod 641). These congruences imply that 232 ≡ −1 (mod 641). Fermat was probably aware of the form of the factors later proved by Euler, so it seems curious that he failed to follow through on the straightforward calculation to find the factor. One common explanation is that Fermat made a computational mistake. There are no other known Fermat primes Fn with n > 4, but little is known about Fermat numbers for large n. In fact, each of the following is an open problem:
Is Fn composite for all n > 4? Are there infinitely many Fermat primes? (Eisenstein 1844) Are there infinitely many composite Fermat numbers? Does a Fermat number exist that is not square-free? As of December 2025, it is known that Fn is composite for 5 ≤ n ≤ 32, although of these, complete factorizations of Fn are known only for 0 ≤ n ≤ 11, and there are no known prime factors for n = 20 and n = 24. The largest Fermat number known to be composite is F18233954, and its prime factor 7 × 218233956 + 1 was discovered in October 2020.
Heuristic arguments Heuristics suggest that F4 is the last Fermat prime. The prime number theorem implies that a random integer in a suitable interval around N is prime with probability 1 / ln N. If one uses the heuristic that a Fermat number is prime with the same probability as a random integer of its size, and that F5, ..., F32 are composite, then the expected number of Fermat primes beyond F4 (or equivalently, beyond F32) should be
∑n≥331lnFn<1ln2∑n≥331log2(22n)=1ln22−32<3.36×10−10. One may interpret this number as an upper bound for the probability that a Fermat prime beyond F4 exists. This argument is not a rigorous proof. For one thing, it assumes that Fermat numbers behave "randomly", but the factors of Fermat numbers have special properties. Boklan and Conway published a more precise analysis suggesting that the probability that there is another Fermat prime is less than one in a billion. Anders Bjorn and Hans Riesel estimated the number of square factors of Fermat numbers from F5 onward as
∑n≥5∑k≥11k(k2n+1)ln(k2n)<π26ln2∑n≥51n2n≈0.02576; in other words, there are unlikely to be any non-squarefree Fermat numbers, and in general square factors of a2n+b2n are very rare for large n.
Equivalent conditions
Let Fn=22n+1 be the nth Fermat number. Pépin's test states that for n > 0,
Fn is prime if and only if 3(Fn−1)/2≡−1(modFn). The expression 3(Fn−1)/2 can be evaluated modulo Fn by repeated squaring. This makes the test a fast polynomial-time algorithm. But Fermat numbers grow so rapidly that only a handful of them can be tested in a reasonable amount of time and space. There are some tests for numbers of the form k 2m + 1, such as factors of Fermat numbers, for primality.
Proth's theorem (1878). Let N = k 2m + 1 with odd k < 2m. If there is an integer a such that a(N−1)/2≡−1(modN) then N is prime. Conversely, if the above congruence does not hold, and in addition (aN)=−1 (See Jacobi symbol) then N is composite. If N = Fn > 3, then the above Jacobi symbol is always equal to −1 for a = 3, and this special case of Proth's theorem is known as Pépin's test. Although Pépin's test and Proth's theorem have been implemented on computers to prove the compositeness of some Fermat numbers, neither test gives a specific nontrivial factor. In fact, no specific prime factors are known for n = 20 and 24.
… excerpt ends here. Continue reading the full article.
