The Network Layer
Core Responsibilities of the Network Layer
The Network Layer is responsible for the end-to-end delivery of data packets from a source host to a destination host across multiple interconnected networks. Its primary weapons are Addressing (identifying where things are) and Routing (deciding the path).
IPv4: The Internet’s Foundation
An IPv4 address is a 32-bit identifier, usually written in dotted-decimal notation: 192.168.1.10.
Subnetting and CIDR
An IP address is split into two parts: the Network ID and the Host ID. The Subnet Mask defines where the split happens.
IP: 192.168.1.5 = 11000000.10101000.00000001.00000101
Mask: 255.255.255.0 = 11111111.11111111.11111111.00000000
└─────── Network ID ───┘ └─ Host ┘
CIDR Notation: 192.168.1.5/24 (The /24 signifies that the first 24 bits are the Network ID)
Specialized IP Addresses
| Address Range | Purpose |
|---|---|
127.0.0.1 |
Loopback (Localhost) |
10.x.x.x |
Private (LAN only) |
192.168.x.x |
Private (Home/SOHO LANs) |
255.255.255.255 |
Local Broadcast |
0.0.0.0 |
"Any" or "Default" route |
Transitioning to IPv6
We ran out of IPv4 addresses years ago. IPv6 is the solution, offering a massive $2^{128}$ address space.
| Feature | IPv4 | IPv6 |
|---|---|---|
| Address Length | 32-bit (~4.3 billion) | 128-bit (Virtually infinite) |
| Notation | Dotted Decimal | Hexadecimal (2001:0db8::1) |
| NAT | Mandatory for scaling | Optional/Discouraged |
| Header | Variable (20-60 bytes) | Fixed (40 bytes) for faster routing |
ICMP: The Diagnostic Tool
The Internet Control Message Protocol (ICMP) is used by devices to communicate networking errors or status information. Since it doesn't carry user application data, it is primarily a tool for network troubleshooting.
- Ping: Uses ICMP
Echo RequestandEcho Replyto test if a host is alive. - Traceroute: Uses ICMP
Time Exceededmessages by incrementing the IP header's TTL field to map the path to a destination.
Routing: Finding the Way
Routers maintain a Routing Table to decide which "Next Hop" a packet should be sent to.
- Direct Route: If the destination is on the same subnet, send it directly.
- Static Route: Manually configured path.
- Dynamic Route: Learned via protocols like OSPF or BGP.
- Default Gateway: If no specific route matches, send the packet here (usually the path to the ISP).
NAT: Network Address Translation
NAT allows an entire private network to share a single public IP address. The router tracks outgoing connections and maps them to unique ports to ensure incoming data reaches the correct internal machine.
Implementation Insights
The TTL (Time-To-Live) Guard
Every IP packet has a TTL field (usually 64 or 128). Every time a router forwards a packet, it decrements the TTL by 1. If it hits 0, the packet is killed. Without TTL, a simple routing loop (A thinks the path is through B, B thinks it's through A) would keep packets circling forever, eventually crashing the global internet.
IP Fragmentation: The Silent Performance Killer
If an IP packet is too large for a specific link, the router must "fragment" it into smaller pieces. The destination must then wait for all pieces to arrive before reassembling. If a single fragment is lost, the entire original packet must be retransmitted. Modern network design prefers "Path MTU Discovery" to ensure fragments are never created in the first place.