Sub topic 12
Summarizing routes
Route summarization (also called supernetting) replaces several contiguous routes with one shorter-prefix route. Routing tables get smaller, and updates between routers shrink. This chapter assumes you can find a block's size and network address from a prefix length, as covered in the earlier chapters on block size and subnet boundaries.
The idea
Suppose a router must tell its neighbor about four networks: 192.168.0.0/24 through 192.168.3.0/24. The neighbor can store four routes, or it can store one route that covers all four. The single route works if the four networks together fill exactly one aligned block.
The manual method
- Write the third octet of each network in binary (the first two octets are identical).
- Find the leftmost bit position where the addresses differ. Every bit before it is shared.
- Count the shared bits from the start of the address. That count is the summary prefix length.
- Set all bits after the shared bits to 0 to get the summary network address.
For the four networks above, the third octet values are 0, 1, 2, and 3:
| Network | Third octet (binary) |
|---|---|
| 192.168.0.0/24 | 00000000 |
| 192.168.1.0/24 | 00000001 |
| 192.168.2.0/24 | 00000010 |
| 192.168.3.0/24 | 00000011 |
The first six bits of the third octet match. The first two octets give 16 shared bits, so the summary prefix is 16 + 6 = 22. The summary is 192.168.0.0/22, which covers 1,024 addresses (four blocks of 256).
Two conditions for an exact summary
A summary is exact only when both conditions hold:
- The count of networks is a power of two (2, 4, 8, and so on).
- The first network's address is a multiple of the combined block size.
The combined block here is 4 × 256 = 1,024, which is 4 in the third octet. The first network starts at third-octet value 0, a multiple of 4, so the block is aligned.
Now take 192.168.1.0/24 through 192.168.4.0/24. That is still four networks, but the first starts at 1, which is not a multiple of 4. No single prefix covers exactly these four. The shortest prefix that contains them is 192.168.0.0/21, which also covers 192.168.0.0/24 and 192.168.5.0/24 through 192.168.7.0/24. Those extra networks may not belong to you.
Splitting an awkward set
When the set does not align, summarize in groups. For 192.168.1.0/24 through 192.168.4.0/24:
- 192.168.1.0/24 stays alone (it is aligned at size 1).
- 192.168.2.0/23 covers 192.168.2.0/24 and 192.168.3.0/24 (start 2 is a multiple of 2).
- 192.168.4.0/24 stays alone.
That gives three routes instead of four. It is a smaller saving, but it is exact.
Checking with Python
The ipaddress.collapse_addresses function does this merging for you:
import ipaddress
blocks = [
ipaddress.ip_network("192.168.0.0/24"),
ipaddress.ip_network("192.168.1.0/24"),
ipaddress.ip_network("192.168.2.0/24"),
ipaddress.ip_network("192.168.3.0/24"),
]
print(list(ipaddress.collapse_addresses(blocks)))
# [IPv4Network('192.168.0.0/22')]
gap = [ipaddress.ip_network(f"192.168.{n}.0/24") for n in (1, 2, 3, 4)]
print(list(ipaddress.collapse_addresses(gap)))
# [IPv4Network('192.168.1.0/24'), IPv4Network('192.168.2.0/23'), IPv4Network('192.168.4.0/24')]The second call returns the same three-route split worked out by hand above. The function never produces a summary that covers addresses outside the inputs.
Summaries and route selection
A summary route sits in the routing table next to more specific routes. When a packet matches several of them, the router chooses the one with the longest prefix. The next chapter covers that rule. It is what lets a router hold a broad summary and still send traffic for one specific subnet somewhere else.
Exercise
A router learns 10.4.8.0/24, 10.4.9.0/24, 10.4.10.0/24, and 10.4.11.0/24. Can they be summarized exactly? If so, give the summary route.
Show answer
Yes. The third-octet values 8, 9, 10, 11 are four consecutive values, and 8 is a multiple of 4. In binary, 8 to 11 is 000010xx, so six bits of the third octet are shared. The prefix is 16 + 6 = 22. The summary is 10.4.8.0/22.
Exercise
Can 172.16.2.0/24 through 172.16.5.0/24 be summarized into one exact route? If not, what is the smallest exact set of routes?
Show answer
No. There are four networks, but the first starts at third-octet value 2, which is not a multiple of 4. The exact set is 172.16.2.0/23 (covering 2 and 3) and 172.16.4.0/23 (covering 4 and 5), which is two routes.