Fermat's Last Theorem: a margin note and 358 years

What Fermat's Last Theorem says, why a note scribbled in a book margin in 1637 stumped mathematicians for 358 years, and how Andrew Wiles finally proved it.

15 phút đọcCơ bảnEyeBlogs

Đọc bản tiếng Việt →

Engraved portrait of Pierre de Fermat on a grey background: a man with long hair parted in the middle, a thin moustache and a wide white collar, looking straight ahead. Below, in orange script on a dark band: "I have a truly marvelous proof, which this margin is too narrow to contain."
Mục lục

A line written in the margin

Around 1637, in Toulouse in the south of France, a judge sat reading an old mathematics book. It was the Arithmetica of Diophantus, a Greek mathematician who had lived in Alexandria some fourteen hundred years earlier, in a Latin translation printed in 1621. At Problem 8 of Book II, “to divide a given square into two squares”, he picked up his pen and wrote in the blank space beside the text:

It is impossible to divide a cube into two cubes, or a fourth power into two fourth powers, or in general any power higher than the second into two powers of the same degree. I have discovered a truly marvelous proof of this, which this margin is too narrow to contain.

The judge was Pierre de Fermat. The statement he wrote is now called Fermat’s Last Theorem: the equation an+bn=cna^n + b^n = c^n has no solutions in positive whole numbers when nn is greater than 2. Fermat never wrote down that “marvelous proof”. It took mathematicians 358 years to find one, until Andrew Wiles, a British professor at Princeton, published it in 1995, more than a hundred pages long[4].

This is an episode in our series on mathematicians, and the story has a strange twist: the final solution did not come from staring at Fermat’s equation. It came from something that seemed entirely unrelated, the curves that Abel once studied, and those same curves now protect your Internet connection.

What is Fermat’s Last Theorem?

Anyone who has studied geometry knows Pythagoras’ theorem: in a right triangle, the square of the hypotenuse equals the sum of the squares of the other two sides. Some right triangles have all three sides as whole numbers, the most famous being the 3, 4, 5 triangle:

32+42=9+16=25=52.3^2 + 4^2 = 9 + 16 = 25 = 5^2.

There are plenty of such triples: 5, 12, 13; 8, 15, 17; 20, 21, 29… The Babylonians listed them on clay tablets almost four thousand years ago, and Diophantus knew how to generate infinitely many. That is exactly the problem next to which Fermat wrote his note.

Fermat asked the natural next question: what if we replace squares with cubes? Are there three positive whole numbers with a3+b3=c3a^3 + b^3 = c^3? Or fourth powers, a4+b4=c4a^4 + b^4 = c^4? His answer: never, for any power above 2.

The statement is short enough for a seventh-grader to understand. You can try it on a pocket calculator right now: 63+83=7286^3 + 8^3 = 728, while 93=7299^3 = 729, short by exactly 1. Or 93+103=17299^3 + 10^3 = 1729, while 123=172812^3 = 1728, over by exactly 1. So close, yet never a hit. Near the end of this article, a short piece of code will try tens of thousands of pairs and draw that empty space.

Most great problems take years of study just to understand the question. This one anyone can understand and anyone can sit down and try, which is why for three centuries thousands of people believed they were about to solve it.

The judge who did mathematics in his spare time

Fermat was born around 1601 in Beaumont-de-Lomagne, the son of a prosperous leather merchant. He studied law, and from 1631 until the end of his life he served as a councillor at the high court in Toulouse[1]. Mathematics was a pastime.

But a very serious one. Fermat laid the foundations of analytic geometry at almost the same time as Descartes, found ways to compute maxima and tangents decades before Newton, and together with Pascal founded probability theory in letters about an unfinished game. Number theory, the study of whole numbers, he practically revived after more than a thousand years of quiet since Diophantus.

Yet he published almost nothing. He wrote letters to friends, often with a challenge problem and a claim that he had solved it, but without the solution. And he wrote notes in the margins of books.

Fermat passed away in 1665. Five years later, his son Clément-Samuel republished the Arithmetica together with his father’s 48 marginal notes[1]. The original copy with Fermat’s handwriting has been lost. What remains is the 1670 printed page below: right under Problem 8 is an italic passage headed Observatio Domini Petri de Fermat, “observation of Master Pierre de Fermat”.

