The Polymathic Engineer

The Polymathic Engineer

The Anatomy of an IPv4 Address (Part I)

How an IPv4 address is built, what a subnet mask does, and how a device determines the network it belongs to.

Franco Fernando's avatar
Franco Fernando
Jul 25, 2026
∙ Paid

Hi Friends,

Welcome to the 183rd issue of the Polymathic Engineer newsletter. This week, we are going to start a new series of articles on the Internet Protocol (IP) and addressing.

IP is the protocol that moves packets from a source to their final destination, whether the two devices are on the same network or on opposite sides of the world. To arrive there, every packet needs an address, and understanding how those addresses work is the same as understanding how the network layer works.

In this first part, we concentrate on the IPv4 address itself: how it is structured, what a subnet mask does, and how a device can use both to figure out which network it belongs to.

The outline is as follows:

  • IPv4 address structure

  • Subnet masks

  • Finding the network address

  • Valid and invalid subnet masks

  • Network, broadcast, and host addresses

  • Types of destination addresses

  • What exactly is a subnet?

  • How devices communicate


Project-based learning is the best way to develop technical skills. CodeCrafters is an excellent platform for tackling exciting projects, such as building your own Redis, Kafka, a DNS server, SQLite, an HTTP server, or Git from scratch using your favorite programming language. Now you can also try to build your own Claude Code (for free, still in beta).

Sign up and become a better software engineer.


IPv4 Address Structure

We write an IPv4 address in dotted-decimal notation, such as 192.168.1.100. But that is just for our convenience. Under the hood, an IPv4 address is really a 32-bit number, which gives us about 4.29 billion possible addresses in total.

To make those 32 bits readable, we divide them into four 8-bit sections called octets. Then we convert each octet into its decimal value and separate them with dots. That is where the dotted decimal notation comes from. Since each octet is 8 bits, its value can go from 0 to 255, so an IPv4 address ranges from 0.0.0.0 all the way up to 255.255.255.255.

For example, the address 193.32.216.9 looks like this in binary:

11000001 00100000 11011000 00001001

Every IPv4 address has two parts: a network portion and a host portion. The network portion says which network the address belongs to, and the host portion identifies a specific device on that network. We’ll spend most of this article on the line separating these two parts, because that’s where most of the confusion lies.

One important detail before we move on. An IP address is not really tied to a device, but to an interface, the boundary between a device and the link that connects it to the network. A regular host normally has just one link, so it has a single interface and a single IP address. A router is different: its whole job is to receive a packet on one link and forward it on another, so it has several interfaces, one per link. That means that a router has several IP addresses, one for each interface.

Subnet Mask

We just said that an IPv4 address has a network portion and a host portion. However, the address by itself doesn’t tell us where one ends and the other begins. That is the job of the subnet mask, also known as the prefix length. It marks the line between the network and the host portions.

A subnet mask is also 32 bits long, and it follows a simple rule: a group of 1s followed by a group of 0s, with no mixing. The 1s line up with the network part of the address, and the 0s line up with the host part. So if a mask starts with 16 ones, the first 16 bits of the address are the network, and the remaining 16 bits are the host.

You can write a subnet mask in two ways. The first is dotted-decimal notation, exactly like an IPv4 address. For example, 255.255.0.0 is a mask with 16 ones followed by 16 zeros. The second is slash notation, which just gives the number of 1 bits in the mask. That same mask becomes /16, as in 172.18.0.0/16.

Slash notation is more widespread these days, largely because it is shorter and harder to get wrong. We’ll see where it actually comes from in Part II, when we look at how addresses are handed out across the Internet. For now, treat the slash as a shorthand for how many bits belong to the network.

Finding the Network Address

So we have an address and a mask. How does a device actually combine them to find the network it belongs to? The operation it performs is a bitwise AND between the host address and the subnet mask.

The rule for AND is simple: if both bits are 1, then the output is 1; in all other cases, the output is 0. We line up the two 32-bit values and use that rule on each bit.

Let’s work through an example. Suppose a host has the address 192.168.1.100 and the mask 255.255.255.0. In binary, they look like this:

192.168.1.100   11000000 10101000 00000001 01100100
255.255.255.0   11111111 11111111 11111111 00000000
AND result      11000000 10101000 00000001 00000000

This post is for paid subscribers

Already a paid subscriber? Sign in
© 2026 Franco Fernando · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture