The story of Fermat's Last Theorem begins with a marginal note that Pierre de Fermat (1601–1665) wrote in his copy of the works of Diophantus. Next to problem 8 in book II (a problem that discusses how to create Pythagorean triples), Fermat wrote:
On the other hand, it is impossible for a cube to be written as a sum of two cubes or a fourth power to be written as a sum of two fourth powers or, generally, for any number that is a power greater than the second to be written a a sum of two like powers. I have a truly marvelous proof of this proposition that this margin is too narrow to contain.
Or, in symbols, there is no solution in natural numbers of an + bn = cn for n > 2. Fermat never left any indication of what the proof was. In retrospect, Fermat probably either did not have a proof, or had a flawed proof. As this was just a marginal note in a book he owned and not intended for publication, it seems most likely that Fermat realized that his proof wouldn't work, never bothered to cross out his erroneous note, and thought no more of it; after all, who else would ever read it? However, after his death, a version of the book containing his notes was published and his conjecture saw the light of day. The conjecture became known as "Fermat's Last Theorem", which is a bit of a misnomer because he wrote this note no later than 1637, relatively early in his mathematical career, and also because it had not yet been proved and so was not yet a theorem, yet the name stuck.
The proof for n = 4 is not highly difficult; Fermat himself found a proof for this exponent. The proof involves infinite descent, a method which involves assuming that a solution in natural numbers exists, and showing that the existence of that solution implies a smaller solution, which implies a smaller one, and so on and so on, so there is no smallest solution in natural numbers. However, if there are to be any solutions in natural numbers, one of them has to be the smallest, so the assumption that there are solutions is false and there are no solutions for n = 4.
A proof for n = 4 would also prove Fermat's Last Theorem for n = 8, 12, 16, ..., since numbers that are eighth, twelfth, sixteenth, ... powers are also fourth powers. In general, Fermat's Last Theorem could be proved if it were shown to be true for n = 4 and for n equal to all odd prime numbers, since all numbers ≥ 3 are either prime or are divisible by either 4 or an odd prime number. During the 1700s and 1800s various mathematicians proved the conjecture for various prime numbers, but not for all prime numbers.
In 1847 Ernst E. Kummer (1810–1893) proved Fermat's Last Theorem for a whole slew of values of n. At one point he believed that he had proved the theorem for all n, but an unwarranted assumption was later found in his argument.
Later on in the nineteenth century, a young student of mathematics named Paul Wolfskehl, who had been spurned by a young woman, had decided to kill himself. He decided the hour when he would do so, and then got so distracted reading Kummer's work that the hour he had chosen had passed, so, perhaps due to the work renewing his interest in mathematics, he decided not to kill himself. When he died in 1906, his will stipulated that 100,000 German marks was to be donated to the Scientific Society of Göttingen to be awarded to whoever proved Fermat's Last Theorem. At the time, 100,000 German marks was the equivalent of £5,000 or $25,000, an incredible sum when the average yearly income in the United States was only somewhat larger than $600. Various mathematicians expressed their fears that such a large inducement might set all sorts of mediocre mathematicians on a path to wasting their time, and in fact it did. In the first year after Wolfskehl's death, the Society received 621 supposed proofs of Fermat's Last Theorem, coming from all kinds of people who, according to the Society, seemed to be motivated more by the 100,000 marks than by any desire to further mathematical knowledge. After World War I, hyperinflation swept away much of the value of the prize, but not everyone knew that so it didn't stop amateur mathematicians and cranks to continue trying to prove the theorem.
The crucial insight to proving Fermat's Last Theorem occurred in 1984. Gerhard Frey noted that, if Fermat's Last Theorem were false, a certain type of elliptic curve known as a semistable elliptic curve would have properties that would violate the Taniyama-Shimura-Weil conjecture (known as the modularity theorem since its proof in 2001). Frey's insight was proven by Ken Ribet in 1986. In 1993, Andrew Wiles announced that he had proven the Taniyama-Shimura-Weil conjecture for semistable elliptic curves, which meant that Fermat's Last Theorem would be proven. There was an error in his initial proof, but Wiles was able to fix the error in 1994, and the proof was published in 1995.