Fermat's last theorem is a theorem first proposed by Fermat in the form of a note scribbled in the margin of his copy of the ancient Greek text Arithmetica by Diophantus. The scribbled note was discovered posthumously, and the original is now lost. However, a copy was preserved in a book published by Fermat's son. In the note, Fermat claimed to have discovered a proof that the Diophantine equation has no integer solutions for and .
The full text of Fermat's statement, written in Latin, reads "Cubum autem in duos cubos, aut quadratoquadratum in duos quadratoquadratos, et generaliter nullam in infinitum ultra quadratum potestatem in duos eiusdem nominis fas est dividere cuius rei demonstrationem mirabilem sane detexi. Hanc marginis exiguitas non caperet" (Nagell 1951, p. 252). In translation, "It is impossible for a cube to be the sum of two cubes, a fourth power to be the sum of two fourth powers, or in general for any number that is a power greater than the second to be the sum of two like powers. I have discovered a truly marvelous demonstration of this proposition that this margin is too narrow to contain."
As a result of Fermat's marginal note, the proposition that the Diophantine equation
(1)

where , , , and are integers, has no nonzero solutions for has come to be known as Fermat's Last Theorem. It was called a "theorem" on the strength of Fermat's statement, despite the fact that no other mathematician was able to prove it for hundreds of years.
Note that the restriction is obviously necessary since there are a number of elementary formulas for generating an infinite number of Pythagorean triples satisfying the equation for ,
(2)

A first attempt to solve the equation can be made by attempting to factor the equation, giving
(3)

Since the product is an exact power,
(4)

Solving for and gives
(5)

which give
(6)

However, since solutions to these equations in rational numbers are no easier to find than solutions to the original equation, this approach unfortunately does not provide any additional insight.
If an odd prime divides , then the reduction
(7)

can be made, so redefining the arguments gives
(8)

If no odd prime divides , then is a power of 2, so and, in this case, equations (7) and (8) work with 4 in place of . Since the case was proved by Fermat to have no solutions, it is sufficient to prove Fermat's last theorem by considering odd prime powers only.
Similarly, is sufficient to prove Fermat's last theorem by considering only relatively prime , , and , since each term in equation (1) can then be divided by , where is the greatest common divisor.
The socalled "first case" of the theorem is for exponents which are relatively prime to , , and () and was considered by Wieferich. Sophie Germain proved the first case of Fermat's Last Theorem for any odd prime when is also a prime. Legendre subsequently proved that if is a prime such that , , , , or is also a prime, then the first case of Fermat's Last Theorem holds for . This established Fermat's Last Theorem for . In 1849, Kummer proved it for all regular primes and composite numbers of which they are factors (Vandiver 1929, Ball and Coxeter 1987).
The "second case" of Fermat's last theorem is " divides exactly one of , , . Note that is ruled out by , , being relatively prime, and that if divides two of , , , then it also divides the third, by equation (8).
Kummer's attack led to the theory of ideals, and Vandiver developed Vandiver's criteria for deciding if a given irregular prime satisfies the theorem. In 1852, Genocchi proved that the first case is true for if is not an irregular pair. In 1858, Kummer showed that the first case is true if either or is an irregular pair, which was subsequently extended to include and by Mirimanoff (1909). Vandiver (1920ab) pointed out gaps and errors in Kummer's memoir which, in his view, invalidate Kummer's proof of Fermat's Last Theorem for the irregular primes 37, 59, and 67, although he claims Mirimanoff's proof of FLT for exponent 37 is still valid.
Wieferich (1909) proved that if the equation is solved in integers relatively prime to an odd prime , then
(9)

(Ball and Coxeter 1987). Such numbers are called Wieferich primes. Mirimanoff (1909) subsequently showed that
(10)

must also hold for solutions relatively prime to an odd prime , which excludes the first two Wieferich primes 1093 and 3511. In 1914, Vandiver showed
(11)

and Frobenius extended this to
(12)

It has also been shown that if were a prime of the form , then
(13)

which raised the smallest possible in the "first case" to by 1941 (Rosser 1941). Granville and Monagan (1988) showed if there exists a prime satisfying Fermat's Last Theorem, then
(14)

for , 7, 11, ..., 71. This establishes that the first case is true for all prime exponents up to (Vardi 1991).
The "second case" of Fermat's Last Theorem (for ) proved harder than the first case.
Euler proved the general case of the theorem for , Fermat , Dirichlet and Lagrange . In 1832, Dirichlet established the case . The case was proved by Lamé (1839; Wells 1986, p. 70), using the identity
(15)

Although some errors were present in this proof, these were subsequently fixed by Lebesgue in 1840. Much additional progress was made over the next 150 years, but no completely general result had been obtained. Buoyed by false confidence after his proof that pi is transcendental, the mathematician Lindemann proceeded to publish several proofs of Fermat's Last Theorem, all of them invalid (Bell 1937, pp. 464465). A prize of German marks, known as the Wolfskehl Prize, was also offered for the first valid proof (Ball and Coxeter 1987, p. 72; Barner 1997; Hoffman 1998, pp. 193194 and 199).
A recent false alarm for a general proof was raised by Y. Miyaoka (Cipra 1988) whose proof, however, turned out to be flawed. Other attempted proofs among both professional and amateur mathematicians are discussed by vos Savant (1993), although vos Savant erroneously claims that work on the problem by Wiles (discussed below) is invalid. By the time 1993 rolled around, the general case of Fermat's Last Theorem had been shown to be true for all exponents up to (Cipra 1993). However, given that a proof of Fermat's Last Theorem requires truth for all exponents, proof for any finite number of exponents does not constitute any significant progress towards a proof of the general theorem (although the fact that no counterexamples were found for this many cases is highly suggestive).
In 1993, a bombshell was dropped. In that year, the general theorem was partially proven by Andrew Wiles (Cipra 1993, Stewart 1993) by proving the semistable case of the TaniyamaShimura conjecture. Unfortunately, several holes were discovered in the proof shortly thereafter when Wiles' approach via the TaniyamaShimura conjecture became hung up on properties of the Selmer group using a tool called an Euler system. However, the difficulty was circumvented by Wiles and R. Taylor in late 1994 (Cipra 1994, 1995) and published in Taylor and Wiles (1995) and Wiles (1995). Wiles' proof succeeds by (1) replacing elliptic curves with Galois representations, (2) reducing the problem to a class number formula, (3) proving that formula, and (4) tying up loose ends that arise because the formalisms fail in the simplest degenerate cases (Cipra 1995).
The proof of Fermat's Last Theorem marks the end of a mathematical era. Since virtually all of the tools which were eventually brought to bear on the problem had yet to be invented in the time of Fermat, it is interesting to speculate about whether he actually was in possession of an elementary proof of the theorem. Judging by the tenacity with which the problem resisted attack for so long, Fermat's alleged proof seems likely to have been illusionary. This conclusion is further supported by the fact that Fermat searched for proofs for the cases and , which would have been superfluous had he actually been in possession of a general proof.
In the season 7, episode 6 ("Treehouse of Horror VI") segment entitled of the animated televsion program The Simpsons, the equation appears at one point in the background. Expansion reveals that only the first 9 digits of the expansion match (Rogers 2005). Simpsons season 10, episode 2 ("The Wizard of Evergreen Terrace") mentions , which matches in the first 10 decimal places (Greenwald). Both of these expressions lead to almost integer expressions. At the start of Star Trek: The Next Generation episode "The Royale," Captain Picard mentions that studying Fermat's Last Theorem is a relaxing process.