4.3 Classless Inter-Domain Routing (CIDR) & Subnetting
💡 Core Intuition: The Corporate Office Floor Partition
🍳 The Everyday Analogy: Dividing a Floor into Department Suites
Imagine a large technology enterprise rents the entire 4th floor of a downtown skyscraper:
- To the outside world (the postal delivery courier), the entire floor has a single unified address:
Suite 400. - However, inside the company, the CEO cannot let all 256 employees sit in one chaotic, unpartitioned room. Noise from Sales would distract Software Engineers, and visitors in Marketing might view confidential payroll records in HR.
- To organize the floor, the company builds physical drywall dividers, creating four distinct secured suites:
- Suite 4A: Engineering (Rooms 1 to 64)
- Suite 4B: Sales (Rooms 65 to 128)
- Suite 4C: Finance (Rooms 129 to 192)
- Suite 4D: Human Resources (Rooms 193 to 256)
When a courier enters the 4th-floor elevator lobby, an internal receptionist inspects the badge, determines which suite the employee belongs to, and directs them through the appropriate security door.
This is the exact purpose of Subnetting:
- To the global Internet, an organization appears as a single network block.
- Internally, the organization's network administrator borrows host bits to carve the block into smaller, isolated Subnets (Sub-networks), boosting security, containing broadcast storms, and streamlining departmental administration.
💻 Bridging to Computer Science
In standard classful IP addressing, there were only two levels of hierarchy: Network ID + Host ID.
Subnetting introduces a third hierarchical level by stealing (borrowing) high-order bits from the Host ID to form a Subnet ID:
When the Internet evolved to Classless Inter-Domain Routing (CIDR), rigid class boundaries were abolished entirely. Networks are now specified as arbitrary-length binary prefixes using Slash Notation (/n).
📑Table of Contents
- ✂️ Subnetting Architecture & Bit Borrowing Mechanics
- 🎭 The Subnet Mask & Bitwise AND Decision Engine
- 🌐 Classless Inter-Domain Routing (CIDR) & Slash Notation
- 📜 The Three Mandatory Rules of Valid CIDR Blocks
- 📐 Visual Blueprint: Subnet Router Dispatch Engine
- 🏭 Real-World Production Context: Point-to-Point Links & The
/31Subnet Exception - 📐 Numerical Applications & Worked Examples
- 🎯 Exam & Interview Pitfall Check
✂️ Subnetting Architecture & Bit Borrowing Mechanics
Why do organizations perform subnetting?
- Broadcast Containment: Broadcast frames (
255.255.255.255or ARP queries) are confined to the local subnet, preventing network degradation across other departments. - Access Control & Security: Routers and firewalls placed between subnets can enforce security policies (e.g., blocking student lab traffic from accessing university grading databases).
- Optimized IP Utilization: Large blocks (like Class B with 65,534 hosts) can be divided into sizes matching actual branch office populations.
| Architecture Scheme | Field Breakdown (MSB LSB) | Operational Description |
|---|---|---|
| Classful (No Subnetting) | Flat hierarchy with 65,534 hosts residing in a single massive broadcast domain. | |
| With Subnetting | Borrowing host bits divides the domain into distinct routed subnets. |
The Fundamental Subnetting Equations
When an administrator borrows bits from an original host field of bits:
- Total Subnets Created:
- Total Addresses per Subnet:
- Usable Hosts per Subnet: (Subtracting 2 because the all-0s host ID represents the Subnet Address, and the all-1s host ID represents the Subnet Directed Broadcast Address).
🎭 The Subnet Mask & Bitwise AND Decision Engine
How does an internal router know which subnet an incoming packet belongs to?
1. What is a Subnet Mask?
A Subnet Mask is a 32-bit binary number where:
- Every bit corresponding to the Network ID and Subnet ID is set to
1. - Every bit corresponding to the Host ID is set to
0.
| Mask Component | Bit Pattern Breakdown | Bit Count | Decimal Value |
|---|---|---|---|
| Network & Subnet Portion | 11111111 . 11111111 . 11111111 . 11000000 | 26 contiguous 1s | 255.255.255.192 (/26) |
| Host Portion | 000000 (last 6 bits in fourth octet) | 6 trailing 0s | Provides usable hosts |
2. The Bitwise AND Decision Engine
When an incoming IP packet arrives at a router interface, the router hardware extracts the packet's Destination IP Address, executes a lightning-fast bitwise AND operation against the configured Subnet Mask, and checks if the result matches the Subnet ID in its routing table:
| Layer / Parameter | Dotted Decimal | 32-Bit Binary Stream | Matching Outcome |
|---|---|---|---|
| Incoming Destination IP | 200.1.2.77 | 11001000 . 00000001 . 00000010 . 01001101 | Destination host in transit |
| Interface Subnet Mask | 255.255.255.192 | 11111111 . 11111111 . 11111111 . 11000000 | Applied /26 prefix filter |
| Bitwise AND Output | 200.1.2.64 | 11001000 . 00000001 . 00000010 . 01000000 | Exact match for Subnet 1 (200.1.2.64/26) |
🌐 Classless Inter-Domain Routing (CIDR) & Slash Notation
Standardized in RFC 1519 (1993), Classless Inter-Domain Routing (CIDR) eliminated the artificial Class A, B, and C boundaries. Instead of rigid 8-bit, 16-bit, or 24-bit networks, a network can have any arbitrary prefix length from 1 to 32.
1. Slash Notation (/n)
A CIDR network block is written as:
Where (the prefix length) represents the number of continuous 1s in the network mask:
/8Mask:255.0.0.0(8 network bits, 24 host bits)/16Mask:255.255.0.0(16 network bits, 16 host bits)/24Mask:255.255.255.0(24 network bits, 8 host bits)/26Mask:255.255.255.192(26 network bits, 6 host bits)/30Mask:255.255.255.252(30 network bits, 2 host bits usable hosts for point-to-point router links)
2. Extracting Information from a CIDR Address A.B.C.D / n
Given any CIDR block A.B.C.D / n:
- Total Number of IP Addresses in the Block ():
- Number of Usable Hosts:
- First Address (Network ID):
(Equivalent to setting all the last bits to
0) - Last Address (Directed Broadcast Address):
(Equivalent to setting all the last bits to
1)
📜 The Three Mandatory Rules of Valid CIDR Blocks
Not every random collection of IP addresses can form a valid CIDR network block. For an address range to be routable as a unified CIDR block, it MUST satisfy three strict mathematical conditions:
| Rule # | Requirement | Mathematical & Architectural Specification |
|---|---|---|
| Rule 1 | Contiguity | All IP addresses in the block must be sequential and contiguous, with zero omitted or skipped addresses. |
| Rule 2 | Power-of-2 Block Size | The total number of addresses must strictly satisfy for integer . |
| Rule 3 | Boundary Divisibility | The 32-bit integer value of the first address must be evenly divisible by : . Equivalently, the last bits of the first address must be all 0s. |
Why Does Rule 3 (Divisibility) Exist?
Because a router mask works by setting the first bits to 1s and the remaining bits to 0s. If the starting address did not have zeroes in its last positions, a single binary mask could not cleanly isolate the block without overlapping adjacent ranges!
📐 Visual Blueprint: Subnet Router Dispatch Engine
Below is an interactive architecture diagram illustrating how an enterprise border router uses subnet masks to direct incoming packets into three distinct internal subnets:
Enterprise Router Subnet Partitioning & Forwarding
Hardware bitwise AND matching directs packets across departmental subnets
🏭 Real-World Production Context: Point-to-Point Links & The /31 Subnet Exception
In cloud data centers (AWS Direct Connect, Google Cloud Interconnect) and core carrier networks, millions of routers are connected to each other via direct Point-to-Point Fiber Links:
Core Router R1
Interface fa0/0 (e.g., 10.0.0.0/31)
Direct Point-to-Point Link
High-speed optical fiber interconnect with zero intermediate broadcast hosts
Core Router R2
Interface fa0/1 (e.g., 10.0.0.1/31)
1. The Traditional /30 Problem (50% Address Waste)
Traditionally, engineers assigned a /30 subnet to a point-to-point link:
- Total addresses in
/30= . - Network Address () + Directed Broadcast () = .
- Usable Hosts = (Interface R1 and Interface R2).
- Efficiency: Exactly of all assigned addresses were wasted! Across a backbone with 10,000 links, 20,000 public IP addresses were lost.
2. The Modern Solution: RFC 3021 (/31 Subnets)
To eliminate this massive waste, the IETF standardized RFC 3021:
- A
/31prefix provides . - On a point-to-point link, there is zero need for broadcast (there are only two endpoints; any packet sent by R1 can only go to R2).
- Therefore, RFC 3021 specifies that for
/31links, the first address is assigned to Router 1, and the second address is assigned to Router 2, with zero addresses wasted ( efficiency).
📐 Numerical Applications & Worked Examples
Example 1: Extracting CIDR Block Parameters
Problem Statement: An organization is assigned the CIDR address block 200.10.11.144/27. Calculate:
- The Subnet Mask in dotted-decimal format.
- The total number of IP addresses in this block.
- The number of usable host IP addresses.
- The first address (Network ID) of the block.
- The last address (Directed Broadcast Address) of the block.
- The assignable IP range for workstations.
Step-by-Step Solution:
-
Calculate the Subnet Mask:
- Prefix length .
- Mask contains 27 ones followed by zeroes:
- Subnet Mask = .
-
Calculate Total and Usable Addresses:
- Host bits .
- Total IP addresses .
- Usable host addresses = .
-
Determine First Address (Network ID):
- Inspect the 4th octet ():
- Bitwise AND:
- Network ID = .
-
Determine Last Address (Directed Broadcast Address):
- Add to the Network ID:
- Directed Broadcast Address = .
-
Determine Assignable Host Range:
- First usable host = .
- Last usable host = .
- Assignable Range: .
Example 2: Validating CIDR Block Compliance
Problem Statement: Determine whether each of the following IP address ranges represents a mathematically valid CIDR block. If valid, express it in /n notation; if invalid, state which rule is violated:
- Block A:
100.1.2.32to100.1.2.47 - Block B:
20.10.30.32to20.10.30.63 - Block C:
150.10.20.64to150.10.20.127
Step-by-Step Solution:
-
Evaluate Block A (
100.1.2.32to100.1.2.47):- Rule 1 (Contiguity): Addresses are continuous ( to ).
- Rule 2 (Power of 2): Number of addresses = (Power of 2, ).
- Rule 3 (Divisibility): First address 4th octet is .
- Conclusion: Valid CIDR Block.
- Prefix length .
-
Evaluate Block B (
20.10.30.32to20.10.30.63):- Rule 1 (Contiguity): Addresses are continuous.
- Rule 2 (Power of 2): Number of addresses = (Power of 2, ).
- Rule 3 (Divisibility): First address 4th octet is .
- Conclusion: Valid CIDR Block.
- Prefix length .
-
Evaluate Block C (
150.10.20.64to150.10.20.127):- Rule 1 (Contiguity): Addresses are continuous.
- Rule 2 (Power of 2): Number of addresses = (Power of 2, ).
- Rule 3 (Divisibility): First address 4th octet is .
- Conclusion: Valid CIDR Block.
- Prefix length .
Example 3: Dividing a Network into Four Equal Subnets
Problem Statement: An engineering college is granted the network block 192.168.10.0/24. The network architect must divide this network into four equal-sized subnets for CSE, ECE, ME, and Civil departments. For each subnet, determine:
- Subnet ID and CIDR prefix
- Subnet Mask
- Range of assignable host IP addresses
- Directed Broadcast Address
Step-by-Step Solution:
-
Determine Bit Borrowing:
- Number of subnets required = Borrow .
- New prefix length .
- Remaining host bits .
- Total IP addresses per subnet = .
- Subnet Mask = 26 ones = .
-
Tabulate All Four Subnets:
| Subnet / Dept | Borrowed Bits | Subnet ID (First IP) | Assignable Host Range | Directed Broadcast (Last IP) | Usable Hosts |
|---|---|---|---|---|---|
| Subnet 1 (CSE) | 00 | 192.168.10.0/26 | 192.168.10.1 - 192.168.10.62 | 192.168.10.63 | 62 |
| Subnet 2 (ECE) | 01 | 192.168.10.64/26 | 192.168.10.65 - 192.168.10.126 | 192.168.10.127 | 62 |
| Subnet 3 (ME) | 10 | 192.168.10.128/26 | 192.168.10.129 - 192.168.10.190 | 192.168.10.191 | 62 |
| Subnet 4 (Civil) | 11 | 192.168.10.192/26 | 192.168.10.193 - 192.168.10.254 | 192.168.10.255 | 62 |
🎯 Exam & Interview Pitfall Check
-
Why does bitwise ANDing a Destination IP with a Subnet Mask yield the Subnet ID?
Because of the fundamental algebraic property of the bitwise AND logical operation: and . Since the subnet mask consists of continuous1s across all network and subnet bit positions, ANDing preserves the network and subnet identifier bits intact. Because the host bits in the mask are all0s, ANDing zeroes out all host bits, mathematically producing the exact Subnet ID. -
What happens if an IP address range satisfies Rule 1 (Contiguous) and Rule 2 (Power of 2), but fails Rule 3 (Divisibility)?
The range cannot be advertised as a single routing prefix. If you attempt to write it as a single/nprefix, the prefix will encompass foreign IP addresses outside your range while excluding valid addresses within your range. It would require multiple fragmented routing table entries to advertise, defeating the core purpose of CIDR.
-
Trap: Forgetting to subtract 2 for broadcast and network IDs when calculating usable hosts.
Debunked: If a subnet has 6 host bits, the total addresses are , but the maximum number of usable computers you can configure is strictly . Forgetting the penalty is the single most common numerical error in semester and competitive exams. -
Trap: Assuming subnet masks can have scattered, non-contiguous ones (e.g.,
255.255.240.16).
Debunked: Standard IPv4 subnet masks MUST consist of contiguous1s from the most significant bit followed by contiguous0s. A bit pattern with alternating ones and zeroes like...11010000is invalid in standard CIDR networking.