Number theory is the study of positive integers. One, two, three. It used to be called “higher arithmetic.” It feels old. Natural. Like fire or water.

Most people assume math is either useful or abstract. Number theory sits in a weird middle ground. Amateurs love it. Professionals obsess over it. The problems are easy to understand. Really easy. A ten-year-old can grasp the question. But solving it? That usually requires a PhD-level toolkit.

For centuries, this branch of math was considered the purest, most useless form of mathematics. No bridges built. No engines designed. Just numbers.

Then computers arrived.

Suddenly, number theory became the backbone of digital security. Encryption relies on it. Digital communications depend on it. Modern tech turned abstract curiosity into practical necessity. Computers also helped us factor massive numbers, find primes, and test ideas that were previously impossible to check.

Today, the field is huge. It splits into elementary, algebraic, analytic, geometric, and probabilistic number theory. Each uses different tools to crack the same hard problems.

How Ancient Civilizations Discovered Number Theory

Counting is ancient. Really ancient.

Archaeologists found a 10,000-year-old bone in the Congo region of Africa. It has tally marks scratched into it. Someone was counting something. Maybe livestock. Maybe days. That’s the first step toward understanding multiplicity.

By the time civilizations like Mesopotamia, Egypt, China, and India rose, they had a solid grasp of numbers. We know this because their records survived. Clay tablets. Papyrus. Temple carvings.

The Babylonians were particularly sharp. A tablet called Plimpton 322, dated to around 1700 BCE, shows they understood Pythagorean triples long before Pythagoras was born. In modern notation, these are sets of numbers where $x^2 + y^2 = z^2$. One example on the tablet uses 2,291, 2,700, and 3,541. The math works out perfectly.

This wasn’t just random calculation. It was number theoretic sophistication. But they didn’t have a general theory. No framework. Just isolated results.

For that, we have to look to Classical Greece. They mixed the mystical vibes of the Pythagoreans with the cold, hard logic of Euclid.

Pythagoras and the Mysticism of Numbers

Pythagoras lived in southern Italy around 580–500 BCE. He had followers. Lots of them.

His philosophy was simple but radical: number is the unifying concept of the universe. Planetary motion? Numbers. Musical harmony? Numbers.

Because of this belief, the Pythagoreans attached quasi-rational properties to specific integers. They loved perfect numbers. A perfect number equals the sum of its proper divisors.

Take 6. Its proper divisors are 1, 2, and 3. Add them up: $1 + 2 + 3 = 6$. Done.

Another example is 28. Its divisors are 1, 2, 4, 7, and 14. Sum them: $1 + 2 + 4 + 7 + 14 = 28$.

Centuries later, the philosopher Nicomachus of Gerasa claimed these numbers represented “virtues, wealth, moderation, propriety, and beauty.” Modern writers tend to call this nonsense. Or numerical theology.

The Greeks also liked amicable numbers. These are pairs of integers where each is the sum of the proper divisors of the other. They only knew one pair: 220 and 284.

Check the math. The divisors of 284 are 1, 2, 4, 71, and 142. They add up to 220. The divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55, and 110. They add up to 284.

To someone prone to number mysticism, this looks like magic.

Euclid Brought the Logic

Euclid didn’t care about mysticism. He wanted rigor.

In Book VII of Elements (c. 300 BCE), he defined a number as “a multitude composed of units.” Note the plural. For Euclid, 1 wasn’t a number. 2 was the smallest number.

He defined a prime as a number “measured by a unit alone.” In other words, its only proper divisor is 1. Composite numbers are anything else. Perfect numbers remain those that equal the sum of their parts.

This shift marked the beginning of number theory as a mathematical enterprise, not a numerological one. Euclid proved several theorems that still stand today.

First, he gave a procedure for finding the greatest common divisor of two whole numbers. We call this the Euclidean algorithm now. It’s fundamental.

Second, he established the unique factorization theorem. Also known as the fundamental theorem of arithmetic. It states that any whole number can be factored into primes in one and only one way.

