# How to aggregate a routing table given IP addresses and their subnet masks

Novice networker here.

I can't seem to find any straightforward answers online.

Example:

``````  IP             SUBNET           NEXT HOP
> 129.10.112.0   255.255.255.0    R1
> 129.10.80.0    255.255.255.0    R1
> 129.10.0.0     255.255.0.0      R2
> 129.10.63.0    255.255.255.0    R4
> 129.10.63.0    255.255.255.0    R4
> 129.10.64.0    255.255.192.0    R3
> 129.10.65.0    255.255.255.0    R4
> 129.10.66.0    255.255.255.0    R4
``````

What is the proper method to aggregate these entries into the minimum number of entries?

• Did any answer help you? if so, you should accept the answer so that the question doesn't keep popping up forever, looking for an answer. Alternatively, you could provide and accept your own answer. – Ron Maupin Aug 10 '17 at 3:34

First, separate the entries by next hop. You have to summarize them separately:

``````IP             SUBNET           NEXT HOP
129.10.112.0   255.255.255.0    R1
129.10.80.0    255.255.255.0    R1

129.10.0.0     255.255.0.0      R2

129.10.64.0    255.255.192.0    R3

129.10.63.0    255.255.255.0    R4
129.10.63.0    255.255.255.0    R4
129.10.65.0    255.255.255.0    R4
129.10.66.0    255.255.255.0    R4
``````

Then for each next next hop, convert all the network addresses to binary. Here is just the first one:

``````10000001.00001010.01110000.00000000 = 129.10.112.0
10000001.00001010.01010000.00000000 = 129.10.80.0
``````

Now find all the identical digits, starting from the left. In this case, the digits are all the same up to the 18th position. So your new mask is /18. Now, using either address and the /18 mask, find the network address by ANDing the address and the mask:

``````10000001.00001010.01110000.00000000 = 129.10.112.0
11111111.11111111.11000000.00000000 = /18 (255.255.192.0)
-------------------------------------
10000001.00001010.01000000.00000000 = 129.10.64.0 /18
``````

So the best summarization of the first two routes is 129.10.64.0/18.

(the rest is left as a exercise for the reader)

There is tool Aggregate from ISC.

I have dump with Google IPs (6760 subnets)

``````\$ cat google-ip | wc -l
6760
66.249.64.0/20
66.249.80.0/20
74.125.57.240/29
216.239.44.0/24
216.239.45.0/24
23.251.128.0/23
23.251.128.0/24
23.251.129.0/24
23.251.130.0/23
23.251.130.0/24
``````

Usage of aggregate

``````\$ aggregate < google-ip > google-ip-agged
\$ cat google-ip-agged | wc -l
58
1.0.0.0/24
1.1.1.0/24
1.2.3.0/24
8.8.4.0/24
8.8.8.0/24
8.15.202.0/24
8.34.208.0/20
8.35.192.0/20
23.236.48.0/20
23.251.128.0/19
``````

My big dump aggregated to only 58 subnets.

I used `aur/aggregate` from Archlinux.