Skip to content

Beginner · IPv4 addressing · topic 14 of 57 · 35 min

Network, broadcast and usable host range

Explanation

In every subnet, the address with all host bits 0 is the network address and the one with all host bits 1 is the broadcast address. Everything in between is the usable host range, and there are 2^h − 2 usable hosts, where h is the number of host bits. The block size method (256 minus the interesting mask octet) lets you find all of this in seconds without writing binary.

The four answers every subnet question wants

Given an address and a mask, you usually need four things. The network address is the first address of the subnet, with all host bits set to 0; it names the subnet and is not given to a device. The broadcast address is the last address, with all host bits set to 1; a packet sent to it reaches every device in the subnet. The first usable host is the network address plus 1. The last usable host is the broadcast address minus 1. Routers usually take the first or the last usable address as the default gateway.

If there are h host bits, the subnet has 2^h addresses in total. Two of them (network and broadcast) cannot be given to devices, so there are 2^h − 2 usable hosts. A /24 has 8 host bits: 256 addresses, 254 usable.

Think of it like this: A subnet is like a row of houses in a colony. The first plot holds the colony name board (the network address) and the last plot holds the notice board that everyone reads (the broadcast address). Families can only live in the plots in between.

The block size method (magic number)

Converting everything to binary works, but it is slow. The block size method is what exam takers use.

  1. Write the mask in dotted decimal.
  2. Find the interesting octet: the one where the mask is not 255 and not 0.
  3. Block size = 256 minus the mask value in that octet. Subnets start at every multiple of the block size: 0, block, 2 × block, and so on.
  4. Network address: the largest multiple of the block size that is less than or equal to the address in the interesting octet. Octets to the right become 0.
  5. Broadcast: next multiple minus 1 in the interesting octet. Octets to the right become 255.
  6. First host = network + 1, last host = broadcast − 1, hosts = 2^h − 2.

Worked example 1: 192.168.10.77/27

Mask 255.255.255.224. The interesting octet is the fourth (224). Block size 256 − 224 = 32. Multiples: 0, 32, 64, 96. 77 falls between 64 and 95. Network 192.168.10.64, broadcast 192.168.10.95, first host 192.168.10.65, last host 192.168.10.94. Host bits 32 − 27 = 5, so 2^5 − 2 = 30 usable hosts.

Worked example 2: 172.16.45.200/20

Mask 255.255.240.0. The interesting octet is the third (240). Block size 16. Multiples: 0, 16, 32, 48. 45 falls between 32 and 47. Network 172.16.32.0 (the octet to the right becomes 0). Broadcast 172.16.47.255 (third octet 48 − 1 = 47, and the fourth becomes 255). First host 172.16.32.1, last host 172.16.47.254. Host bits 12, so 2^12 − 2 = 4,094 hosts.

Worked example 3: 10.1.2.3/9

Mask 255.128.0.0. The interesting octet is the second (128). Block size 128. Multiples: 0 and 128. 1 falls in 0 to 127. Network 10.0.0.0, broadcast 10.127.255.255, first host 10.0.0.1, last host 10.127.255.254. Host bits 23, so 2^23 − 2 = 8,388,606 hosts.

AddressNetworkBroadcastUsable rangeHosts
192.168.10.77/27192.168.10.64192.168.10.95.65 to .9430
172.16.45.200/20172.16.32.0172.16.47.255172.16.32.1 to 172.16.47.2544,094
10.1.2.3/910.0.0.010.127.255.25510.0.0.1 to 10.127.255.2548,388,606
192.168.1.130/30192.168.1.128192.168.1.131.129 to .1302

Special cases: /31 and /32

A /31 has only two addresses. RFC 3021 allows both to be used on a point-to-point link between two routers, with no network or broadcast address, which saves addresses. A /32 is a single address: it is used for loopback interfaces on routers and for host routes. The 2^h − 2 formula applies to /30 and shorter prefixes.

Doing it with bits in Python

python
import ipaddress

iface = ipaddress.ip_interface("172.16.45.200/20")
net = iface.network
print(net)                        # 172.16.32.0/20
print(net.broadcast_address)      # 172.16.47.255
print(net.num_addresses - 2)      # 4094
hosts = list(net.hosts())
print(hosts[0], hosts[-1])        # 172.16.32.1 172.16.47.254
ip_interface keeps the host address and its network together. net.hosts() lists usable addresses (fine for small subnets).

Under the hood it is just the AND from the last topic. Turn the address into one 32-bit number, AND it with the mask to get the network, and OR it with the inverted mask (the wildcard) to set all host bits to 1 for the broadcast.

Common mistakes

Careful: Thinking addresses ending in .0 or .255 are always invalid. In 192.168.0.0/23, the range is 192.168.0.0 to 192.168.1.255, so 192.168.0.255 and 192.168.1.0 are normal usable hosts. Only the first and last address of the whole subnet are special.
  • Using the block size in the wrong octet. For /20 the block of 16 is in the third octet, not the fourth.
  • Forgetting to set the octets to the right: they are 0 in the network address and 255 in the broadcast.
  • Forgetting the minus 2. A /27 has 32 addresses but only 30 usable hosts.