Take 1,960. Its prime factorization is $2 \times 2 \times 2 \times 5 \times 7 \times 7$. No other combination of primes multiplies to 1,960. Euclid’s proof wasn’t airtight by modern standards, but the essence was there.

Third, Euclid proved that there is no finite collection of all primes. He showed you can always find another one.

His argument, Proposition 20 of Book IX, is elegant. Take any finite list of primes: $a, b, c, \dots, n$. Multiply them all together. Then add 1. Call this number $N$.

$N = (a \times b \times c \times \dots \times n) + 1$

Now, examine the alternatives.

Euclid’s Final Blow and the Infinite List

Here is the logic that breaks the idea of a final prime.

Take any list of primes. Multiply them all together. Add one. Call the result N.

If N is prime, it is a new one. It is larger than every number in your original list. It cannot be on the list. Simple.

If N is not prime, it is composite. It must have prime factors. Euclid showed these factors cannot be in your original list either.

Why? Because dividing N by any of the original primes leaves a remainder of 1. None of them fit evenly.

Try it. Start with 2, 7, and 11. Multiply them. Add 1. You get 155.
155 is composite. Its factors are 5 and 31.
Neither 5 nor 31 was in your starting group. You found new primes.

This proves primes never end. The list is infinite.

Euclid didn’t stop there. He ended Book IX with a heavy hitter.

He found a recipe for perfect numbers.

A perfect number equals the sum of its proper divisors. 28 is one. 1+2+4+7+14 = 28.

Euclid’s rule: Take powers of 2. Add them up. 1 + 2 + 4 + … + 2^k.
If that sum is prime, multiply it by 2^k. The result is perfect.

Example: 1 + 2 + 4 = 7. Seven is prime.
Multiply 7 by 4 (which is 2^2). You get 28.
It works. It was a massive leap for its time.

Diophantus and the Integer Obsession

Fast forward to Alexandria. Around 250 CE.

Diophantus wrote Arithmetica. He cared about one thing: whole numbers.

No fractions. No decimals. Integers only.

He created Diophantine equations. These are algebraic puzzles where only integer solutions count.

He asked for two numbers. One is a square. One is a cube.
The sum of their squares must also be a square.

In symbols: find integers x, y, z so that (x^2)^2 + (y^3)^2 = z^2.

You can find real numbers that work easily. x = root 2, y = 1, z = root 5.
But integers? That is hard.

One solution is x = 6, y = 3, z = 45.
Check it. 36 squared is 1296. 3 cubed is 27. 27 squared is 729.
1296 + 729 = 2025.
The square root of 2025 is 45.

It fits. But finding it requires work. Diophantus set the stage for modern algebraic number theory.

The East Steps In While Europe Sleeps

Europe went dark after Rome fell. Number theory stalled.

Asia did not.

Chinese astronomers needed better calendars. They hit a wall with modular arithmetic.

Sun Zi around 250 CE posed a classic problem.
Find a number that:
– Leaves remainder 2 when divided by 3
– Leaves remainder 3 when divided by 5
– Leaves remainder 2 when divided by 7

The answer is 23.

Check it. 23 / 3 is 7 remainder 2. 23 / 5 is 4 remainder 3. 23 / 7 is 3 remainder 2.

A thousand years later, Qin Jiushao formalized this. We call it the Chinese remainder theorem. It is still used in computer science today.

Meanwhile in India, Brahmagupta was busy in the 7th century.

He tackled what we now wrongly call the Pell equation.

Find integers x and y such that 92x^2 + 1 = y^2.

He bet anyone who solved it in a year could call themselves a mathematician.

The solution is x = 120 and y = 1,151.

92 times 14,400 plus 1 equals 1,324,801.
1,151 squared is 1,324,801.

He also gave us Hindu-Arabic numerals.

We use them every day. Base-10. Zero included.
Adopted by the world because they are simple. The Indians used them by 800 CE.

Then the Islamic world took over.

Baghdad in the 9th century was a hub. Scholars translated Greek texts. Then they improved them.

Thabit ibn Qurrah found new amicable numbers.
These are pairs where the sum of divisors of one equals the other.

He found 17,296 and 18,416.
The Greeks knew one pair. Thabit found another.

Fermat Changes the Game

Number theory drifted into Europe during the Renaissance.

It was ignored.

Mathematicians loved geometry. They loved algebra. Probability was hot.
Number theory was seen as a toy. A parlor game.

Then came Pierre de Fermat.

1601 to 1665. A French magistrate. A hobbyist.
He published almost nothing. He wrote letters.

He changed everything.

Fermat spotted patterns others missed. He posed problems that took centuries to solve.

Here is how he reshaped the field.

Fermat’s Little Theorem

If p is prime and a is any integer, then p divides a^p – a.

Let p = 7. Let a = 12.
12^7 is huge. Subtract 12.
Divide by 7.
It divides evenly. No remainder.

This is not obvious. It is a powerful tool for cryptography today.

Sums of Squares

Fermat looked at odd primes. He split them into two camps.

Type 1: 4k + 1. Like 5, 13, 17, 97.
Type 2: 4k – 1. Like 3, 7, 11, 79.

Fermat claimed Type 1 primes can always be written as the sum of two squares.
5 = 2^2 + 1^2.
97 = 9^2 + 4^2.

Type 2 primes cannot.
3 is not a sum of two squares. 79 is not.

This split is a landmark in number theory.

The Four Square Theorem

In 1638, Fermat dropped another bomb.

Every whole number is the sum of four or fewer squares.

He said he had the proof. He never shared it.

That is the Fermat style. State the truth. Leave the work to others.

This attitude turned number theory from a curiosity into a serious discipline. It forced mathematicians to dig deeper. To prove things.

The era of playful guessing was over.

How Fermat’s “Impossible” Triangle and Wrong Primes Set the Stage

Fermat had a habit of dropping heavy mathematical bombs and walking away. One of his earlier claims was that you can’t have a right triangle with integer sides where the area is also a perfect square.

Think about it. You need integers $x$, $y$, and $z$ such that $x^2 + y^2 = z^2$. But you also need the area, which is $\frac{xy}{2}$, to equal some integer $w^2$. Fermat said this combination doesn’t exist.

Unlike his usual cryptic notes, he actually provided a proof for this specific case. He used a method called infinite descent. Here is how it works:
– Assume a solution exists.
– Show that you can construct a smaller set of integers that also solves the problem.
– Repeat.

You get an endless chain of smaller and smaller positive integers. But that is impossible. Positive integers have a floor. They stop at 1. Since you can’t descend forever, the original assumption must be wrong. No such triangle exists.

Then there was his guess about primes. Fermat claimed that numbers in the form $2^{2^n} + 1$ are always prime. He checked the first few cases:
– $n=0$: 3 (prime)
– $n=1$: 5 (prime)
– $n=2$: 17 (prime)
– $n=3$: 257 (prime)
– $n=4$: 65,537 (prime)

These are now called Fermat primes. It looked like a solid pattern. Until it wasn’t. The next number in the sequence, $2^{2^5} + 1$, equals 4,294,967,297. It is not prime. Fermat was wrong. Even geniuses miss things.

But his biggest claim came from the margin of his copy of Diophantus’s Arithmetica. He wrote that you cannot split a cube into two cubes, or a fourth power into two fourth powers, or any higher power into two of the same kind.

In math terms: $x^n + y^n = z^n$ has no whole number solutions for $n > 2$.

He added a cheeky note: he had found a “truly marvelous proof,” but the margin was too narrow to write it down. This became Fermat’s Last Theorem. For 350 years, it remained unsolved. It became the most famous open problem in math.

Why Number Theory Was Ignored for a Century

Fermat was brilliant, but number theory didn’t take off right away. Why? Partly because he rarely published full proofs. But the bigger issue was the rise of calculus in the late 1600s.

Calculus solved real-world problems. It helped physicists, astronomers, and engineers understand motion, forces, and orbits. Number theory, by contrast, seemed “pure.” It had no obvious application to building bridges or predicting planetary paths. Scholars chased calculus. Number theory sat on the shelf.

