Computer Networks / Practical class / Practical class 9
Practical class · Computer Networks

The CIDR (Classless Inter-Domain Routing) Concept

This is class 2 of the CIDR topic: complex cases. In class 8 (class 1) you learned to analyze a single address by hand. Now you take the place of a provider engineer: you merge dozens of networks into a single route (aggregation), allocate addresses to departments of different sizes with VLSM, give customers pieces of the provider’s block and hunt down overlapping networks. All of it in tasks that are checked automatically with the ipaddress module.

:ik-kitob: Practical class 9 ⏱ 2 academic hours (80 minutes) 🚇 Packet simulators ⚡ Many networks — one route
09

Lesson goals and plan

By the end of the lesson you will…

  • merge several networks into a single summary route by hand, in binary
  • check the aggregation conditions (contiguity, a power of two, boundary alignment) and detect over-coverage
  • allocate addresses to networks of different sizes with VLSM and explain why you must start with the largest
  • model how an address block is distributed in the IANA → RIR → provider → customer hierarchy
  • use the collapse_addresses, subnets, supernet, address_exclude and overlaps functions of the ipaddress module
  • compress a routing table by next hop and reduce the number of entries

Plan (according to the syllabus)

  1. The CIDR (Classless Inter-Domain Routing) Concept

A provider’s router does not need to know every home network separately: a single entry saying “all of 198.18.0.0/20 — send it to me” is enough. Today you will learn exactly this magic — aggregation. Just be careful: if you “collect” too much, my packets will fall into a black hole!

How do routers on the Internet “remember” billions of addresses?

If there were a separate entry for every home, office and phone network in the world, it would not fit in the memory of backbone routers. In reality the Internet’s global routing table had roughly one million IPv4 entries as of 2026 — a lot, but manageable. The secret is hierarchy and aggregation: a provider announces hundreds of its customers’ small networks as one large block. This is the second, “big” power of CIDR. Today we do exactly that in practice.

Key terms

Theory reminder

A reminder from class 8: a /n block has 232−n addresses; a network address is a multiple of the block size; if the prefix is shortened by 1, the block becomes twice as large. Aggregation is exactly the reverse of that last rule: two adjacent “twin” /n blocks — one /(n−1) block.

1

Contiguity

There must be no “holes” among the networks being merged (or the hole must also be yours).

2

A power of two

For an exact merge the number of blocks must be 2, 4, 8, 16… equal blocks.

3

Alignment

The first network must be a multiple of the summary block size: four /24s starting at 172.16.4.0 give a /22, starting at 172.16.5.0 — they do not.

Table 9.1. The “big” functions of the ipaddress module
FunctionExampleResult
n.subnets(new_prefix=p)ip_network("10.0.0.0/22").subnets(new_prefix=24)10.0.0.0/24 … 10.0.3.0/24 (generator)
n.supernet(new_prefix=p)ip_network("10.0.5.0/24").supernet(new_prefix=22)10.0.4.0/22
collapse_addresses(list)10.0.0.0/24, 10.0.1.0/2410.0.0.0/23
a.address_exclude(b)ip_network("10.0.0.0/24").address_exclude(ip_network("10.0.0.0/26"))10.0.0.128/25, 10.0.0.64/26 (a generator, the order is not guaranteed — sorted())
a.overlaps(b), a.subnet_of(b)10.0.0.0/16 and 10.0.5.0/24True, False / True (the reverse)
summarize_address_range(a, b)10.0.0.0 … 10.0.2.25510.0.0.0/23, 10.0.2.0/24

The CIDR (Classless Inter-Domain Routing) Concept

This is class 2. The basic calculations (mask, block, network/broadcast) are in class 8. Here we apply them on a large scale.

Worked example 1. Merging four branches into one route

Condition: The company “Andijon Agro” has four branches: 172.16.12.0/24, 172.16.13.0/24, 172.16.14.0/24, 172.16.15.0/24. The central router must announce a single summary route for them to the provider.

  1. Convert the differing octet to binary

    Only the 3rd octet differs: 12 = 00001100, 13 = 00001101, 14 = 00001110, 15 = 00001111.

  2. Count the common beginning

    The first 6 bits (000011) are the same in all of them. The two previous octets are 16 bits. The common prefix: 16 + 6 = /22.

  3. The summary network address

    Turn the bits after the common ones into zeros: 00001100 = 12 → 172.16.12.0/22.

  4. Check for over-coverage

    A /22 = 4 × /24 — exactly our four. There are no extra addresses: the aggregation is exact. The alignment is also in place: 12 is a multiple of 4.

