IP Addressing (Layer 3)
Vendor-neutral Layer 3 background - IP addressing, classes, CIDR, subnet masks, and host math. This is the conceptual companion to the interactive Subnetting & CIDR explorer.
Layer 3 in one line
Layer 3 (the network layer) is where IP addressing and routing live: it gets a packet from one host to another across networks, using the IP address as the destination. Layers below it (2/1) move frames on a single link; Layer 3 stitches links into an internet.
An IPv4 address
A 32-bit number written as four dotted decimal octets (10.240.0.5), each 0-255. Every address splits into a network part (which network) and a host part (which machine on it). The split point is defined by the subnet mask.
Classful addressing (the old way)
Originally the split was fixed by class, determined by the leading bits / first octet:
| Class | First octet | Default mask | Hosts per network | Purpose |
|---|---|---|---|---|
| A | 0-127 | /8 (255.0.0.0) | ~16 million | Very large networks |
| B | 128-191 | /16 (255.255.0.0) | ~65,000 | Medium networks |
| C | 192-223 | /24 (255.255.255.0) | 254 | Small networks |
| D | 224-239 | - | - | Multicast |
| E | 240-255 | - | - | Experimental / reserved |
Fixed classes waste addresses (a network needing 300 hosts had to take a whole Class B of 65,000). CIDR replaced this.
CIDR (the modern way)
CIDR = Classless Inter-Domain Routing. It drops fixed class boundaries and lets the network/host split fall at any bit, written as network/prefix:
10.0.0.0/24- the/24prefix means the first 24 bits are the network; the remaining32 - 24 = 8bits address hosts.
A smaller prefix number = more host bits = bigger range.
Subnet masks and host math
The subnet mask is just the prefix drawn as an address: the network bits are 1, the host bits are 0.
| Prefix | Subnet mask | Host bits | Total addresses |
|---|---|---|---|
/24 | 255.255.255.0 | 8 | 2⁸ = 256 |
/20 | 255.255.240.0 | 12 | 2¹² = 4,096 |
/16 | 255.255.0.0 | 16 | 2¹⁶ = 65,536 |
/8 | 255.0.0.0 | 24 | 2²⁴ = 16,777,216 |
Total addresses = 2^(32 − prefix)
Usable hosts = total − 2 - the network address (all host bits 0) and the broadcast address (all host bits 1) are not assignable.
So a /24 has 256 total and 254 usable. (GCP reserves 4 instead of 2 - see IP addresses.)
Worked example: sizing a /26 for a team
An office needs at least 50 usable host addresses. Check whether 10.0.1.0/26
works:
- Prefix is
/26, so host bits =32 - 26 = 6. - Total addresses =
2^6 = 64. - Usable hosts =
64 - 2 = 62(subtract the network address10.0.1.0and the broadcast address10.0.1.63). 62 ≥ 50, so/26fits, with 12 addresses to spare for future growth.
If the team instead needed 65 hosts, /26 (62 usable) would be one address
short - the next size up, /25, gives 2^7 - 2 = 126 usable hosts.
The total - 2 formula assumes there is a dedicated network address and a
dedicated broadcast address to subtract - true for any subnet with 2 or more
host bits. It breaks down at the edges: a /32 has zero host bits, so it is
a single address with no network/broadcast split at all (used to describe
one specific host, e.g. a loopback or a route to one machine). A /31 has
exactly one host bit, giving only two addresses total - and RFC 3021 defines
both of them as usable host addresses on a point-to-point link (no
network/broadcast reservation), so a /31 yields 2 usable hosts, not
2 - 2 = 0. Applying the generic formula to /31 or /32 without knowing
this exception is a classic off-by-one mistake when sizing point-to-point
WAN links or loopback routes.
Public vs private addresses
Not routable on the public internet; reused freely inside private networks and cloud VPCs:
- 10.0.0.0/8
- 172.16.0.0/12
- 192.168.0.0/16
Everything else is public (globally routable, must be allocated to you).
/16 is bigger than /24. The number counts network bits - fewer network bits leaves more host bits, so a smaller number is a larger range.