How Euler Saved Number Theory

Enter Leonhard Euler. Born in 1707, Euler was Swiss, incredibly prolific, and arguably the most influential mathematician of the 18th century. When he decided to care about number theory, the subject suddenly mattered.

Initially, Euler didn’t care either. He was busy with other math. But Christian Goldbach, a diplomat and number theory enthusiast, wouldn’t let him ignore it. Goldbach wrote to Euler like a persistent salesperson.

On December 1, 1729, Goldbach asked: “Do you know Fermat’s observation that all numbers $2^{2^n} + 1$ are prime?”

Euler took the bait. He checked Fermat’s claim. And he broke it. He showed that 4,294,967,297 is divisible by 641. Fermat was wrong again.

This was the start. Over the next 50 years, Euler published more than 1,000 pages on number theory. He proved many of Fermat’s other assertions:
– He proved Fermat’s Little Theorem.
– He proved that primes of the form $4k + 1$ can be written as the sum of two squares.
– He worked on perfect numbers, showing that even perfect numbers must follow the form Euclid found 2,000 years earlier.
– He found 58 new pairs of amicable numbers. Before Euler, only three pairs were known.

Euler couldn’t solve everything, though. He managed to prove Fermat’s Last Theorem for the cases where $n=3$ and $n=4$. But the general case stumped him. He also couldn’t prove Goldbach’s Conjecture —the idea that every even number greater than 2 is the sum of two primes. He believed it was true but couldn’t prove it.

Still, Euler gave number theory legitimacy. It was no longer just a hobby for eccentric mathematicians. It was serious math.

The 19th Century and the Sum of Four Squares

Progress accelerated after Euler. In 1770, Joseph-Louis Lagrange proved another one of Fermat’s claims: every whole number can be written as the sum of four or fewer squares.

Soon after, Lagrange established Wilson’s Theorem. It states that a number $p$ is prime if and only if $p$ divides evenly into $[(p-1)!] + 1$.

Number theory was waking up. But the real revolution was coming. The next major shift would come with a book that changed how we think about numbers entirely.

Gauss sets the rules for modern number theory

Carl Friedrich Gauss dropped a bomb in 1801. Disquisitiones Arithmeticae wasn’t just another math book. It was the bible for number theorists. He took the messy work of everyone before him, organized it, and then sprinted past them.

Gauss knew that breaking composite numbers into prime factors was “one of the most important and useful in arithmetic.” So he gave the first modern proof of the unique factorization theorem. He also nailed down the law of quadratic reciprocity. Euler had seen glimpses of it. Gauss proved it.

To make the math cleaner, he introduced congruence. If you write ab mod m, it means m divides evenly into the difference ab. Take 39 and 4. Their difference is 35. 7 divides 35. So 39 ≡ 4 mod 7.

This simple idea changed everything. Paired with Fermat’s little theorem, it became a core tool. Without it, modern number theory looks very different.

Why Dirichlet changed the game with calculus

Gauss inspired a whole generation. Sophie Germain obsessed over the theory of numbers. She made real progress on Fermat’s last theorem. Adrien-Marie Legendre and Peter Gustav Lejeune Dirichlet proved it for n = 5. The sum of two fifth powers can’t be a fifth power.

Ernst Kummer pushed further in 1847. He showed the theorem held for a large class of exponents. But he couldn’t rule out failures elsewhere. The problem stayed open.

Dirichlet kept a copy of Gauss’s Disquisitiones by his bed. He read it at night. And he changed the field. He proved that if a and b share no common factor, the arithmetic progression a, a + b, a + 2b, a + 3b, … contains infinitely many primes.

That means there are infinitely many primes in the form 4k + 1. And infinitely many in 4k − 1.

The result was big. The method was bigger. Dirichlet used calculus to prove a number theory result. Most mathematicians thought that was impossible. Or at least, strange. This mix of analysis and arithmetic birthed analytic number theory.

How the prime number theorem counts primes

The prime number theorem stands as one of the 19th century’s greatest hits. It needs a quick explanation.