A page printed in 1670 in Latin and Greek, the paper yellowed: Problem VIII of Diophantus' Arithmetica, dividing a square into a sum of two squares. Directly below is an italic passage headed Observatio Domini Petri de Fermat, the note that states Fermat's Last Theorem.
Problem 8 of Book II of the Arithmetica, 1670 edition, with Fermat's note printed in italics below. Public domain (Wikimedia Commons).

Later mathematicians checked the claims in these notes one by one and gradually settled them. By the end of the 18th century only one was left, so it came to be called Fermat’s “last” theorem, even though strictly speaking it was still only a conjecture.

Did Fermat really have a proof?

Most historians of mathematics answer: almost certainly not.

Fermat did leave a genuine proof for the case n=4n = 4, in another note. The method is called infinite descent: suppose there is a solution; from it, build another solution with smaller numbers, then smaller still, forever. But positive whole numbers cannot keep decreasing forever, so the original solution cannot exist.

Later, in his letters, Fermat repeatedly challenged friends to prove the cases of cubes and fourth powers, but never mentioned the general case again[3]. More importantly, Wiles’ proof needs tools from the 20th century, and every route Fermat might have taken was tried by later mathematicians and failed. The widely accepted view is that Fermat once thought of a flawed argument, then noticed the flaw and quietly stopped mentioning it. He probably never imagined the book would be reprinted with that note.

Two centuries, one exponent at a time

If you cannot do every exponent at once, do them one at a time. In fact it is enough to prove the theorem for n=4n = 4 and for odd prime exponents: a solution with exponent 15 would give a15=(a5)3a^{15} = (a^5)^3, a solution with exponent 3.

Fermat had taken care of 4. What followed was a slow climb:

  • Exponent 3: Leonhard Euler, who had solved the seven bridges of Königsberg, gave a proof in his algebra textbook of 1770. It had a gap, but one that can be filled using Euler’s own other results[3].
  • A whole family of primes: around the 1820s, Sophie Germain, a Frenchwoman who taught herself mathematics while universities were closed to women, proved a result covering an entire family of primes. She had once written to Gauss under the name of a male student, “Monsieur LeBlanc”[3].
  • Exponent 5: Dirichlet and Legendre, 1825.
  • Exponent 7: Gabriel Lamé, 1839.

After nearly two hundred years, four exponents were done. A different idea was needed.

1 March 1847

On 1 March 1847, Lamé announced to the French Academy of Sciences that he had found a proof for every exponent, by splitting an+bna^n + b^n into a product of factors using a kind of “new number” built from the nn-th roots of 1. Augustin Cauchy immediately said he was pursuing the same approach.

Joseph Liouville pointed out a suspicious step. The whole argument relied on something that seemed obvious: every number factors into primes in exactly one way, like 12=2×2×312 = 2 \times 2 \times 3. That is true for ordinary whole numbers. But for Lamé’s “new numbers”?

A few weeks later, Ernst Kummer wrote from Germany that he had proved three years earlier that it is false[3]. The simplest example of this kind appears when you add −5\sqrt{-5} to the whole numbers:

6=2×3=(1+−5)×(1−−5),6 = 2 \times 3 = (1 + \sqrt{-5}) \times (1 - \sqrt{-5}),

and none of these factors can be broken down any further: the two factorizations are genuinely different. Lamé’s and Cauchy’s proofs collapsed.

To restore unique factorization, Kummer invented “ideal numbers”, and with them proved the theorem for a whole class of primes called regular primes, which includes every prime below 100 except 37, 59 and 67. The idea, later developed by Dedekind into the notion of an ideal, became a cornerstone of modern algebra. It was the first time Fermat’s theorem left behind a gift bigger than itself. Not the last.

A prize, and letters that never stopped coming

Not everyone was taken with the problem. In 1816, Gauss wrote that Fermat’s theorem, as an isolated proposition, held little interest for him, since he could easily state many such propositions that no one could prove or disprove[3].

