Network Layer: IP Addressing, CIDR Subnetting, and Routing
A comprehensive breakdown of network models, layered communication workflows, IP addressing schemes, subnetting mechanics, and transport layer protocols.
1. Network Models: OSI vs. TCP/IP Architecture
Computer networks rely on layered architectures to standardize communication between disparate devices across the globe. The two primary models are the theoretical 7-Layer OSI Model and the practical 4-Layer TCP/IP Model used by the modern Internet.
The 7-Layer OSI Model Breakdown
Mnemonic Hook: To easily remember the OSI layers from top to bottom (Layer 7 to Layer 1):
All People Seem To Need Data Processing
(Application, Presentation, Session, Transport, Network, Data Link, Physical)
OSI Model vs. TCP/IP Model Mapping
2. End-to-End Data Flow: The Chat Message Lifecycle
Real-Life Analogy: Sending a Message
When a user types a "Hi" message to a friend on a mobile device, the data traverses the protocol stack down to physical transmission mediums (Wi-Fi, cell towers, fiber cables), reaches the central server for processing, and ascends back up the stack on the recipient's device.
Step-by-Step Traversal Workflow
3. Data Encapsulation and Protocol Data Units (PDUs)
Data moves through headers appended at each layer during transmission (encapsulation) and stripped off during reception (de-encapsulation).
- Sender Flow (Top to Bottom): Data is generated at the Application layer. Each descending layer appends its specific control metadata (headers containing IP addresses, ports, sequence numbers, checksums) until it converts to raw bits at the Physical layer.
- Receiver Flow (Bottom to Top): The receiving host takes physical bits, validates Layer 2 MAC addresses, inspects Layer 3 IP routing information, evaluates Layer 4 port mappings, and delivers the payload to the Layer 7 Application.
4. IP Addressing Fundamentals: IPv4 vs. IPv6
An IP address functions as a unique numerical identifier for any device connected to a network, analogous to a postal address or GPS coordinate.
IPv4 vs. IPv6 Comparison
5. IPv4 Classes and Special IP Ranges
IPv4 addresses were historically categorized into five classes based on the leading octet bits.
Special Purpose IP Ranges
- Loopback Address / Localhost (
127.0.0.1): Used by a host machine to establish network connections back to itself without placing packets onto the physical network interface. - Private IP Ranges (RFC 1918): Non-routable on the public internet, used inside local homes, offices, and data center private networks:
10.0.0.0to10.255.255.255(Class A private)172.16.0.0to172.31.255.255(Class B private)192.168.0.0to192.168.255.255(Class C private)
6. CIDR, Subnet Masks, and Subnetting Mechanics
Real-Life Analogy: Hierarchical Postal Routing
To send mail internationally, the logistics carrier does not search for individual house numbers immediately. The letter moves progressively:
Subnetting applies this identical hierarchy to binary networks, allowing large blocks of addresses to be cleanly divided into smaller, manageable sub-networks.
Network vs. Host Identification
A Subnet Mask separates an IP address into two distinct parts:
- Network ID: Identifies the specific network segment.
- Host ID: Identifies the specific physical or virtual machine within that segment.
CIDR Notation Explained (192.168.1.0/24)
In Classless Inter-Domain Routing (CIDR) notation, /24 represents the prefix length:
- Network Bits: First 24 bits are fixed for the network (
192.168.1). - Host Bits: Remaining bits are available for host assignments.
Why Subtract 2?
- Network ID (First Address):
192.168.1.0identifies the subnet itself.- Broadcast Address (Last Address):
192.168.1.255is reserved to broadcast packets simultaneously to all hosts on the subnet.- Assignable Host Range:
192.168.1.1through192.168.1.254.
7. Transport Protocols: TCP vs. UDP
The Transport Layer manages end-to-end communication, error recovery, and host multiplexing.
Real-Life Analogy: Delivery Receipts
- TCP (WhatsApp with Read Receipts): You send a message Single Tick (Sent) Double Tick (Delivered) Blue Tick (Acknowledged read). If undelivered, retransmission occurs.
- UDP (Standard SMS / Postcard): You drop the message in transit without waiting to confirm whether the recipient was available or successfully read it.
Core Protocol Comparison
8. High-Frequency Interview Questions
Q1: At which OSI layer does routing take place?
Answer: Layer 3 (Network Layer). Routers inspect Layer 3 IP packets to determine the optimal next-hop destination across interconnected networks.
Q2: What is the primary difference between a Network Switch and a Router?
Answer:
- A Switch operates at Layer 2 (Data Link Layer), forwarding traffic within the same local network using hardware MAC addresses.
- A Router operates at Layer 3 (Network Layer), routing traffic between different disparate networks using logical IP addresses.
Q3: What is the purpose and IP of the Loopback address?
Answer: The standard IPv4 loopback address is 127.0.0.1 (localhost). It enables local client-server software testing on the same host machine by routing packets internally through the network stack without transmitting data across external network interfaces.
Q4: At which layer do SSL/TLS and Data Compression operate in the OSI model?
Answer: Layer 6 (Presentation Layer), which handles data encryption, decryption, syntax conversion, and data compression before reaching the application.
Summary and Key Takeaways
- Layered Abstraction: The 7-Layer OSI model serves as the standard theoretical framework, while the 4-Layer TCP/IP model drives real-world internet architecture.
- Encapsulation Chain: Data flows downward on the sender host by adding headers (Data Segment Packet Frame Bits) and strips headers upward on the receiver.
- Network Hardware Placement: Switches operate at Layer 2 (Data Link / MAC), whereas Routers operate at Layer 3 (Network / IP).
- IPv4 Address Structure: Formatted as 32-bit addresses across 4 octets. Addresses contain a fixed Network portion and variable Host portion determined by the Subnet Mask.
- Usable Host Formula: Total usable hosts per subnet are calculated using , setting aside the first address (Network ID) and the last address (Broadcast ID).
- Transport Layer Trade-offs: TCP delivers guaranteed, ordered data through connection handshakes and acknowledgments; UDP prioritizes maximum transmission speed and low latency with zero connection overhead.