Chapter 5: CIDR Notation and Prefix Length

Learning Objectives

Pre-Quiz: The Slash Notation

An address is written as 192.168.0.15/24. What does the number 24 actually count?

The number of usable host addresses in the network
The count of consecutive leading 1 bits in the subnet mask
The value of the last octet of the IP address
The number of subnets the block has been divided into

Why is /23 a perfectly valid prefix under CIDR when it would have been impossible under classful addressing?

Classful addressing only supported prefixes larger than /24
CIDR lets the network/host boundary fall at any bit position, not just on 8-bit octet boundaries
/23 is reserved for IPv6 and only became legal after CIDR
Classful masks were always odd numbers, so /23 was skipped

For a /24 network, how many of the 32 address bits are host bits?

8
24
16
32

A router receives a packet for 192.168.0.15 on an interface configured as /24. What operation does it perform to extract the network address 192.168.0.0?

A bitwise AND of the address with the subnet mask
A bitwise OR of the address with the broadcast address
It adds the prefix length to the final octet
It looks up the class of the address to guess the mask

What is the key practical advantage of slash notation over the old classful naming (Class A/B/C)?

It uses fewer characters when written on a whiteboard
It states the mask explicitly every time instead of leaving it implied by the address class
It works only with private IP addresses
It removes the need for a subnet mask entirely

The Slash Notation

Key Points

Addresses like 192.168.0.15/24, 10.0.0.0/8, and 172.16.0.0/16 use slash notation (also called CIDR notation): an IP address, a slash, and a decimal number. That number is the prefix length — the count of consecutive leading 1 bits in the subnet mask.

An IPv4 address is 32 bits. The prefix length says how many of those bits belong to the network portion; the rest are the host portion. So /24 means the first 24 bits are network and the last 8 are host:

/24  →  11111111.11111111.11111111.00000000  →  255.255.255.0

Count the 1s in 255.255.255.0 and you get exactly 24 — which is why it is written /24.

Figure 5.1: Prefix length as the bit boundary between network and host portions