The over-coverage risk

What if the branches are 172.16.13.0, .14.0, .15.0, .16.0? From 13 to 16 there are very few common bits (00001101 … 00010000) → the summary turns out to be a /19 and covers 32 /24s — 28 of them are not yours! If such a route is announced, other people’s traffic will flow to you and be dropped — a “black hole”. The right solution is several exact routes: collapse_addresses gives exactly that.

Enter the networks into the visualizer below (one per line). It stacks them in binary, highlights the common prefix in color, and shows the summary route and — most importantly — the over-covered blocks.

:ik-pazl: Aggregation visualizer

Worked example 2. VLSM: a university faculty

Condition: the faculty has been allocated 192.168.10.0/24. The needs: computer classrooms — 100 hosts, teachers — 50, guest Wi-Fi — 20, the link between two routers — 2. Give each a suitable block and reduce the waste.

  1. Sort from largest to smallest

    100, 50, 20, 2. Reason: large blocks align to large boundaries; if they are placed first, the small ones fit into the remaining space “without holes”.

  2. The smallest block for each

    100 → /25 (126), 50 → /26 (62), 20 → /27 (30), 2 → /30 (2) — the formula from task 6 of class 8.

  3. Place them one after another

    192.168.10.0/25 → .128/26 → .192/27 → .224/30. The next free space starts at .228 — a reserve for the future (.228/30, .232/29, .240/28).

  4. Check

    None of them overlap, all are inside the /24, and each is aligned to its own size.

Now see this visually. Turn on the “In input order” mode and watch what “holes” appear in between because of alignment when the blocks are placed without sorting, and how sometimes there is not enough space.

:ik-olcham: VLSM allocator

Worked example 3. A provider allocates its own block

Addresses are distributed from top to bottom: IANA → a regional registry (RIR; for Uzbekistan — RIPE NCC) → a local registry, usually a provider (LIR) → customers. At each stage a large block is split into smaller ones, while a summary route is announced upward.

IANA RIR: RIPE NCC Provider: 198.18.0.0/20 Bank: /22 University: /23 Café: /29 … customers To the Internet: only one /20 route
Fig. 9.1. Hierarchical distribution: downward — splitting, upward — a summary announcement. (198.18.0.0/15 is a block reserved for testing; it is used here as a conventional example)

Condition: the provider has 198.18.0.0/20. Customers come in turn and ask for /22, /23, /24, /24, /26. The provider gives each the first suitable (first-fit) aligned free block. The steps:

  1. /22

    Free: 198.18.0.0/20 → the first /22: 198.18.0.0/22. The remainder: 4.0/22, 8.0/21.

  2. /23

    The suitable block with the smallest address is 4.0/22 → its first half is 198.18.4.0/23. The remainder: 6.0/23, 8.0/21.

  3. /24, /24

    6.0/23 → 198.18.6.0/24 and 198.18.7.0/24.

  4. /26

    8.0/21 → 198.18.8.0/26. The list of what remains: 8.64/26, 8.128/25, 9.0/24, 10.0/23, 12.0/22 — Python calculates this in task 5.

In real life

In their internal (subscriber) networks, providers often use private addresses (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 — RFC 1918) or the 100.64.0.0/10 “carrier NAT” block (CGNAT, RFC 6598), because public IPv4 addresses are scarce. That is why the “WAN” address of your home router often starts with 100.64…100.127.

Test runs: first predict, then check

Independent tasks

7 tasks — harder than those in class 8: with lists, blocks and algorithms. Write input() without a prompt. If you have not done the tasks of class 8 yet, start with them.

Please note

In test 2 of task 7, 10.1.0.0/23 and 10.1.3.0/24 cannot be merged into one /22: the 10.1.2.0/24 in the middle goes to another router. In fact the router would still work correctly — thanks to the longest prefix rule (10.1.2.0/24 is more specific). That rule is the main topic of the next class, class 10.

Common mistakes