In 1908, the German industrialist Paul Wolfskehl left in his will a prize of 100,000 marks for the first proof of the theorem, administered by the Göttingen Academy of Sciences[2]. The result was a flood of mail: 621 “proofs” in the first year alone, eventually thousands. According to a well-known anecdote, the mathematician Edmund Landau had cards printed in advance: “Thank you for your manuscript on the proof. The first mistake is on page ___, line ___”, and had his students fill in the blanks. After two wars and inflation, when the prize was finally awarded in 1997 it was worth only about 75,000 Deutschmarks.

Computers joined in too: by 1993 the theorem had been verified for every prime exponent up to four million[3]. But four million is not infinity, and checking every case you can think of is not a proof.

A detour through curves

The breakthrough came from two branches of mathematics that seemed to have nothing to do with each other.

The first is elliptic curves, of the form y2=x3+ax+by^2 = x^3 + ax + b, which you met in the article on Abel: on them you can “add” two points to get a third.

The second is modular forms, functions so symmetric it is hard to believe, living in an entirely different world of complex analysis.

Imagine every elliptic curve has a fingerprint, an infinite sequence of numbers: for each prime pp, count how many points the curve has when you work modulo pp (as the Abel article did for a curve modulo 97). Every modular form also has a characteristic sequence of its own. In 1955, at a conference in Japan, Yutaka Taniyama put forward a bold idea, later made precise by Goro Shimura: the fingerprint of every elliptic curve matches the fingerprint of some modular form. The two worlds are really one, written in two different languages.

The Taniyama–Shimura conjecture was regarded as deep but out of reach. Taniyama passed away in 1958, at only 31, too early to see it become the key to Fermat’s problem.

A curve that cannot exist

In 1984, the German mathematician Gerhard Frey made a surprising observation. Suppose Fermat’s theorem is false, so there are positive whole numbers with ap+bp=cpa^p + b^p = c^p for some prime pp. Then build the curve

y2=x (x−ap) (x+bp).y^2 = x\,(x - a^p)\,(x + b^p).

Frey argued that this curve would be so strange that it could not be modular: its fingerprint could not match any modular form. Frey’s observation was not yet a proof. In 1986, Ken Ribet at Berkeley proved it rigorously[6]. As the story goes, the last piece fell into place while Ribet was having coffee with the mathematician Barry Mazur.

After Ribet, the chain of reasoning lacked just one link:

  1. If Fermat’s equation has a solution, there is a Frey curve that is not modular (proved by Ribet).
  2. If the Taniyama–Shimura conjecture is true, then every elliptic curve (at least of the kind the Frey curve belongs to) is modular.
  3. These contradict each other. So Fermat’s equation has no solution.

A problem about whole numbers had become the problem of proving the Taniyama–Shimura conjecture, at least for the semistable curves the Frey curve belongs to. Harder, but for the first time there was a road.

Seven years in the attic

In 1963, a ten-year-old boy in Cambridge, England, borrowed The Last Problem by Eric Temple Bell from his local library. He read about Fermat’s equation and told himself that one day he would solve it[2]. His name was Andrew Wiles.

Wiles grew up to be an expert in exactly the right thing: elliptic curves. In the summer of 1986, on hearing that Ribet had completed the first link, he recalled knowing at once that the course of his life was changing[2].

He decided to work alone and in secret, in his attic study at home in Princeton. So that colleagues would not suspect, he held back side results and published them bit by bit. For seven years only his wife knew what he was working on; near the end, he asked his colleague Nick Katz to check part of it.

Cambridge, June 1993

From 21 to 23 June 1993, Wiles gave three lectures at the Isaac Newton Institute in Cambridge, the city where he grew up. The title of the series said nothing about Fermat, but rumours spread fast, and the third lecture was packed. Having written the final corollary on the board, Fermat’s Last Theorem, he said: “I think I’ll stop here.” The room broke into applause.

The news made front pages around the world. But in September 1993, Katz himself, acting as a referee for the roughly two-hundred-page manuscript, found a gap in a crucial step[2]. The more Wiles tried to fix it, the deeper it seemed.

More than a year followed that Wiles has described as the hardest of his life, with the whole world waiting. He brought in his former student Richard Taylor. On the morning of 19 September 1994, while taking one last look at why an old method he had abandoned did not work, Wiles suddenly saw that this very method, combined with the new approach, closed the gap exactly[2].

