LinuxXIX · Networking FoundationsIPv4
IPv4 addressing, subnetting, and CIDR
What you'll learn
- Read an IPv4 address and its prefix length
- Calculate the network, broadcast, and usable host ranges
- Choose a subnet size for a production use case
- Recognise the private address ranges defined by RFC 1918
Prerequisites
Verified against Ubuntu 24.04 LTS · Debian 12 (Bookworm) · RHEL 9.x · Rocky Linux 9.x · AlmaLinux 9.x · Linux kernel 6.1 LTS / 6.6 LTS · systemd 255+ · OpenSSH 8.7p1 (RHEL 9) / 9.6p1 (Ubuntu 24.04) · nftables 1.0.x · chrony 4.x · Pacemaker 2.1.x · Corosync 3.1.x · 2026-08-09
IPv4 is still the dominant layer-3 protocol in production. Its address space is small (about 4.3 billion) and nearly exhausted, but every sysadmin must understand its structure to configure hosts, design subnets, and read firewall rules.
Address format
An IPv4 address is 32 bits, written as four decimal octets:
10.0.0.5
192.168.1.100
203.0.113.42
The leading bits determine the network portion; the trailing bits identify the host. A prefix length (CIDR notation) tells you where the split is.
| Prefix | Meaning | Hosts |
|---|---|---|
| /32 | Single host | 1 |
| /30 | Point-to-point link | 2 usable |
| /29 | Tiny subnet | 6 usable |
| /28 | Small subnet | 14 usable |
| /24 | Classic class C | 254 usable |
| /16 | Class B | 65,534 usable |
| /8 | Class A | 16,777,214 usable |
Two addresses per subnet are always reserved: the network address (all host bits zero) and the broadcast address (all host bits one).
Calculate a subnet
ipcalc 10.10.0.0/24
ipcalc 10.10.0.0/26
ipcalc 10.10.0.50/26 -n
ipcalc is part of the ipcalc package on Debian-derived
distros and is in initscripts on RHEL. The -n flag shows
the network range.
Worked example: 10.10.0.0/26
The /26 means 26 bits of network and 6 bits of host. 2^6 = 64 addresses total, 62 usable.
| Item | Value |
|---|---|
| Network | 10.10.0.0 |
| First usable | 10.10.0.1 |
| Last usable | 10.10.0.62 |
| Broadcast | 10.10.0.63 |
| Total addresses | 64 |
| Usable hosts | 62 |
Always leave room for the gateway, monitoring agents, and future growth. A /30 is correct for a point-to-point link but not for a server subnet.
Private address ranges (RFC 1918)
Three ranges are reserved for private use and not routable on the public internet:
| Range | Prefix | Use |
|---|---|---|
| 10.0.0.0 - 10.255.255.255 | 10.0.0.0/8 | Large private networks |
| 172.16.0.0 - 172.31.255.255 | 172.16.0.0/12 | Medium private networks |
| 192.168.0.0 - 192.168.255.255 | 192.168.0.0/16 | Home and small office |
There are also the CGNAT range (100.64.0.0/10) and the link-local range (169.254.0.0/16) used by IPv4 zeroconf.
Subnet design discipline
When you design a subnet:
- Estimate the host count including monitoring agents, load balancers, and gateway IPs.
- Round up to the nearest CIDR that fits with room to spare. A 50-host subnet should be a /25 (126 usable), not a /26.
- Document the allocation in an IPAM tool or spreadsheet. Undocumented networks become unmanageable within a year.
- Reserve the first 10 and last 10 addresses for network infrastructure (gateway, monitoring, future expansion).
ip -4 addr show
ip -4 route
ip -4 neigh show
The -4 flag forces IPv4 output. Without it, dual-stack hosts
show both IPv4 and IPv6, which is usually what you want but
sometimes gets in the way of a quick check.
Knowledge check
Knowledge check · 3 questions
Q1. How many usable host addresses does a /27 subnet have?
Q2. Which of these is a private (RFC 1918) address?
Q3. Which of the following statements about IPv4 subnetting are correct? Select all that apply.
Passing score: 75%. Answers are checked in this browser.