flowchart LR subgraph Bits["32-bit IPv4 address"] direction LR N["Network portion
bits 1-24
(the prefix: 24 leading 1s)"] H["Host portion
bits 25-32
(trailing 0s)"] end N -. "boundary drawn at /24" .-> H N --> MaskN["Mask: 11111111.11111111.11111111"] H --> MaskH["Mask: 00000000"] MaskN --> Result["255.255.255.0 = /24"] MaskH --> Result

Analogy — a phone number and its area code. The prefix length draws a line: everything to the left is the "area code" (which network you belong to), everything to the right is your personal "line number." A /24 draws that line after 24 binary digits; a /16 draws it earlier. Everyone on the same side of the line shares the same network.

At the packet level, a router applies the mask using a bitwise AND, which zeroes out the host bits and leaves the network address behind. That extracted network address is what the router matches against its routing table.

Figure 5.2: How a router extracts the network address with a bitwise AND

flowchart TD A["IP address
192.168.0.15"] B["Subnet mask (/24)
255.255.255.0"] A --> AND{"bitwise AND
(bit-by-bit)"} B --> AND AND --> C["Network address
192.168.0.0"] C --> D["Router matches this against
its routing table to decide
where the packet belongs"]

Visual animation — coming soon

/8, /16, /24, and everything in between

The old classful system allowed only three sizes, all landing on tidy octet boundaries: /8 (Class A), /16 (Class B), and /24 (Class C). CIDR's power is that the prefix is not restricted to multiples of 8 — it can be any value from /0 to /32. A /23, /26, or /30 is perfectly valid. This freedom to place the boundary at any bit position is the mathematical heart of variable-length subnet masking (VLSM).

CIDR vs. classful

AspectClassful addressingCIDR (classless)
Network sizesFixed at /8, /16, /24Any prefix from /0 to /32
BoundaryLocked to 8-bit octetsAny bit position
NotationClass name (A/B/C)Slash notation (/nn)
SubnettingOnly within class limitsArbitrary subnet and supernet

Under classful rules the class was implied by the address's first bits and the mask was assumed. Under CIDR nothing is assumed — the prefix length is stated explicitly every time, which is exactly why the notation is so useful.

Post-Quiz: The Slash Notation

An address is written as 192.168.0.15/24. What does the number 24 actually count?

The number of usable host addresses in the network
The count of consecutive leading 1 bits in the subnet mask
The value of the last octet of the IP address
The number of subnets the block has been divided into

Why is /23 a perfectly valid prefix under CIDR when it would have been impossible under classful addressing?

Classful addressing only supported prefixes larger than /24
CIDR lets the network/host boundary fall at any bit position, not just on 8-bit octet boundaries
/23 is reserved for IPv6 and only became legal after CIDR
Classful masks were always odd numbers, so /23 was skipped

For a /24 network, how many of the 32 address bits are host bits?

8
24
16
32

A router receives a packet for 192.168.0.15 on an interface configured as /24. What operation does it perform to extract the network address 192.168.0.0?

A bitwise AND of the address with the subnet mask
A bitwise OR of the address with the broadcast address
It adds the prefix length to the final octet
It looks up the class of the address to guess the mask

What is the key practical advantage of slash notation over the old classful naming (Class A/B/C)?

It uses fewer characters when written on a whiteboard
It states the mask explicitly every time instead of leaving it implied by the address class
It works only with private IP addresses
It removes the need for a subnet mask entirely
Pre-Quiz: CIDR and Address Allocation

An organization needs 500 addresses. Under classful rules, why was this so wasteful?

A Class C (254 hosts) was too small, so they were bumped to a Class B (65,536), leaving ~99% idle
Class B blocks could not be routed on the internet
They had to buy two separate Class A blocks
Classful addressing charged per unused address

Which prefix gives a near-perfect fit for that 500-host organization?

/24 (254 usable hosts)
/23 (510 usable hosts)
/16 (65,534 usable hosts)
/25 (126 usable hosts)

What were the two original design goals of CIDR when the IETF introduced it in 1993?

Slowing IPv4 address exhaustion and curbing routing-table growth
Encrypting traffic and adding firewalls
Replacing IPv4 with IPv6 and adding NAT
Standardizing DNS and speeding up DHCP

An ISP holds a /16 and controls sixteen contiguous /24s that share their first 20 bits. What is the benefit of advertising them as a single 203.0.0.0/20?

It doubles the number of usable hosts
Sixteen routing-table entries collapse into one, keeping routing tables lean
It converts the block from IPv4 to IPv6
It prevents customers from subnetting further

How does supernetting relate to subnetting?

They are unrelated; supernetting only applies to IPv6
Supernetting shortens the prefix to combine blocks; subnetting lengthens it to split a block
Both lengthen the prefix, just at different layers
Supernetting removes the mask entirely, while subnetting keeps it

CIDR and Address Allocation

Key Points

CIDR was introduced by the IETF in 1993 (RFC 1518 and RFC 1519, later updated by RFC 4632 in 2006) to solve two urgent problems classful addressing created: the rapid exhaustion of the IPv4 address space, and the runaway growth of internet routing tables.

The purpose: ending the waste of classful allocation

The classful system forced every network into one of a few sizes: Class A (/8) ≈ 16.7 million addresses, Class B (/16) = 65,536, Class C (/24) = 256. An organization needing 500 addresses could not fit in a single Class C (254 usable), so it was bumped to a Class B of over 65,000 — using fewer than 1% and leaving ~99% idle.

CIDR fixes this with right-sized (classless) allocation. Because the prefix can fall on any bit boundary, that 500-host organization gets a /23 (510 usable hosts) — a near-perfect fit instead of a wasteful /16. This directly slows depletion of the IPv4 pool.

Analogy — renting the right amount of storage. Classful allocation rented only three unit sizes: closet, garage, or warehouse. If your belongings didn't fit the closet, your only option was the warehouse — and you paid for all that empty space. CIDR builds a unit to whatever size you actually need.

Provider address blocks

Regional registries hand large blocks to ISPs, and ISPs subdivide them classlessly for customers. An ISP holding a /16 might carve it into hundreds of /24s, /26s, or /29s, each sized to a customer's need. The address block — a contiguous range described by one CIDR prefix — becomes the fundamental unit of allocation.

Figure 5.3: Provider address-block allocation hierarchy

graph TD RIR["Regional Internet Registry
hands out large blocks"] ISP["ISP holds a /16
(65,536 addresses)"] C1["Customer A: /24
(254 hosts)"] C2["Customer B: /26
(62 hosts)"] C3["Customer C: /29
(6 hosts)"] RIR --> ISP ISP --> C1 ISP --> C2 ISP --> C3

Reducing routing table size through supernetting

Every distinct network needs an entry in core routers' routing tables. Under classful routing each network required its own entry, and as the internet grew these tables ballooned toward sizes that threatened router memory and performance.

CIDR's answer is route aggregation, also called supernetting. Multiple contiguous blocks that share the same leading bits collapse into a single entry with a shorter prefix — a supernet. Suppose an ISP controls sixteen contiguous /24s that all share their first 20 bits:

203.0.0.0/24
203.0.1.0/24
203.0.2.0/24
   ...
203.0.15.0/24     (16 networks in total)

Because all sixteen share their first 20 bits, they can be advertised as a single supernet:

203.0.0.0/20     (one routing entry replaces sixteen)

Figure 5.4: Supernetting collapses sixteen contiguous /24s into one /20 route

flowchart LR subgraph Sixteen["Sixteen separate /24 routes"] direction TB R1["203.0.0.0/24"] R2["203.0.1.0/24"] R3["203.0.2.0/24"] Rdot["..."] R16["203.0.15.0/24"] end Sixteen -->|"share first 20 bits
→ route aggregation"| Super["203.0.0.0/20
one supernet route"]

Multiply that savings across the whole internet and the effect is dramatic: smaller routing tables, faster routing decisions, less router memory. Supernetting is the mirror image of subnetting — subnetting makes a prefix longer to split a block, while supernetting makes it shorter to combine blocks. None of this was possible under classful rules, which is why classless addressing is now the universal standard.

Post-Quiz: CIDR and Address Allocation

An organization needs 500 addresses. Under classful rules, why was this so wasteful?

A Class C (254 hosts) was too small, so they were bumped to a Class B (65,536), leaving ~99% idle
Class B blocks could not be routed on the internet
They had to buy two separate Class A blocks
Classful addressing charged per unused address

Which prefix gives a near-perfect fit for that 500-host organization?

/24 (254 usable hosts)
/23 (510 usable hosts)
/16 (65,534 usable hosts)
/25 (126 usable hosts)

What were the two original design goals of CIDR when the IETF introduced it in 1993?

Slowing IPv4 address exhaustion and curbing routing-table growth
Encrypting traffic and adding firewalls
Replacing IPv4 with IPv6 and adding NAT
Standardizing DNS and speeding up DHCP

An ISP holds a /16 and controls sixteen contiguous /24s that share their first 20 bits. What is the benefit of advertising them as a single 203.0.0.0/20?

It doubles the number of usable hosts
Sixteen routing-table entries collapse into one, keeping routing tables lean
It converts the block from IPv4 to IPv6
It prevents customers from subnetting further

How does supernetting relate to subnetting?

They are unrelated; supernetting only applies to IPv6
Supernetting shortens the prefix to combine blocks; subnetting lengthens it to split a block
Both lengthen the prefix, just at different layers
Supernetting removes the mask entirely, while subnetting keeps it
Pre-Quiz: Prefix-to-Mask Conversion

Using the fill-and-pad recipe, what is the dotted-decimal mask for /26?

255.255.255.192
255.255.255.224
255.255.255.0
255.255.192.0

Reverse conversion: given the mask 255.255.255.192, what is the prefix length?

/24
/26
/27
/25

How many usable host addresses does a /30 provide, and why is it the classic choice for a router-to-router link?

4 usable — enough for a small office
2 usable — exactly enough for the two ends of a point-to-point link
6 usable — the standard for WAN links
0 usable — it is reserved

In the partial-octet table, which octet value corresponds to 3 borrowed bits (11100000)?

192
224
240
248

Why does a /31 uniquely give 2 usable addresses out of 2, unlike almost every other prefix?

RFC 3021 lets point-to-point links use both addresses, reserving no network or broadcast address
It borrows an extra bit from the /32 above it
Its broadcast address doubles as a second host
It is only valid in IPv6, where broadcast does not exist

Prefix-to-Mask Conversion

Key Points

Every IPv4 prefix from /0 to /32 maps to exactly one subnet mask. Total addresses in a block = 2^(32 − prefix); usable hosts is normally 2^(32 − prefix) − 2, subtracting one address for the network identifier and one for the broadcast address.

Two rows deserve special attention. A /31 (RFC 3021) is used for point-to-point links, where both addresses are usable and no network or broadcast address is reserved — 2 usable out of 2. A /32 describes a single host: exactly one address, used for host routes and loopback interfaces.

Fast mental conversion

You do not need all 33 rows. Memorize just the eight possible values of a partial octet — the octet only partly filled with 1 bits:

Bits borrowedOctet value
1128
2192
3224
4240
5248
6252
7254
8255

These come straight from binary: one leading 1 is 10000000 = 128; two are 11000000 = 192; each added bit adds the next power of two until all eight give 11111111 = 255. Each value is the previous one plus a halving step (128, +64, +32, +16, …).

With that table in hand, converting any prefix to a mask is a three-step recipe:

  1. Fill whole octets. Each group of 8 prefix bits becomes a 255. A /26 has three full octets (24 bits), so the mask starts 255.255.255.
  2. Handle the leftover bits. Subtract the full octets from the prefix: 26 − 24 = 2 leftover bits. Look up 2 bits → 192. Mask is now 255.255.255.192.
  3. Pad with zeros. Any octet after the partial one is 0.

Figure 5.5: The three-step prefix-to-mask conversion recipe

flowchart TD Start["Start with a prefix
e.g. /26"] Step1["Step 1 — Fill whole octets
26 ÷ 8 = 3 full octets → 255.255.255"] Step2["Step 2 — Handle leftover bits
26 − 24 = 2 bits → look up in table → 192"] Step3["Step 3 — Pad remaining octets with 0
(none left for /26)"] Result["Mask: 255.255.255.192"] Start --> Step1 --> Step2 --> Step3 --> Result

Visual animation — coming soon

Worked example — convert /20: 20 = 16 + 4, so two full octets → 255.255; 4 leftover bits → 240; remaining octet 0255.255.240.0.

Worked example — mask to prefix: given 255.255.255.192, two full 255s = 16 bits, a third 255 = 24, and 192 = 2 bits → 24 + 2 = /26.

Worked example — host counts: for /26, total = 2^6 = 64, usable = 62. For /30, total = 2^2 = 4, usable = 2 — exactly why /30 is the classic router-to-router link.

Common exam prefixes

PrefixMaskUsable hostsTypical use
/8255.0.0.016,777,214Very large blocks; private 10.0.0.0/8
/16255.255.0.065,534Large campus
/24255.255.255.0254The default LAN subnet
/25255.255.255.128126Splitting a /24 in half
/26255.255.255.19262Small departments
/27255.255.255.22430Small offices, wireless segments
/28255.255.255.24014Tiny subnets, DMZ hosts
/30255.255.255.2522Point-to-point WAN links
/31255.255.255.2542Point-to-point links (RFC 3021)
/32255.255.255.2551Single host / loopback route

Notice the pattern past /24: the final octet marches through the partial-octet values — 128, 192, 224, 240 — while the host count halves at each step. Seeing that pattern rather than memorizing isolated facts is what makes conversion feel automatic.

Post-Quiz: Prefix-to-Mask Conversion

Using the fill-and-pad recipe, what is the dotted-decimal mask for /26?

255.255.255.192
255.255.255.224
255.255.255.0
255.255.192.0

Reverse conversion: given the mask 255.255.255.192, what is the prefix length?

/24
/26
/27
/25

How many usable host addresses does a /30 provide, and why is it the classic choice for a router-to-router link?

4 usable — enough for a small office
2 usable — exactly enough for the two ends of a point-to-point link
6 usable — the standard for WAN links
0 usable — it is reserved

In the partial-octet table, which octet value corresponds to 3 borrowed bits (11100000)?

192
224
240
248

Why does a /31 uniquely give 2 usable addresses out of 2, unlike almost every other prefix?

RFC 3021 lets point-to-point links use both addresses, reserving no network or broadcast address
It borrows an extra bit from the /32 above it
Its broadcast address doubles as a second host
It is only valid in IPv6, where broadcast does not exist

Your Progress

Answer Explanations