We can think differently about networks and subnets using modular arithmetic & ring theory. Should we? Probably not.
What if networks are just rings? ​
IP addresses look like boring dotted decimals: 192.168.1.1
, 10.0.0.42
, 8.8.8.8
. But under the hood, networking is pure binary. And binary means math. And math means we can do cursed stuff.
In fact:
The space of IPv4 addresses is just the commutative residue class ring of integers mod
NOW, is that useful?
The answer might shock you...
(it's "no")
IP addresses as a ring ​
- Each IPv4 address = an element of
. - Addition = add two IPs, wrap around at
. - Multiplication = defined mod
as well (not used in networking, but the ring structure exists).
So 0.0.0.0
= 0, 255.255.255.255
= 192.168.0.1
is just 3232235521
in
Subnets/Masks as ideals ​
CIDR blocks like 192.168.0.0/24
are usually taught as "keep the first 24 bits fixed, vary the last 8."
But in ring language:
That is: a coset of the ideal
/24
→ cosets mod= groups of 256 consecutive addresses. /16
→ cosets mod= groups of 65,536. /32
→ cosets mod= just one address.
So...
Every subnet is just congruence classes in the ring.
Notation ​
Instead of 192.168.0.0/24
, we could write:
Meaning: all addresses congruent to 192.168.0.0
modulo 256.
Clean, right? Hmm... Well, not really.
But this does scale for IPv6 (128 bits), it could be nice to write:
instead of a wall of colons and hex digits with /64
.
It could be much simpler to describe "all addresses congruent mod
Some interesting connections ​
If IPv4 is
Partitioning:
Ideals inpartition the ring into cosets. Subnets partition address space into networks. Ideals = subnets, Cosets = host groups, Lattice of ideals = the hierarchy of subnetting. Local ring:
has a unique maximal ideal . In networking terms, "everything breaks down into powers of 2". Exactly how subnetting works. Zero divisors:
Not every element has a multiplicative inverse (becauseisn't prime). Networking analogy (not exact, but similar): some addresses don't behave like regular hosts (network and broadcast addresses "collapse" the same way). Addition wraps around:
Just like incrementing255.255.255.255
brings you back to0.0.0.0
.Uniform notation:
a mod 2^k
instead of dotted-decimal +/n
.Additive identity (0):
In the ring,is the neutral element. In networking, that's the all-zero address ( 0.0.0.0
or::
). It plays a "special" role: the unspecified address or "this host" in routing.Prime ideals:
There are no prime ideals inbeyond . That reflects the rigid structure of subnetting: everything reduces to powers of two. No alternative partition sizes exist (you can't subnet in blocks of 3 or 5). This is why networks always split cleanly into halves, quarters, eighths... never thirds. Polynomials over the ring:
Consider. You can think of this as "networks with an extra dimension." For example, addresses + time, or addresses + port numbers. In fact, transport protocols already do something like this: a socket is IP × port → essentially a polynomial ring structure on top of the base ring. Here, IP × port behaves like adding another dimension.
Ring homomorphisms ​
From IPv6 to IPv4:
This is exactly what "IPv4-mapped IPv6 addresses" do (::ffff:192.168.0.1
). It's a homomorphism that forgets 96 high-order bits.
From subnets to smaller subnets: restricting a coset modulo
Take IPv6 address space
projects every IPv6 address onto its subnet prefix (/64
). This maps the 128-bit space onto the 64-bit "network" space. It's exactly what routers care about: the higher-order bits decide the routing table, the lower-order bits are thrown away. That's algebra and networking aligning perfectly.
Chinese Remainder Theorem: ​
Normally, the CRT lets you split
is the prime factorization of
But here,
Lattice of ideals ↔ subnet hierarchy ​
In commutative algebra:
The set of ideals of a ring, ordered by inclusion, forms a lattice (a partially ordered set where any two have a unique meet and join).
In
, the ideals are exactly for . They're nested:
In networking:
/0
(the whole internet) contains/1
networks./1
contains/2
./2
contains/3
.- ... all the way down to
/32
(a single host).
That's exactly the same chain structure as the ideals. Bigger subnet (smaller prefix length) = bigger ideal. Smaller subnet (longer prefix length) = smaller ideal.
So:
- In algebra: ideals
form a descending chain. - In networking: subnets
/k
form a descending chain of refinements.
Well
That's not just an analogy. It's literally the same lattice structure.
TL;DR: In other words ​
- IPv4 =
. - A
/n
subnet = a coset of the ideal- Ideals = subnets.
- Cosets = host groups.
- Lattice of ideals = the hierarchy of subnetting.
- Quotients = collapsing hosts into a network.
- Homomorphisms = projection from big address spaces to smaller, just like prefix matching.
- CRT doesn't add extra structure here (because powers of 2), which explains why IP networks are powers-of-two only.
So IMO Networking is number theory with better marketing.