Sub topic 7
Network address, broadcast address, and usable hosts
This chapter assumes you can convert between binary and decimal, and that you know a prefix length such as /26 gives the number of network bits. You will learn how to find the three key values of any subnet: the network address, the broadcast address, and the range of usable host addresses.
The two reserved addresses
Every subnet is a contiguous block of addresses. The host bits (the bits not covered by the prefix) take every value from all zeros to all ones. The two ends of that range have special roles:
- The network address has all host bits set to 0. It names the subnet itself, as in a routing table entry. You do not assign it to a device.
- The broadcast address has all host bits set to 1. A packet sent to it is delivered to every host in the subnet. You do not assign it to a device either.
The addresses between them are the usable host addresses.
Counting addresses
If a prefix has h host bits, where h = 32 − prefix length, then:
- Total addresses = 2^h
- Usable hosts = 2^h − 2
The "− 2" removes the network and broadcast addresses.
| Prefix | Host bits | Total addresses | Usable hosts |
|---|---|---|---|
| /24 | 8 | 256 | 254 |
| /26 | 6 | 64 | 62 |
| /27 | 5 | 32 | 30 |
| /28 | 4 | 16 | 14 |
| /29 | 3 | 8 | 6 |
| /30 | 2 | 4 | 2 |
The /31 and /32 prefixes break this formula. A later chapter covers them.
Worked example: 192.168.10.77/26
- A /26 leaves 6 host bits, so the block holds 2^6 = 64 addresses.
- The change happens in the fourth octet, so the subnets start at multiples of 64: 0, 64, 128, 192.
- The address .77 lies between 64 and 127, so the network address is 192.168.10.64.
- The broadcast address is the last address in the block: 64 + 64 − 1 = 127, so 192.168.10.127.
- The usable range is 192.168.10.65 through 192.168.10.126, which is 62 hosts.
You can check this with Python:
import ipaddress
iface = ipaddress.ip_interface("192.168.10.77/26")
net = iface.network
print(net.network_address) # 192.168.10.64
print(net.broadcast_address) # 192.168.10.127
hosts = list(net.hosts())
print(hosts[0], hosts[-1], len(hosts)) # 192.168.10.65 192.168.10.126 62ip_interface keeps the host address and its prefix together. Its .network attribute applies the mask for you.
Common errors
- Counting 64 usable hosts in a /26. Subtract 2 from the total.
- Using the wrong boundary. The network address must be a multiple of the block size in the octet where the prefix ends. 192.168.10.77/26 cannot start at .77 or .60.
- Assigning the network or broadcast address to a device. The host would misbehave or be unreachable. The only exceptions are the special prefixes covered later.
- Giving the broadcast address as the next subnet's start. The broadcast address is the last address of the block. The next subnet starts one address higher.
Why this matters
When you size a subnet, you work backward from the number of hosts. For 50 hosts you need at least 52 addresses, so 6 host bits give 64 addresses and a /26. Block size arithmetic, covered next, builds on these three values.
Exercise
A host has the address 10.1.1.130/27. Give the network address, broadcast address, usable host range, and number of usable hosts.
Show answer
A /27 has 5 host bits, so the block size is 32. Subnets in the fourth octet start at 0, 32, 64, 96, 128, 160, and so on. The address .130 lies in the block starting at 128. The network address is 10.1.1.128 and the broadcast address is 10.1.1.159 (160 − 1). The usable range is 10.1.1.129 to 10.1.1.158, which is 2^5 − 2 = 30 hosts.