Let π(n ) be the count of primes less than or equal to n.
For n = 10, the primes are 2, 3, 5, 7. So π(10) = 4.
For n = 25, π(25) = 9.
For n = 100, π(100) = 25.

Now look at the ratio. π(n )/n tells you how many numbers up to n are prime.
π(10)/10 = 0.40. Forty percent.
As n grows, this percentage drops. The primes get thinner.

How the Prime Number Theorem maps the chaos of primes

The pattern isn’t obvious. You look at prime numbers and they scatter like shrapnel. No rhythm. No easy rule. But the Prime Number Theorem finds a signal in the noise. It gives us a way to predict how primes distribute themselves among whole numbers, at least when those numbers get big.

For a large number n, the proportion of primes up to n —written as π(n )/n —is roughly 1/log n. That log is the natural logarithm. Linking primes to logarithms feels weird. It’s extraordinary. It connects discrete counting to continuous curves.

Young Gauss spotted this first. He was flipping through log tables, staring at primes, and his mind just clicked. Later, Bernhard Riemann and Pafnuty Chebyshev pushed the math further. But it took until 1896 for Jacques Hadamard and Charles Jean de la Vallée-Poussin to actually prove it. A tidy ending to the 19th century.

The 20th century explosion in number theory research

Then the 20th century hit. Number theory didn’t just grow; it exploded. Classical methods met analytic techniques, and new subfields sprouted. Algebraic number theory. Geometric number theory. Combinatorial number theory. The concepts got abstract. The tools got sophisticated. Fermat couldn’t have imagined this.

Srinivasa Ramanujan burst onto the scene early on. He had almost no formal training and died young, but he produced brilliance like water from a tap. He loved analytic number theory. His papers had titles like “Highly composite numbers” and proved that almost all numbers n are made of about log(log n ) prime factors. Dense stuff. But accurate.

Then there was Paul Erdős. A Hungarian genius who lived out of a suitcase. He traveled constantly, hopping between universities, chasing math. At 18, he simplified Chebyshev’s theorem: if n ≥ 2, there’s always a prime between n and 2n. He published over 1,500 papers with more than 500 collaborators. He’d show up unannounced, say “My brain is open,” and dive into work. No sleep. No home. Just math.

Computers and cryptography change the game

Two things changed everything later. Computers. And encryption.

Computers brought brute force to bear on old questions. Euler thought you needed at least four fourth powers to sum to a fourth power. He was wrong. In 1988, Noam Elkies used a computer to find a counterexample:

2,682,440^4 + 15,365,639^4 + 18,796,760^4 = 20,615,673^4

The result has 30 digits. Euler missed it because the numbers are huge. The computer didn’t.

Then came the money. Number theory got practical. Encryption schemes rely on factoring gigantic numbers into primes. You know the factors. The hacker doesn’t. This broke the idea that number theory is beautiful but useless. It’s now the backbone of digital security.

The climax: Fermat’s Last Theorem solved

In 1995, Andrew Wiles proved Fermat’s Last Theorem. Richard Taylor helped. The proof was 130 pages long. Complex. Dense. It wouldn’t fit in any margin, as Fermat had claimed. But it was true. A century of effort, finally resolved.

Unsolved mysteries in number theory

But the field isn’t done. Many problems remain open. They sound simple. They aren’t.

  • Do odd perfect numbers exist?
  • Are there infinitely many primes of the form n ^2 + 1?
  • Are there infinitely many twin primes (pairs like 5 and 7)?
  • Is Goldbach’s conjecture true? (Every even number is the sum of two primes.)

Euler tried. Everyone since has tried. No luck.

The Clay Mathematics Institute in Cambridge, Massachusetts, named seven Millennium Prize Problems in 2000. Each comes with a million dollars. Maybe these problems will be solved. Maybe not. Eric Temple Bell called number theory the “last great uncivilized continent of mathematics.” He wasn’t wrong.

The theory of numbers is old. It’s fresh. The problems stick because they look simple. They’re deceptively hard. Beautiful, too. Gauss called it the queen of mathematics. He wasn’t flattering. He was describing the hierarchy.