The Gaussian Integers
Ordinary number theory studies \mathbb{Z} = \{\ldots, -2, -1, 0, 1, 2, \ldots\}.
Gauss asked a deceptively simple question: what if
we enlarge this world to include i = \sqrt{-1}, but keep the "integer"
spirit — whole-number real and imaginary parts, nothing fractional? The result,
a + bi with a, b \in \mathbb{Z}, is a brand new
number system: the Gaussian integers.
This new world has its own notion of prime, its own unique factorisation, and — this is the
payoff — it explains facts about the ordinary integers that otherwise look like coincidences. Why is
5 = 1^2 + 2^2 a sum of two squares while 7 is
not, no matter how hard you search? By the end of this page that question answers itself, almost
for free, once you know how primes behave when you move house from \mathbb{Z}
to \mathbb{Z}[i].
A new number system
The Gaussian integers are \mathbb{Z}[i] = \{\,a + bi : a, b \in \mathbb{Z}\,\} —
the lattice of points with integer coordinates in the complex plane. They add and multiply exactly
like complex numbers, and — crucially — the lattice is closed under both operations: add or multiply
two Gaussian integers and you land back on a lattice point.
(a+bi) + (c+di) = (a+c) + (b+d)i, \qquad (a+bi)(c+di) = (ac - bd) + (ad+bc)i.
The key measuring tool is the norm:
N(a + bi) = a^2 + b^2 = (a+bi)(a-bi),
which is just the squared distance from the origin. The norm is multiplicative,
N(zw) = N(z)N(w) — this is exactly Brahmagupta's identity from the
two-squares
page, now revealed as a statement about multiplying complex numbers. It's the single most useful
fact on this page: it turns questions about factoring Gaussian integers into questions about
factoring ordinary whole numbers, which we already know how to handle.
One more piece of bookkeeping: the units of \mathbb{Z}[i]
— the Gaussian integers with a multiplicative inverse inside the system — are exactly the four
elements of norm 1: \pm 1, \pm i. Multiplying
by a unit just rotates a point by a multiple of 90°, so
z and its four rotations z, iz, -z, -iz count
as "the same" factorisation — they're called associates, the Gaussian analogue of
how 3 and -3 are "the same" prime in
\mathbb{Z}.
Worked example: 2 stops being prime
In \mathbb{Z}, 2 is the archetypal prime. Watch
what happens in \mathbb{Z}[i]:
2 = (1+i)(1-i).
Check it directly: (1+i)(1-i) = 1 - i^2 = 1 - (-1) = 2. ✓
Neither factor is a unit — N(1+i) = 1^2+1^2 = 2 and
N(1-i) = 2, and neither equals 1 — so this is a
genuine factorisation. That means 2 is no longer
prime once you allow Gaussian-integer factors: it has split into two smaller pieces. Notice
the norms multiply correctly: N(1+i)\cdot N(1-i) = 2 \cdot 2 = 4 = N(2),
exactly as the multiplicative property promised.
Also notice 1-i and 1+i are associates:
1 - i = -i(1+i), so really there is only one new prime factor
here, appearing twice: 2 = -i(1+i)^2. This special, repeated-factor
behaviour has a name — 2 is said to ramify. It is the one
exception among all primes; every other prime either splits cleanly into two different
factors or doesn't split at all.
Worked example: 5 splits, 7 does not
Now try 5 and 7, the next two odd primes.
5 = (2+i)(2-i).
Check: (2+i)(2-i) = 4 - i^2 = 4+1 = 5. ✓ Both factors have norm
N(2\pm i) = 4+1 = 5, which is not 1, so this is
a real factorisation and 5 splits into two genuinely
different Gaussian primes, 2+i and its "conjugate partner"
2-i (they are not associates of each other — rotating
2+i by 90° gives -1+2i,
not 2-i).
Now try the same trick on 7. Suppose
7 = \alpha\beta with neither factor a unit. Taking norms,
N(\alpha)N(\beta) = N(7) = 49. Since neither factor is a unit, neither
norm is 1, so the only option is
N(\alpha) = N(\beta) = 7. That requires integers
a, b with a^2 + b^2 = 7 — but check every
case: 0,1,4 are the only squares below 7, and
no two of them add to 7. There is no Gaussian integer of
norm 7, so the factorisation is impossible.
7 stays exactly as prime in \mathbb{Z}[i] as it
was in \mathbb{Z} — mathematicians say it stays inert.
Look closely at what separated the two cases: 5 \equiv 1 \pmod 4 while
7 \equiv 3 \pmod 4. That single residue — is a prime one more or three
more than a multiple of four — turns out to decide the whole story, every time, for every odd prime.
The norm as a primality detector
The norm doesn't just verify factorisations after the fact — it can predict them. Two rules
fall straight out of multiplicativity:
-
If N(\pi) is itself an ordinary prime number, then
\pi must be a Gaussian prime. (If it factored as
\pi = \alpha\beta with neither a unit, the norms
N(\alpha)N(\beta) = N(\pi) would factor the prime
N(\pi) non-trivially — impossible.)
-
To test whether an ordinary prime p splits, you only need to ask: does
a^2 + b^2 = p have a solution in integers? If yes, p
splits as p = (a+bi)(a-bi); if no, it stays inert.
For example, N(1+2i) = 1+4 = 5, a prime, so 1+2i
is automatically a Gaussian prime — no further checking needed. And
N(3+4i) = 9+16 = 25 = 5^2 is not itself prime, which is our first
clue that 3+4i might factor further; indeed
3+4i = (2+i)^2, built entirely from the prime above
5 that we already found.
You can check the norm mechanically for any candidate — a small script makes the pattern obvious:
the norm of every Gaussian prime above an inert rational prime is a perfect square
(N(7)=49=7^2), while a split prime's factors carry the prime itself as
their norm (N(2+i)=5, not a square).
function norm(a: number, b: number): number {
return a * a + b * b;
}
console.log("N(1+i) =", norm(1, 1));
console.log("N(2+i) =", norm(2, 1));
console.log("N(2-i) =", norm(2, -1));
console.log("N(3+4i) =", norm(3, 4));
console.log("N(7+0i) =", norm(7, 0));
Gaussian primes and unique factorisation
Put the three worked examples together and a clean, complete rule for every ordinary prime
p emerges:
-
A prime p \equiv 1 \pmod 4 splits:
p = \pi \bar\pi for some Gaussian prime \pi
(e.g. 5, 13, 17, \ldots).
-
A prime p \equiv 3 \pmod 4 stays inert — still prime
in \mathbb{Z}[i] (e.g. 3, 7, 11, \ldots).
-
The single prime 2 = -i(1+i)^2 ramifies — it is the
one exceptional case, sitting exactly at the boundary.
Crucially, none of this factoring freedom breaks the most important habit of the integers:
\mathbb{Z}[i] still enjoys
unique factorisation
— every Gaussian integer breaks into Gaussian primes in exactly one way (up to order and units). This
holds because \mathbb{Z}[i] is a Euclidean domain: you can
do long division with remainder using the norm to measure "size," so
Euclid's algorithm
carries over almost untouched. It is not automatic that enlarging a number system keeps unique
factorisation — it is a small miracle that this particular enlargement does.
The single trickiest idea on this page: primality is relative to which number system you're
standing in. It feels wrong at first — surely a prime number is just prime, full
stop? But "prime" really means "has no factors other than units and itself," and that depends
entirely on what counts as a legal factor.
2 is prime in \mathbb{Z} because no integer
divides it except \pm 1, \pm 2. But once \mathbb{Z}[i]
is on the table, 1+i becomes a legal factor, and
2 = -i(1+i)^2 is no longer prime. Nothing about 2
itself changed — the rulebook changed. The same is true of 5, 13, 17
and every prime congruent to 1 \pmod 4: perfectly prime in one world,
openly composite in the next. Only the primes congruent to 3 \pmod 4
(like 3, 7, 11, 19) survive the move completely unscathed. Keep asking
"prime where?" and this whole page stays easy; forget to ask it and every statement below
looks self-contradictory.
Before Gauss, the fact that a prime is a sum of two squares exactly when it's
1 \pmod 4 looked like a strange coincidence, and the classical proofs
(Fermat's infinite descent, or Euler's decades-long struggle with it) are real fights, full of clever
but unmotivated tricks. The Gaussian integers turn it into one clean, almost mechanical observation.
A prime p is a sum of two squares, p = a^2+b^2,
exactly when p = (a+bi)(a-bi) — that is, exactly when
p splits in \mathbb{Z}[i].
Unique factorisation then tells us splitting happens precisely for
p \equiv 1 \pmod 4 (plus the special case p=2 = 1^2+1^2).
So the two-squares theorem isn't some ad-hoc fact bolted onto the integers — it's the shadow, cast
down into \mathbb{Z}, of ordinary prime factorisation happening one number
system over. This is the whole point of adjoining new numbers: hard facts about the world you started
in can become easy facts about the bigger world you moved to.
The bigger idea
Gauss's move — adjoin a new algebraic number and study its arithmetic — is the template for all of
algebraic number theory.
Sometimes unique factorisation survives the jump, exactly as it did here for
i = \sqrt{-1}. Sometimes it spectacularly fails — adjoin
\sqrt{-5} instead, and
6 = 2\cdot 3 = (1+\sqrt{-5})(1-\sqrt{-5}) gives two genuinely different
factorisations into irreducibles. Rescuing a substitute for unique factorisation when it breaks — via
ideals —
is what the final stage of this course is about.