Address structure
An IPv4 address is a 32-bit number written as four decimal bytes separated by dots: 192.168.1.10.
That is simply 0xC0A8010A, or 11000000.10101000.00000001.00001010 in binary.
The network prefix (CIDR) specifies how many left-hand bits belong to the network portion.
192.168.1.0/24 means the first 24 bits (192.168.1) are the same for every address in
that network; the remaining 8 bits form the host range.
How many hosts fit in /N
| prefix | subnet mask | host range | examples |
|---|---|---|---|
| /8 | 255.0.0.0 | 16 777 214 | 10.0.0.0/8 (RFC1918) |
| /16 | 255.255.0.0 | 65 534 | 172.16.0.0/16 |
| /24 | 255.255.255.0 | 254 | 192.168.1.0/24 (home network) |
| /29 | 255.255.255.248 | 6 | small point-to-point for 4 devices |
| /30 | 255.255.255.252 | 2 | classic p2p link |
| /31 | 255.255.255.254 | 2 (RFC 3021) | optimized p2p, no reserved addresses |
| /32 | 255.255.255.255 | 1 | single address (loopback, host route) |
The N-2 subtraction applies because the network address (all zeros in the host part) and the broadcast address (all ones) are normally reserved.
Reserved ranges (RFC 1918 and others)
| range | purpose |
|---|---|
10.0.0.0/8 | private networks (large) |
172.16.0.0/12 | private (Docker default) |
192.168.0.0/16 | private (home routers) |
127.0.0.0/8 | loopback (local interfaces) |
169.254.0.0/16 | link-local (assigned when DHCP gives no address) |
224.0.0.0/4 | multicast |
0.0.0.0/0 | "any address", used as the default route |
Addresses from private ranges are not routed to the internet, so reaching the outside requires nat.
Viewing addresses on a machine
ip -4 addr # all IPv4 addresses on all interfaces
ip -4 -br addr # compact view: name/state/IP/prefix
hostname -I # all host IP addresses (no mask)
An address can have one of three scopes:
- scope global - reachable publicly (or privately via NAT)
- scope host - loopback only (for example 127.0.0.1)
- scope link - reachable only within one broadcast domain