IP Addresses Explained: IPv4, IPv6 and Subnets
An IP address identifies a host on a network. Learn IPv4, IPv6, the subnet mask, CIDR notation, and the private ranges.
By Velloreth
What an address is
A numeric label that identifies a host on a network.
It has two parts:
- The network part, which identifies the subnet
- The host part, which identifies the device
The subnet mask says where the split is.
IPv4
32 bits, written as four octets.
192.168.1.10
Each octet is 0 to 255, so the space is about 4.3 billion addresses.
The space is exhausted, which is why NAT and IPv6 exist.
IPv6
128 bits, written as eight groups of hexadecimal digits.
2001:0db8:85a3:0000:0000:8a2e:0370:7334
The shorthand removes a leading zero and collapses one run of zeros.
2001:db8:85a3::8a2e:370:7334
The space is effectively unlimited.
The benefits:
- No NAT
- A simpler header
- Stateless autoconfiguration
- A built-in checksum removal
The subnet mask
A value that says which bits are the network part.
| Mask | CIDR | Addresses |
|---|---|---|
| 255.255.255.0 | /24 | 256 |
| 255.255.0.0 | /16 | 65,536 |
| 255.0.0.0 | /8 | 16,777,216 |
| 255.255.255.128 | /25 | 128 |
| 255.255.255.192 | /26 | 64 |
A /24 means the first 24 bits are the network and the last 8 are the host.
Two addresses are reserved in each subnet: the network address and the broadcast address.
So a /24 holds 254 usable hosts, not 256.
CIDR notation
An address and a prefix length.
192.168.1.0/24
The number after the slash is the count of network bits.
It replaced the class-based system, which had only three sizes.
A subnet of any size is possible, which is the point.
The private ranges
| Range | CIDR | Use |
|---|---|---|
| 10.0.0.0 – 10.255.255.255 | 10.0.0.0/8 | a large private network |
| 172.16.0.0 – 172.31.255.255 | 172.16.0.0/12 | a medium private network |
| 192.168.0.0 – 192.168.255.255 | 192.168.0.0/16 | a home network |
| fc00::/7 | IPv6 private |
They are not routable on the public internet.
A router translates them to a public address with NAT.
The special addresses
| Address | Meaning |
|---|---|
| 127.0.0.1 | loopback, this machine |
| 0.0.0.0 | any interface, or an unspecified address |
| 169.254.0.0/16 | link-local, when DHCP fails |
| 255.255.255.255 | the local broadcast |
| ::1 | the IPv6 loopback |
A 169.254 address means the device did not get a DHCP lease.
NAT
Network Address Translation.
It rewrites the source address of an outgoing packet to the router’s public address.
It tracks the connection, so the reply can be routed back.
It is why a home network with many devices needs one public address.
It is a workaround for the IPv4 shortage, and it breaks an inbound connection unless a port is forwarded.
The tools
ip addr show # the local addresses
ip route # the routing table
ping 8.8.8.8 # reachability
dig example.com # the DNS resolution
traceroute example.com # the path
ss -tulpn # the listening ports
ip replaces ifconfig on a modern Linux.
Common mistakes
A /24 assumed to hold 256 hosts. Two are reserved.
A private address expected to be reachable. It is not routable.
A 169.254 address ignored. DHCP failed.
A subnet that overlaps. A routing conflict.
A hardcoded IP. It changes.
NAT assumed to be a firewall. It is not.
IPv6 disabled. A modern network needs it.
A /32 on a host. It is a single address.
A broadcast address assigned to a host. It is reserved.
No reverse DNS. A log is hard to read.
A quotable summary
An IP address identifies a host on a network, with a network part and a host part divided by the subnet mask. IPv4 is 32 bits and exhausted, IPv6 is 128 bits and effectively unlimited, and CIDR notation writes the prefix length as /24. The private ranges 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16 are not routable on the public internet, and NAT is the workaround that lets a home network share one public address.
Related reading
For the related topics, see dns-explained and how-cdns-actually-work. For the broader context, http-vs-https and ssh-and-keys-guide.