ErrorConsequenceCorrect answer
Announcing three /24s as “one /22”the fourth (foreign) /24 is also directed to you — a black holea /23 + a /24, or only the block that belongs to you
Merging adjacent but unaligned networks (1.0 and 2.0) into a /23no such /23 exists; the router would read it as 0.0/23check the twin first: is the address of the n-block a multiple of 2 × block?
Starting from the small networks in VLSMalignment holes, running out of spacesort the needs in decreasing order
Choosing a block without adding 2 to the number of hostsa /26 for a department of 62 hosts — the next device will not fitallow a reserve (20–30%) and account for the network/broadcast addresses
Assuming the result of address_exclude is sortedthe output order differs from the testsorted() or collapse_addresses
Giving customers overlapping blockstwo customers have the same addresses — connectivity breakscheck every new block with overlaps

Boss level

Boss level: the regional plan of “Vodiy Telekom”

You are the chief engineer of a provider. The company has been allocated a block (line 1). Line 2 has the number of cities k, then each line has City number_of_hosts. The task: +80 XP

  1. Place the cities one after another with VLSM in decreasing order of the number of hosts (for ties — in input order). A city that does not fit is skipped, and the next ones continue.
  2. Print the cities in input order: Shahar: tarmoq or Shahar: joy yetmadi.
  3. Aniq marshrutlar: — the collapse result of the allocated blocks (separated by «, »).
  4. Bo‘sh manzillar: N — the number of unallocated addresses in the block.

Think about it: In test 1, Andijan and Fergana were merged together into 10.50.0.0/21 because they happened to be adjacent twins. If the provider placed the regions in geographic order in advance, how many entries would be saved on the backbone routers?

Reinforcement

Review questions

What is route aggregation and why is it needed?

Representing several networks with one route that has a shorter prefix. Router tables shrink, route exchange speeds up, and internal changes do not “spread” outside.

The three conditions for exact aggregation?

The networks are contiguous; their number (of equal size) is a power of two; the first network is aligned to the size of the summary block.

How do you find the summary prefix by hand?

Write the smallest and the largest address in binary and count the common leading bits; if you turn the remaining bits into zeros, you get the summary network address.

What is over-coverage and how do you detect it?

When the summary block also contains addresses that do not belong to you. Subtract all the real networks from the summary (address_exclude) and check that the remainder is not empty.

What is VLSM and in what order is it done?

Masks of different lengths in one block. The needs are sorted in decreasing order, and each is given the smallest suitable block, one after another.

Explain the hierarchical distribution of IP addresses.

IANA → RIR (RIPE NCC) → LIR/provider → customer. Downward, large blocks are split; upward, a summary route is announced.

What is the difference between collapse_addresses and the “smallest summary block”?

collapse is a minimal list without over-coverage (there may be several blocks); the smallest summary is a single block, but it may cover extra addresses.

Can two CIDR blocks intersect “partially”?

No: either they do not intersect at all, or one lies inside the other (because the block boundaries are aligned).

Independent work

The independent study topic in the course syllabus: “IPv4 addressing, subnetting and efficient planning of IP addresses.” (6 hours). In class 8 you did the manual calculation part; this is the planning part.

Draw up a complete IP plan for the organization in your variant: a VLSM table (department, hosts, block, mask, gateway, reserve), a map of the blocks (a figure or a table), the summary route(s) to be announced to the provider, and an over-coverage check. Confirm the calculations with a Python script (ipaddress) and attach the script.

Assessment criteria (individual assignment)
CriterionPoints
The VLSM table is correct, the blocks do not overlap and are aligned2
The summary route(s) and the over-coverage analysis1
The Python script confirms the calculation1
The reserve and expansion plan are justified1

Summary

AggregationTwin /n blocks → one /(n−1); router tables shrink.
Three conditionsContiguity, a power of two, alignment — otherwise over-coverage.
Black holeDo not announce a block that is not yours; collapse_addresses is the safe way.
VLSMLargest to smallest, the smallest suitable block, one after another.
HierarchyIANA → RIPE NCC → provider → customer; upward — a summary announcement.
ipaddresssubnets, supernet, collapse_addresses, address_exclude, overlaps, subnet_of.
Next stepClass 10: how a router chooses the more specific prefix — routing.

Your lesson results

Your results are saved in this browser. Read all the sections and complete the exercises and assignments.

My personal notes