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:
F
n
=
2
2
n
+
1
,
{\displaystyle F_{n}=2^{2^{n}}+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).
Contents
Basic properties
The Fermat numbers satisfy the following recurrence relations:
F
n
=
(
F
n
−
1
−
1
)
2
+
1
{\displaystyle F_{n}=(F_{n-1}-1)^{2}+1}
F
n
=
F
0
F
1
⋯
F
n
−
1
+
2
{\displaystyle F_{n}=F_{0}F_{1}\cdots F_{n-1}+2}
for n ≥ 1,
F
n
=
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
F
5
=
2
2
5
+
1
=
2
32
+
1
=
4294967297
=
641
×
6700417.
{\displaystyle F_{5}=2^{2^{5}}+1=2^{32}+1=4294967297=641\times 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.
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
≥
33
1
ln
F
n
<
1
ln
2
∑
n
≥
33
1
log
2
(
2
2
n
)
=
1
ln
Equivalent conditions
Let
F
n
=
2
2
n
+
1
{\displaystyle F_{n}=2^{2^{n}}+1}
be the nth Fermat number. Pépin's test states that for n > 0,
F
n
{\displaystyle F_{n}}
is prime if and only if
3
(
F
n
−
1
)
/
2
≡
−
1
(
mod
F
n
)
.
{\displaystyle 3^{(F_{n}-1)/2}\equiv -1{\pmod {F_{n}}}.}
Factorization
Because of Fermat numbers' size, it is difficult to factorize or even to check primality. Pépin's test gives a necessary and sufficient condition for primality of Fermat numbers, and can be implemented by modern computers. The elliptic curve method is a fast method for finding small prime divisors of numbers. Distributed computing project Fermatsearch has found some factors of Fermat numbers. Yves Gallot's proth.exe has been used to find factors of large Fermat numbers. Édouard Lucas, improving Euler's above-mentioned result, proved in 1878 that every factor of the Fermat number
F
n
{\displaystyle F_{n}}
, with n at least 2, is of the form
k
×
2
n
+
2
+
1
{\displaystyle k\times 2^{n+2}+1}
(see Proth number), where k is a positive integer. By itself, this makes it easy to prove the primality of the known Fermat primes.
Factorizations of the first 12 Fermat numbers are:
As of January 2025, only F0 to F11 have been completely factored. The distributed computing project Fermat Search is searching for new factors of Fermat numbers. The set of all Fermat factors is A050922 (or, sorted, A023394) in OEIS.
The following factors of Fermat numbers were known before 1950 (since then, digital computers have helped find more factors):
Pseudoprimes and Fermat numbers
Like composite numbers of the form 2p − 1, every composite Fermat number is a strong pseudoprime to base 2. This is because all strong pseudoprimes to base 2 are also Fermat pseudoprimes – i.e.,
2
F
n
−
1
≡
1
(
mod
F
n
)
{\displaystyle 2^{F_{n}-1}\equiv 1{\pmod {F_{n}}}}
for all Fermat numbers.
In 1904, Cipolla showed that the product of at least two distinct prime or composite Fermat numbers
F
a
F
b
…
F
s
,
{\displaystyle F_{a}F_{b}\dots F_{s},}
a
>
b
>
⋯
Other theorems about Fermat numbers
A Fermat number cannot be a perfect number or part of a pair of amicable numbers. (Luca 2000)
The series of reciprocals of all prime divisors of Fermat numbers is convergent. (Křížek, Luca & Somer 2002)
If nn + 1 is prime and
n
≥
2
{\displaystyle n\geq 2}
, there exists an integer m such that n = 22m. The equation
nn + 1 = F(2m+m)
holds in that case.
Let the largest prime factor of the Fermat number Fn be P(Fn). Then,
P
(
F
n
)
≥
2
n
+
2
(
4
n
+
9
)
+
Relationship to constructible polygons
Carl Friedrich Gauss developed the theory of Gaussian periods in his Disquisitiones Arithmeticae and formulated a sufficient condition for the constructibility of regular polygons. Gauss stated that this condition was also necessary, but never published a proof. Pierre Wantzel gave a full proof of necessity in 1837. The result is known as the Gauss–Wantzel theorem:
An n-sided regular polygon can be constructed with compass and straightedge if and only if n is the product of a power of 2 and distinct Fermat primes: in other words, if and only if n is of the form n = 2kp1p2...ps, where k, s are nonnegative integers and the pi are distinct Fermat primes.
A positive integer n is of the above form if and only if its totient φ(n) is a power of 2.
Applications of Fermat numbers
Pseudorandom number generation
Fermat primes are particularly useful in generating pseudo-random sequences of numbers in the range 1, ..., N, where N is a power of 2. The most common method used is to take any seed value between 1 and P − 1, where P is a Fermat prime. Now multiply this by a number A, which is greater than the square root of P and is a primitive root modulo P (i.e., it is not a quadratic residue). Then take the result modulo P. The result is the new value for the RNG.
V
j
+
1
=
(
A
×
V
j
)
mod
P
{\displaystyle V_{j+1}=(A\times V_{j}){\bmod {P}}}
(see linear congruential generator)
This is useful in computer science, since most data structures have members with 2X possible values. For example, a byte has 256 (28) possible values (0–255). Therefore, to fill a byte or bytes with random values, a random number generator that produces values 1–256 can be used, the byte taking the output value −1. Very large Fermat primes are of particular interest in data encryption for this reason. This method produces only pseudorandom values, as after P − 1 repetitions, the sequence repeats. A poorly chosen multiplier can result in the sequence repeating sooner than P − 1.
Generalized Fermat numbers
Numbers of the form
a
2
n
+
b
2
n
g
c
d
(
a
+
b
,
2
)
{\displaystyle {\frac {a^{2^{n}}+b^{2^{n}}}{gcd(a+b,2)}}}
with a, b any coprime integers, a > b > 0, are called generalized Fermat numbers. An odd prime p is a generalized Fermat number if and only if p is congruent to 1 (mod 4). (Here we consider only the case n > 0, so 3 =
2
2
0
+
1
{\displaystyle 2^{2^{0}}\!+1}
is not a counterexample.)
An example of a probable prime of this form is 200262144 + 119262144 (found by Kellen Shenton).
By analogy with the ordinary Fermat numbers, it is common to write generalized Fermat numbers of the form
Generalized Fermat primes of the form Fn(a)
Because of the ease of proving their primality, generalized Fermat primes have become in recent years a topic for research within the field of number theory. Many of the largest known primes today are generalized Fermat primes.
Generalized Fermat numbers can be prime only for even a, because if a is odd then every generalized Fermat number will be divisible by 2. The smallest prime number
F
n
(
a
)
{\displaystyle F_{n}(a)}
with
n
>
4
{\displaystyle n>4}
is
F
5
(
30
)
{\displaystyle F_{5}(30)}
, or 3032 + 1. Besides, we can define "half generalized Fermat numbers" for an odd base, a half generalized Fermat number to base a (for odd a) is
a
2
n
+
1
2
Generalized Fermat primes of the form Fn(a, b)
It is also possible to construct generalized Fermat primes of the form
a
2
n
+
b
2
n
{\displaystyle a^{2^{n}}+b^{2^{n}}}
. As in the case where b=1, numbers of this form will always be divisible by 2 if a+b is even, but it is still possible to define generalized half-Fermat primes of this type. For the smallest prime of the form
F
n
(
a
,
b
)
{\displaystyle F_{n}(a,b)}
(for odd
a
+
b
{\displaystyle a+b}
), see also (sequence A111635 in the OEIS).
Largest known generalized Fermat primes
The following is a list of the ten largest known generalized Fermat primes. The whole top-10 is discovered by participants in the PrimeGrid project.
On the Prime Pages one can find the current top 20 generalized Fermat primes and the current top 100 generalized Fermat primes.



