IPv4 & IPv6 Addressing

Layer 3 defines logical addressing and routing. Understanding IP headers, subnetting, and MTU is critical for network engineering.

1. The IPv4 Header

The standard IPv4 header is 20 bytes (without options). Routers process this header to make forwarding decisions based on the Destination IP.

Ver/IHL 0x45 1B
TOS DSCP 1B
Total Length len(pkt) 2B
ID/Flags/Frag Fragment Info 4B
TTL 64 1B
Proto TCP=6 1B
Source IP 192.168.1.10 4B
Dest IP 8.8.8.8 4B

2. Historical Context: Classful Addressing

Before CIDR (1993), IP addresses were divided into strict "Classes" based on the first octet. This wasted millions of addresses.

Subnetting & CIDR Cheat Sheet

CIDR (Classless Inter-Domain Routing) allows variable-length subnet masks (VLSM), breaking the rigid class structure.

RFC 1918 Private Address Space

These ranges are not routable on the public Internet. NAT (Network Address Translation) is required.

IPv6 Address Types

CIDR Subnet Mask Hosts Magic Number (Block Size)
/24 255.255.255.0 254 1 (in 3rd octet)
/25 255.255.255.128 126 128
/26 255.255.255.192 62 64
/27 255.255.255.224 30 32
/28 255.255.255.240 14 16
/29 255.255.255.248 6 8
/30 255.255.255.252 2 4 (Common for P2P links)
/32 255.255.255.255 1 1 (Host route)
Engineer's Notebook: The /31 Subnet

Historically, /30 was the standard for point-to-point links (4 IPs, 2 usable). Modern routers support /31 (2 IPs total, both usable as host addresses) to conserve address space on P2P links. RFC 3021.

3. MTU & Fragmentation

MTU (Maximum Transmission Unit) is typically 1500 bytes for Ethernet. If a packet is larger than the MTU:

  1. If DF (Don't Fragment) bit is Set: The router drops the packet and sends ICMP Type 3 Code 4 ("Fragmentation Needed").
  2. If DF is Clear: The router fragments the packet, increasing CPU load and overhead.

Path MTU Discovery (PMTUD) relies on ICMP. If you block all ICMP at your firewall, PMTUD breaks, causing "black hole" connections where small packets pass but large ones (like HTTP responses) fail.