Overview

In this short blog post we are going to present a simple procedure for IPv4 prefix summarization. The procedure is based on the one found in “Optimal Routing Design” book by Russ White, Don Slice and Alvaro Retana, but differs in some respects. The process is three step, and require the use of Windows calculator for ease of computation. No binary breakdowns are involved, just some basic arithmetic. For the sake of simplicity, we skip all proofs, as those are trivial. The same approach could be adopted for use with IPv6 prefixes, provided that decimal arithmetic is replaced with hexadecimal.

Scenario

We are going to use an example to demonstrate the method. Here is the task: find the optimal (longest prefix length) summary prefix for the following set of subnets:

Preparations

It does not matter if the subnets have different prefix lengths – you may simply ignore these, as the resulting summary will use its own prefix length. Sort the prefixes in ascending order, starting with lowest and to the highest 32-bit number. Find the octet where the prefixes differ (we would call it “changing octet” from here on). In our case this is the 3rd octet (98, 99 etc):

You only need to sort the prefixes to find the lowest and the highest changing octet values. The changing octet position also gives us the corresponding “positional prefix length”. If this octet is the first in the prefix, the positional prefix length is 8, if it’s the second then the positional prefix length is 16, next 24 for third and 32 for fourth position in the dotted-decimal form.

Step 1:

Take the highest and lowest changing octets and perform XOR operation on them. You may use Windows calculator or any other utility that allows for logical operations on decimal numbers: “98 XOR 105 = 11″. Next, take the lowest power of “2” that is strictly greater than the resulting number (even if the result is a power of two itself). In our case it is 16. Let’s call this number as “y”. After that, find the number z, so that “2^z=y” (here “^” means power, not XOR like in C), i.e. take Log2 of “y”: “z = Log2(y) = Log2(16) = 4″. You may use a short table of powers of 2 ranging from 2^0 to 2^8 – you don’t need more as you deal with just a single octet. It’s easy to memorize these numbers too. Notice that dealing with IPv6 would require the table of 16 elements (2^0 through 2^16).

Note The original method found in “Optimal Routing Design” uses subtraction operation instead of XOR at this step. It could be shown that subtraction does not work in all cases. For example, it does not reveal the correct highest mismatching bit position in the case of: 10.1.66.0 and 10.1.69.0 as “69-66=3″ (incorrectly approximated by 2^2) while “69 XOR 66 = 7″ (correctly approximated by 2^3). The reason being are “arithmetic underflows” that happen with subtraction.

Step 2:

Take the any changing octet value, e.g. the lowest one, and divide it by “y” then drop the remainder: “98/16 = 6.125″ rounded to 6 (“floor” function). Now multiply 6 by “y” again to yield 96 – this is the base octet of the summary address. The summary prefix now looks like: 192.168.96.0. Effectively, these two operations represent logical binary shift right and left to mask the changing bits. Yes, you may take ANY octect from the set of prefixes – the result will be the same.

Step 3:

The final step is finding the summary prefix length. Take the positional prefix length corresponding to the changing octet, as described previously. In our case it’s the third octet, and thus the positional prefix length is 24. Now subtract “z” from this number to get “x” – the summary prefix length: “x=24-z=24-4=20″. The summary prefix is: 192.168.y.0/x = 192.168.96.0/20

Step 4 (Optional):

Convert prefix length into network mask, if needed. To accomplish this, take 256 and subtract “y”: 256-16=240. This is the netmask component that corresponds to the summary base octet: 192.168.96.0 255.255.240.0

Conclusions

The procedure presented in this article could be useful when dealing with large-scale networks and configuring manual IPv4 prefix summarization. You may avoid complicated binary conversions and simply use the calculator to find the resulting prefix.

About Petr Lapukhov, 4xCCIE/CCDE:

Petr Lapukhov's career in IT begain in 1988 with a focus on computer programming, and progressed into networking with his first exposure to Novell NetWare in 1991. Initially involved with Kazan State University's campus network support and UNIX system administration, he went through the path of becoming a networking consultant, taking part in many network deployment projects. Petr currently has over 12 years of experience working in the Cisco networking field, and is the only person in the world to have obtained four CCIEs in under two years, passing each on his first attempt. Petr is an exceptional case in that he has been working with all of the technologies covered in his four CCIE tracks (R&S, Security, SP, and Voice) on a daily basis for many years. When not actively teaching classes, developing self-paced products, studying for the CCDE Practical & the CCIE Storage Lab Exam, and completing his PhD in Applied Mathematics.

Hey Petr can you write some good detailed article on Prefix Lists from binary prospective. I know most people feel that it’s very easy though. But there are many out there like me who still want to
understand it from binary point of view specially when someone asks something like : Construct a prefix list that denies any prefix for which the most-significant four bits are “0110″, and permits everything else.

so Petr in my case y=4 as 221XOR223=2 so I have to take Y strictly greater than the XOR result right? so it will be 4. Then I will do Log2(4) which will give me result of 2 and that is 24-2=22 and that will be my mask. and for 3rd octet 221/4=55.25 and I will take 55 by leaving reminder and again 55×4=220, so that way 222.222.220.0/22 is the result right?

So for Y it has to be “greater than”, it is “not equal” to the XOR result….

“Take the highest and lowest changing octets and perform XOR operation on them. You may use Windows calculator or any other utility that allows for logical operations on decimal numbers: “98 XOR 105 = 11″. Next, take the lowest power of “2” that is strictly greater than the resulting number (even if the result is a power of two itself)”

The above, as Wikipedia mentions says the answer is a 192.168.96.0/20. It in itself is wrong because a /20 encompasses 16 /24 networks. We’re only asked to summarize for the above 6 /24 networks in the example to ONE block, if possible.

1. What if the above subnets were to be BLOCKED via an ACL? The subnet 192.168.97.0/24 is included in the 92.168.96.0/20 Supernet. To me that is an invalid summarization as it included a network that shouldn’t be part of the blocked networks.

If I was to summarize the above, assuming each of them are /24’s as suggested by some of the contiguous subnets 192.168.98.0 through 192.168.102.0, the summary address should be

192.168.98.0/23
192.168.100.0/23
192.168.102.0/24
192.168.105.0/24

If converted into an ACL, the above summary addresses will only permit networks within 192.168.98.0 through 192.168.102.255 and 192.168.105.0-192.168.105.255. Networks 192.168.96.0/24, 192.168.97.0/24, and 192.168.103.0/24 up to 192.168.111.0/24 are not specified to be included in the summary route.

To contrast, see another example below for summarization and only the networks specified.

Leave a Reply

Currently you have JavaScript disabled. In order to post comments, please make sure JavaScript and Cookies are enabled, and reload the page.Click here for instructions on how to enable JavaScript in your browser.