Sub topic 12
Summarizing routes
Route summarization (also called supernetting or route aggregation) replaces several contiguous routes with one shorter-prefix route that covers all of them. This chapter assumes you can convert between binary and decimal, read CIDR prefixes, and compute block sizes and network addresses from the earlier chapters.
Why summarize
A router keeps one entry per destination prefix. Without summarization, a site that owns 200 subnets advertises 200 routes to its upstream neighbors. With summarization it advertises one. Smaller routing tables use less memory, speed up lookups, and hide internal changes. If one internal subnet goes down, the summary stays up and neighbors never see the change.
Summarization is the reverse of subnetting. Subnetting lengthens the prefix to split a block into pieces. Summarization shortens the prefix to join the pieces back together.
The working model: find the shared leading bits
A summary route is the longest prefix that all the routes share. Follow these steps:
- Write the networks in binary.
- Find the number of leading bits that are identical in every network.
- That count is the summary prefix length.
- Set every bit after the shared bits to 0 to get the summary network address.
Take four networks: 192.168.0.0/24, 192.168.1.0/24, 192.168.2.0/24, and 192.168.3.0/24. The first two octets are identical in all four, which is 16 bits. Only the third octet varies:
| Network | Third octet (binary) |
|---|---|
| 192.168.0.0/24 | 000000**00** |
| 192.168.1.0/24 | 000000**01** |
| 192.168.2.0/24 | 000000**10** |
| 192.168.3.0/24 | 000000**11** |
The first 6 bits of the third octet are the same in every row. The summary prefix is 16 + 6 = 22, and the summary is 192.168.0.0/22. A /22 has 10 host bits, so it holds 1024 addresses. Four /24 blocks of 256 addresses also total 1024, so the summary matches the original blocks exactly.
The block-size shortcut
You can skip the binary by using block size arithmetic. A summary of prefix length P is a block, and a block must start on a multiple of its own size. The four /24 networks above span 4 values of the third octet, so the block size in that octet is 4. The first network starts at 0, which is a multiple of 4, so the summary is valid.
To check a candidate, apply two tests:
- The number of networks must be a power of two. The blocks being joined must fill the summary exactly.
- The first network address must be a multiple of the summary's block size.
Take 192.168.4.0/24 through 192.168.7.0/24. The count is 4, and 4 is a multiple of 4, so they summarize to 192.168.4.0/22.
When the networks do not align
Take 192.168.2.0/24 through 192.168.5.0/24. They are also four contiguous networks, but the first one starts at 2, which is not a multiple of 4.
| Network | Third octet (binary) |
|---|---|
| 192.168.2.0/24 | 00000**010** |
| 192.168.3.0/24 | 00000**011** |
| 192.168.4.0/24 | 00000**100** |
| 192.168.5.0/24 | 00000**101** |
Only the first 5 bits of the third octet are shared. A single covering route would be 192.168.0.0/21, which spans third-octet values 0 to 7. That is 2048 addresses, and half of them (192.168.0.0/24, 192.168.1.0/24, 192.168.6.0/24, 192.168.7.0/24) are not yours.
The exact answer is two summaries: 192.168.2.0/23 and 192.168.4.0/23. Contiguous does not mean summarizable as one route.
A summary may cover unused space
Summaries do not have to be exact, provided you own the whole range. Consider the VLSM plan from the earlier chapter:
- 192.168.1.0/25
- 192.168.1.128/26
- 192.168.1.192/27
- 192.168.1.224/30
These four subnets sit inside 192.168.1.0/24. The /24 also contains unallocated space (192.168.1.228 to 192.168.1.255), but the whole /24 belongs to the same site. Advertising 192.168.1.0/24 is safe and keeps the table small.
Checking summaries with Python
The ipaddress module can both merge networks exactly and compute the smallest single covering block. The function below finds the shared leading bits of the lowest and highest addresses, which is the same method as the binary table.
import ipaddress
def smallest_supernet(networks):
nets = [ipaddress.ip_network(n) for n in networks]
low = min(int(n.network_address) for n in nets)
high = max(int(n.broadcast_address) for n in nets)
prefix = 32
while (low >> (32 - prefix)) != (high >> (32 - prefix)):
prefix -= 1
start = (low >> (32 - prefix)) << (32 - prefix)
return ipaddress.ip_network((start, prefix))
cases = {
"aligned": [
"192.168.0.0/24", "192.168.1.0/24",
"192.168.2.0/24", "192.168.3.0/24",
],
"misaligned": [
"192.168.2.0/24", "192.168.3.0/24",
"192.168.4.0/24", "192.168.5.0/24",
],
}
for label, nets in cases.items():
parsed = [ipaddress.ip_network(n) for n in nets]
sup = smallest_supernet(nets)
owned = sum(n.num_addresses for n in parsed)
print(label, sup, "covers", sup.num_addresses, "owned", owned)
print(list(ipaddress.collapse_addresses(parsed)))
# aligned 192.168.0.0/22 covers 1024 owned 1024
# [IPv4Network('192.168.0.0/22')]
# misaligned 192.168.0.0/21 covers 2048 owned 1024
# [IPv4Network('192.168.2.0/23'), IPv4Network('192.168.4.0/23')]If covers is larger than owned, the single summary includes addresses you do not hold. collapse_addresses never does this. It returns the fewest exact routes.
Summaries and longest-prefix match
A summary does not remove the need for specific routes. Routers can hold a summary and a more specific route at the same time, and they pick the route with the longest matching prefix. This is useful when one subnet lives somewhere else than the rest of the summarized block.
| Route | Next hop |
|---|---|
| 10.0.0.0/8 | Router A |
| 10.1.0.0/16 | Router B |
| 10.1.2.0/24 | Router C |
A packet for 10.1.2.9 matches all three routes. The /24 is the longest match, so it goes to Router C. A packet for 10.1.9.9 matches the /8 and the /16, so it goes to Router B. The next chapter covers this selection rule in detail.
Common errors
- Counting only the changed octet. Shared bits in earlier octets count too. The summary above is /22, not /6.
- Skipping the alignment check. A first network that is not a multiple of the block size cannot start a summary block.
- Summarizing a count that is not a power of two. Three contiguous /24 networks (0, 1, 2) cannot be one exact route. The result is 192.168.0.0/23 plus 192.168.2.0/24.
- Covering addresses you do not own. Traffic for the extra space is attracted to your router and then dropped or looped. Only advertise a summary that covers space you control.
- Forgetting that prefix length shrinks as the block grows. Joining two equal blocks lowers the prefix by 1. Joining four lowers it by 2. Joining eight lowers it by 3.
Exercise
Summarize 10.8.0.0/16, 10.9.0.0/16, 10.10.0.0/16, and 10.11.0.0/16 into one route. Show the alignment check.
Show answer
There are 4 networks, so the prefix shortens by 2 bits, from /16 to /14. The block size in the second octet is 4, and the first network starts at 8, which is a multiple of 4, so the networks align. In binary the second octet is 000010 followed by 00, 01, 10, or 11, so 6 bits are shared and the prefix is 8 + 6 = 14. The summary is 10.8.0.0/14.
Exercise
Can 192.168.6.0/24 through 192.168.9.0/24 be summarized as one exact route? If not, give the exact set of routes and the smallest single covering route.
Show answer
No. There are four networks, but the first starts at 6, which is not a multiple of 4. The exact set is 192.168.6.0/23 and 192.168.8.0/23. The smallest single covering route is 192.168.0.0/20, because the third octet values 6 (00000110) and 9 (00001001) share only 4 bits. That block covers third-octet values 0 to 15, which is 4096 addresses for 1024 owned.