Skip to main content

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:

ClassFirst octetDefault maskHosts per networkPurpose
A0-127/8 (255.0.0.0)~16 millionVery large networks
B128-191/16 (255.255.0.0)~65,000Medium networks
C192-223/24 (255.255.255.0)254Small networks
D224-239--Multicast
E240-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 /24 prefix means the first 24 bits are the network; the remaining 32 - 24 = 8 bits 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.

PrefixSubnet maskHost bitsTotal addresses
/24255.255.255.082⁸ = 256
/20255.255.240.0122¹² = 4,096
/16255.255.0.0162¹⁶ = 65,536
/8255.0.0.0242²⁴ = 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:

  1. Prefix is /26, so host bits = 32 - 26 = 6.
  2. Total addresses = 2^6 = 64.
  3. Usable hosts = 64 - 2 = 62 (subtract the network address 10.0.1.0 and the broadcast address 10.0.1.63).
  4. 62 ≥ 50, so /26 fits, 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.

Off-by-one host counts around /31 and /32

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​

Private ranges (RFC 1918)

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).

Prefix direction trips people up

/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.