In May 1995, the Annals of Mathematics printed two papers back to back: a long one by Wiles and a shorter one by Taylor and Wiles[4][5]. From the margin note of 1637, that was 358 years.

In 2016, Wiles received the Abel Prize, named after the young Norwegian whose work on elliptic functions is one of the roots of this very proof[7].

Where is Fermat’s Last Theorem today?

To be honest, the statement “no whole-number solutions when n>2n > 2” does not power any application. Its value lies in what people had to build along the way.

A bridge between two worlds

Wiles proved the Taniyama–Shimura conjecture only for semistable curves. In 2001, Christophe Breuil, Brian Conrad, Fred Diamond and Richard Taylor completed it for all elliptic curves over the rational numbers. Today it is called the modularity theorem.

It was the first big piece proved of the Langlands program, a web of conjectures saying that many seemingly distant branches of mathematics are really facets of the same thing, and Wiles’ methods are among its main tools. Ngô Bảo Châu received the Fields Medal in 2010 for proving the Fundamental Lemma, a link in that same program.

The curve in your phone

Elliptic curves, the protagonists of the proof, are also the foundation of the cryptography described in the article on Abel: key exchange in most HTTPS connections, signatures on Bitcoin transactions. When choosing a safe curve, cryptographers have to count its points modulo pp, exactly the “fingerprint” above.

Fermat also left a theorem with a confusingly similar name: Fermat’s little theorem, ap−1a^{p-1} always leaves remainder 1 when divided by a prime pp (if pp does not divide aa), also stated only in a letter. It is the reason RSA decryption works, as explained in prime numbers, RSA and JWT. Measured by applications, the “little” theorem matters far more than the “last” one.

When computers check a proof

A proof of over a hundred pages, resting on thousands of pages of other theory, can be read in full by only a few dozen people in the world, and the gap of 1993 showed that experts can miss things too.

In 2024, Kevin Buzzard at Imperial College London started a multi-year project: rewriting the proof of Fermat’s Last Theorem in Lean, a language in which a computer checks every step of reasoning[8]. Tools like this are also being used to check solutions written by AI models.

Near misses

In a 1998 episode of the cartoon The Simpsons, Homer writes on a blackboard

398712+436512=447212.3987^{12} + 4365^{12} = 4472^{12}.

Take the 12th root of the left side on a pocket calculator and the screen shows exactly 4472. A counterexample to Fermat? No: the writer David X. Cohen, who studied mathematics, deliberately found a near miss close enough to fool a calculator. You can refute it without a machine: 3987 and 4365 are both divisible by 3 (digit sums 27 and 18), so the left side is divisible by 3; 4472 is not (digit sum 17).

And the 1729 from earlier is the famous “taxicab number”: Ramanujan once pointed out to Hardy that it is the smallest number that can be written as a sum of two cubes in two ways, 13+1231^3 + 12^3 and 93+1039^3 + 10^3.

Hunting for Fermat solutions yourself

The Python code below tries every pair 2≤a≤b≤3002 \le a \le b \le 300 (44,850 pairs) and asks: is an+bna^n + b^n an exact nn-th power of a whole number? It uses Python’s exact integers, with no rounding, so it cannot be fooled like a pocket calculator. Then it lists the cubic “near misses” that are off by exactly 1, checks Homer Simpson’s equation, and draws Figure 1. All you need is matplotlib.