Need help?

Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.

Try:

Watch the lesson

Network, broadcast and usable host range · 1/8

Network · Broadcast First · Last · Hosts

Every subnet has four answers you must find quickly: the network address, the broadcast address, the first and last usable host, and the number of hosts.

Prefer a video by a teacher? Find free videos on “find network address broadcast address usable host range subnetting fast” on YouTube ↗

In real life: Planning CCTV cameras at a Flipkart-style warehouse

A warehouse in Bhiwandi gets a new camera network. The network team assigns 10.30.8.0/26 to the CCTV cameras. Before the installer arrives, the engineer works out the plan: network 10.30.8.0, gateway 10.30.8.1, cameras from 10.30.8.2 to 10.30.8.62, broadcast 10.30.8.63. That is 62 usable addresses, enough for 55 cameras, the recorder and the gateway with a few spare. The installer gets a printed list instead of guessing.

python
import ipaddress

net = ipaddress.ip_network("10.30.8.0/26")
print("gateway:", net.network_address + 1)
print("broadcast:", net.broadcast_address)
print("usable:", net.num_addresses - 2)
Shows gateway 10.30.8.1, broadcast 10.30.8.63 and usable 62.

Practice (0/4 done)

Task 1 · Code · Python

Write usable_hosts(prefix) that returns the number of usable host addresses for a prefix length: 2 to the power (32 − prefix), minus 2. Special cases: /31 returns 2 (point-to-point, RFC 3021) and /32 returns 1.

Task 2 · Code · Python

Without the ipaddress module, finish subnet_info(ip, prefix) for prefixes from /8 to /30. It must return a dict with "network", "broadcast", "first", "last" (all strings) and "hosts" (a number). The helpers to_int and to_ip are already written for you. Use bit arithmetic: mask = (0xFFFFFFFF << (32 - prefix)) & 0xFFFFFFFF, network = address & mask, broadcast = network | (~mask & 0xFFFFFFFF).

Task 3 · Code · Python

Now the easy way. Write describe(cidr) using ipaddress.ip_interface. It returns a tuple: (network with prefix as a string, broadcast address as a string, number of usable hosts). Example: describe("192.168.10.77/27") returns ("192.168.10.64/27", "192.168.10.95", 30).

Task 4 · Question

What is the broadcast address of 10.10.10.10/29?

Quick quiz

Question 1

1.How many usable hosts are in a /26?

Question 2

2.What is the network address of 192.168.5.130/25?

Question 3

3.What is the last usable host in 172.16.32.0/20?

Question 4

4.Is 192.168.0.255/23 a usable host address?

Question 5

5.Why can a /31 be used on a link between two routers?

Read more (free)

Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.

How many usable hosts are in a /26?

Answer: 62

32 − 26 = 6 host bits. 2^6 − 2 = 62.

What is the network address of 192.168.5.130/25?

Answer: 192.168.5.128

/25 has a block size of 128. 130 is in 128 to 255, so the network is 192.168.5.128.

What is the last usable host in 172.16.32.0/20?

Answer: 172.16.47.254

The block of 16 runs from 32 to 47 in the third octet. The broadcast is 172.16.47.255, so the last host is 172.16.47.254.

Is 192.168.0.255/23 a usable host address?

Answer: Yes, the subnet runs from 192.168.0.0 to 192.168.1.255

In a /23 the broadcast is 192.168.1.255. 192.168.0.255 is in the middle of the range, so it is a normal host.

Why can a /31 be used on a link between two routers?

Answer: RFC 3021 allows both of its two addresses to be hosts on point-to-point links

RFC 3021 defines /31 for point-to-point links: both addresses are usable, with no network or broadcast address.

Each subnet must hold 25 hosts. Which prefix wastes the fewest addresses?Related

Answer: /27

/27 gives 30 usable hosts. /28 gives only 14, and /26 wastes more.

From Subnetting a network into equal subnets

Where does Cisco IOS expect a wildcard mask instead of a subnet mask?Related

Answer: In access-list statements and the OSPF network command

Interfaces take subnet masks. ACLs and OSPF network statements take wildcard masks.

From Subnet masks, prefix length and wildcard masks

How many usable hosts are in a /28?Related

Answer: 14

2^(32−28) = 16 addresses, minus network and broadcast = 14.

From IP addresses, subnets and CIDR

Which of these is NOT an RFC 1918 private range?Related

Answer: 169.254.0.0/16

169.254.0.0/16 is the link-local (APIPA) range, not one of the three RFC 1918 private ranges.

From IPv4 address structure and special ranges

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

Next steps

  1. 1 more topic in “IPv4 addressing” before its exam: Validating addresses and checking the same subnet.
  2. Module 3 exam: IPv4 addressing · 13 questions · 20 min, without help. 5 topics of this module still to finish first.
  3. Then the next module, Subnetting practice and IPv6. 57 topics left in the course before the final exam.

← Previous: Subnet masks, prefix length and wildcard masks