An IPv4 address is a 32-bit number, written as four decimal numbers from 0 to 255 so people can say it out loud. That is the whole format. What makes addressing interesting is that the address is really two addresses joined together: part of it names the network, and the rest names a specific host on that network. The subnet mask is what says where the split falls.
The mask and CIDR notation
A subnet mask is 32 bits too, but it is always a run of 1s followed by a run of 0s — never mixed. The 1s mark network bits and the 0s mark host bits. Because the 1s are always contiguous, you only need to say how many there are, which is what CIDR notation does: /24 means 24 network bits, which is the mask 255.255.255.0.
| CIDR | Subnet mask | Host bits | Usable hosts |
|---|---|---|---|
| /24 | 255.255.255.0 | 8 | 254 |
| /25 | 255.255.255.128 | 7 | 126 |
| /26 | 255.255.255.192 | 6 | 62 |
| /27 | 255.255.255.224 | 5 | 30 |
| /28 | 255.255.255.240 | 4 | 14 |
| /29 | 255.255.255.248 | 3 | 6 |
| /30 | 255.255.255.252 | 2 | 2 |
Private addresses and NAT
IPv4 has about 4.3 billion addresses, which ran out. Three ranges are reserved as private: they can be reused inside any organization and are never routed on the public internet. Your home network almost certainly uses one of them right now.
- 10.0.0.0/8 — 10.0.0.0 to 10.255.255.255. Around 16.7 million addresses; used by large organizations.
- 172.16.0.0/12 — 172.16.0.0 to 172.31.255.255. Around 1 million addresses.
- 192.168.0.0/16 — 192.168.0.0 to 192.168.255.255. Around 65 000 addresses; the home-router default.
- 169.254.0.0/16 — APIPA. Not a configured private range but a symptom: a host assigns itself one of these when it cannot reach a DHCP server.
DHCP and static addressing
DHCP hands out addresses automatically. A client broadcasts a discovery, a server offers an address, the client requests it and the server acknowledges — DORA: Discover, Offer, Request, Acknowledge. The lease includes the address, the subnet mask, the default gateway and DNS server addresses, and it expires so that addresses return to the pool. Servers, printers and network equipment usually get static addresses or DHCP reservations instead, because other devices need to find them at a predictable address.
IPv6, briefly
IPv6 uses 128-bit addresses written as eight groups of four hex digits, for example 2001:0db8:0000:0000:0000:ff00:0042:8329. Runs of zeros can be shortened with a double colon, once per address, giving 2001:db8::ff00:42:8329. The address space is large enough that NAT becomes unnecessary and every device can hold a globally unique address. Adoption has been slow because NAT made IPv4 workable enough for long enough.