fermat_margin.py
import matplotlib.pyplot as plt
plt.rcParams.update({"figure.facecolor": "#16181c", "axes.facecolor": "#16181c", "text.color": "#d4d7dc",
"axes.edgecolor": "#2a2e35", "xtick.color": "#878d97", "ytick.color": "#878d97", "font.size": 12})
N = 300 # try every pair 2 ≤ a ≤ b ≤ N
pairs = [(a, b) for a in range(2, N + 1) for b in range(a, N + 1)]
def nearest(a, b, n):
"""Return the c closest to the n-th root of aⁿ + bⁿ, and the gap aⁿ + bⁿ − cⁿ (exact integers)."""
s = a ** n + b ** n
c = round(s ** (1 / n))
return c, s - c ** n
# ── Part 1: count solutions of aⁿ + bⁿ = cⁿ ───────────────────────────────
for n in range(2, 6):
hits = sum(1 for a, b in pairs if nearest(a, b, n)[1] == 0)
print(f"n = {n}: {hits} solutions with a ≤ b ≤ {N}")
# ── Part 2: cubic "near misses": off by exactly 1 ────────────────────────
near3 = [(a, b, *nearest(a, b, 3)) for a, b in pairs if abs(nearest(a, b, 3)[1]) == 1]
for a, b, c, d in near3:
print(f"{a}³ + {b}³ = {a**3 + b**3:>8} {c}³ = {c**3:>8} off by {d:+d}")
# ── Part 3: Homer Simpson's test ─────────────────────────────────────────
lhs, rhs = 3987 ** 12 + 4365 ** 12, 4472 ** 12
print(f"\n12th root of 3987¹² + 4365¹² ≈ {lhs ** (1 / 12):.10f}")
print("A 10-digit calculator shows:", f"{lhs ** (1 / 12):.6f}", "→ looks like 4472")
print("Exact integer check: 3987¹² + 4365¹² == 4472¹² ?", lhs == rhs)
# 3987 and 4365 are both divisible by 3, but 4472 is not, so the two sides cannot be equal.
print("Left side divisible by 3?", lhs % 3 == 0, "| right side divisible by 3?", rhs % 3 == 0)
# ── Plot ─────────────────────────────────────────────────────────────────
pyth = [(a, b) for a, b in pairs if nearest(a, b, 2)[1] == 0]
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 5.8))
xs = [a for a, b in pyth] + [b for a, b in pyth]
ys = [b for a, b in pyth] + [a for a, b in pyth]
ax1.plot(xs, ys, "o", color="#8fa9c9", ms=3.5)
ax1.annotate("3² + 4² = 5²", (3, 4), xytext=(40, 255), color="#e8b05a", fontsize=12,
arrowprops=dict(arrowstyle="->", color="#e8b05a"))
ax1.set_title(f"n = 2: {len(pyth)} pairs (a, b) hit", color="#d4d7dc", fontsize=12)
ax1.set_ylabel("b", color="#878d97")
# The right panel is almost empty: no pair hits. Gold stars are pairs that miss by exactly 1.
ax2.plot([a for a, b, c, d in near3] + [b for a, b, c, d in near3],
[b for a, b, c, d in near3] + [a for a, b, c, d in near3], "*", color="#e8b05a", ms=14)
ax2.text(150, 285, f"{len(pairs)} pairs tried, 0 hits", color="#878d97", fontsize=12, ha="center")
ax2.annotate("9³ + 10³ = 12³ + 1 = 1729", (9, 10), xytext=(40, 255), color="#e8b05a", fontsize=12,
arrowprops=dict(arrowstyle="->", color="#e8b05a"))
ax2.set_title(f"n = 3: 0 hits, {len(near3)} pairs off by just 1", color="#d4d7dc", fontsize=12)
for ax in (ax1, ax2):
ax.set_xlim(0, N)
ax.set_ylim(0, N)
ax.set_aspect("equal")
ax.set_xlabel("a", color="#878d97")
ax.grid(color="#22262c")
fig.tight_layout()
fig.savefig("fermat-suyt-trung-en.png", dpi=150, bbox_inches="tight")
n = 2: 249 solutions with a ≤ b ≤ 300
n = 3: 0 solutions with a ≤ b ≤ 300
n = 4: 0 solutions with a ≤ b ≤ 300
n = 5: 0 solutions with a ≤ b ≤ 300
6³ + 8³ = 728 9³ = 729 off by -1
9³ + 10³ = 1729 12³ = 1728 off by +1
64³ + 94³ = 1092728 103³ = 1092727 off by +1
71³ + 138³ = 2985983 144³ = 2985984 off by -1
73³ + 144³ = 3375001 150³ = 3375000 off by +1
135³ + 138³ = 5088447 172³ = 5088448 off by -1
135³ + 235³ = 15438250 249³ = 15438249 off by +1
12th root of 3987¹² + 4365¹² ≈ 4472.0000000071
A 10-digit calculator shows: 4472.000000 → looks like 4472
Exact integer check: 3987¹² + 4365¹² == 4472¹² ? False
Left side divisible by 3? True | right side divisible by 3? False
Two square panels side by side, with axes a and b both running from 0 to 300. The left panel, titled 'n = 2: 249 pairs (a, b) hit', is full of blue dots: some scattered, some lined up on straight rays from the origin, like multiples of the triple 3, 4, 5; a gold arrow points to a dot near the origin labelled 3² + 4² = 5². The right panel, titled 'n = 3: 0 hits, 7 pairs off by just 1', is almost empty, showing only the text '44850 pairs tried, 0 hits' and about a dozen scattered gold stars, each a near miss; an arrow points to the star near the origin labelled 9³ + 10³ = 12³ + 1 = 1729.
Figure 1. Left: for squares, there are 249 pairs a ≤ b ≤ 300 where a² + b² is a perfect square; many lie on straight rays because multiplying the triple 3, 4, 5 by 2, 3, 4… still gives a triple. Right: for cubes, none of the 44,850 pairs hits; the stars are pairs that miss by exactly 1 (each pair drawn twice, mirrored across the diagonal).

