Skip to content

Linux Foundations / Follow traffic and find the fault ยท Step 14 of 46

Lesson: Classless Inter-Domain Routing (CIDR)Switch
โ† Linux Foundations

Network operations

Classless Inter-Domain Routing (CIDR)

Learn CIDR notation, why it replaced address classes and how routes are summarised.

CIDR is the way we write and route IP address blocks today. You have already used it: the /24 in 192.168.1.0/24.

Before CIDR

Originally the first bits of an address decided its class. Class A networks were what we now call /8, class B /16 and class C /24. These fixed sizes wasted addresses: an organisation needing 1,000 hosts found a class C too small and a class B far too big. Routing tables were also growing quickly.

CIDR (first described in RFC 1519, now RFC 4632) removed the classes. A prefix can be any length from 0 to 32.

The notation

A block must start on a boundary that matches its size. A /22 steps by 4 in the third octet, so 10.0.100.0/22 is a valid start (100 is a multiple of 4) and covers 10.0.100.0 through 10.0.103.255. By contrast, 10.0.101.0/22 names an address inside that block, not its start.

A shorter prefix means a bigger block: /16 holds far more addresses than /24.

Variable length subnets

Within your own block you can mix sizes, often called VLSM. From a /24 you might take a /25 for staff, a /26 for servers and a /26 for guests. Allocate the largest first so that each block starts on a proper boundary, and never overlap them.

Summarisation

Neighbouring blocks can be advertised as one shorter prefix:

192.168.4.0/24
192.168.5.0/24
192.168.6.0/24
192.168.7.0/24   ->  192.168.4.0/22

This works because the first 22 bits are identical and all four pieces are present. Fewer routes means smaller tables.

Python can do it for you:

$ python3 -c 'import ipaddress; nets = [ipaddress.ip_network(f"192.168.{i}.0/24") for i in range(4, 8)]; print(list(ipaddress.collapse_addresses(nets)))'
[IPv4Network('192.168.4.0/22')]

If a summary covers addresses you do not own or cannot reach, traffic for them may be drawn to you and dropped.

Longest match

A summary and a more specific route can exist together. The router picks the longest matching prefix, so a /24 wins over the /22 that contains it.

See the IPv4 subnetting guide for more practice.

Try it

Which single prefix covers 10.20.8.0/24 to 10.20.15.0/24? Work it out in binary, then confirm with the Python command, changing the numbers. Also try three blocks only and see why the result holds more than one prefix.

Check your understanding

Classless Inter-Domain Routing (CIDR)

All 5 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.