The first four lines are Fermat’s Last Theorem in a nutshell: exponent 2 has 249 solutions, exponents 3, 4 and 5 have none. The next seven lines show how close cubes can get, just 1 apart, without ever hitting. The last line is the quickest way not to be fooled by Homer Simpson.

But remember the lesson of 1993: finding no solutions among 44,850 pairs, or up to four million exponents, is still not a proof. You can raise N to 1000 or 2000 and wait a little longer. The answer will still be 0, but to be sure for every number took 358 years and more than a hundred pages from Wiles.

Back to the margin

Fermat probably had no proof. But that confident line, “I have discovered a truly marvelous proof”, kept the problem alive for 358 years. A puzzle anyone could understand, plus the promise that a solution existed, was enough to draw in Euler, Sophie Germain, Kummer, thousands of amateurs writing to Göttingen, and a ten-year-old boy in a library in Cambridge.

Along the way, mathematics gained Kummer’s ideal numbers, the bridge between elliptic curves and modular forms, and tools that hundreds of researchers now use in the Langlands program. None of it fit in that narrow margin in Toulouse. Perhaps that is the most valuable thing the note left behind.

Other episodes in the series: Pascal, Fermat and the unfinished game, Euler and the seven bridges of Königsberg, and Abel and the letter that came too late, who opened the way to the elliptic curves in Wiles’ proof.

Free geometry illustration tool for students and teachers: EyeViz.

Phát video: Video: Fermat's Last Theorem: a margin note and 358 years
Video: Fermat's Last Theorem: a margin note and 358 yearsVideo bằng tiếng Việt

Tài liệu tham khảo

  1. [1]J. J. O'Connor and E. F. Robertson. Pierre de Fermat (1601–1665), biography. MacTutor History of Mathematics, University of St Andrews.
  2. [2]Simon Singh. Fermat's Last Theorem (US title: Fermat's Enigma). Fourth Estate, 1997.
  3. [3]J. J. O'Connor and E. F. Robertson. Fermat's Last Theorem. MacTutor History of Mathematics, University of St Andrews.
  4. [4]Andrew Wiles. Modular elliptic curves and Fermat's Last Theorem. Annals of Mathematics 141(3), pp. 443–551, 1995.
  5. [5]Richard Taylor and Andrew Wiles. Ring-theoretic properties of certain Hecke algebras. Annals of Mathematics 141(3), pp. 553–572, 1995.
  6. [6]Kenneth A. Ribet. On modular representations of Gal(Q̄/Q) arising from modular forms. Inventiones Mathematicae 100, pp. 431–476, 1990.
  7. [7]Sir Andrew J. Wiles, Abel Prize Laureate 2016. Norwegian Academy of Science and Letters.
  8. [8]Kevin Buzzard et al.. Formalising Fermat's Last Theorem in Lean (the FLT project). Imperial College London.
  9. [9]Fermat's Last Theorem. Wikipedia.