Loading W Code...
IPv4, IPv6 & Subnetting
IP addresses are unique identifiers for devices on a network. Understanding IP addressing and subnetting is essential for network design.
32-bit Address Space
IPv4 uses 32-bit addresses, providing approximately 4.3 billion unique addresses. Written in dotted decimal notation (e.g., 192.168.1.1).
// IPv4 Address Format (32 bits = 4 octets)
┌─────────┬─────────┬─────────┬─────────┐
│ Octet 1 │ Octet 2 │ Octet 3 │ Octet 4 │
│ 8 bits │ 8 bits │ 8 bits │ 8 bits │
└─────────┴─────────┴─────────┴─────────┘
Example: 192.168.1.1
Binary: 11000000.10101000.00000001.00000001
// IPv4 Classes (Classful Addressing)
┌───────┬─────────────┬─────────────────┬──────────────────┬─────────────┐
│ Class │ First Octet │ Range │ Default Mask │ Networks │
├───────┼─────────────┼─────────────────┼──────────────────┼─────────────┤
│ A │ 0xxxxxxx │ 1.0.0.0 - │ 255.0.0.0 (/8) │ 126 nets │
│ │ (1-126) │ 126.255.255.255 │ │ 16M hosts │
├───────┼─────────────┼─────────────────┼──────────────────┼─────────────┤
│ B │ 10xxxxxx │ 128.0.0.0 - │ 255.255.0.0 (/16)│ 16K nets │
│ │ (128-191) │ 191.255.255.255 │ │ 65K hosts │
├───────┼─────────────┼─────────────────┼──────────────────┼─────────────┤
│ C │ 110xxxxx │ 192.0.0.0 - │ 255.255.255.0 │ 2M nets │
│ │ (192-223) │ 223.255.255.255 │ (/24) │ 254 hosts │
├───────┼─────────────┼─────────────────┼──────────────────┼─────────────┤
│ D │ 1110xxxx │ 224.0.0.0 - │ N/A │ Multicast │
│ │ (224-239) │ 239.255.255.255 │ │ │
├───────┼─────────────┼─────────────────┼──────────────────┼─────────────┤
│ E │ 1111xxxx │ 240.0.0.0 - │ N/A │ Reserved │
│ │ (240-255) │ 255.255.255.255 │ │ │
└───────┴─────────────┴─────────────────┴──────────────────┴─────────────┘// Private IP Ranges (Not routable on Internet)
┌───────┬─────────────────────────────────┬───────────────┬────────────┐
│ Class │ Range │ CIDR │ Addresses │
├───────┼─────────────────────────────────┼───────────────┼────────────┤
│ A │ 10.0.0.0 - 10.255.255.255 │ 10.0.0.0/8 │ 16,777,216 │
│ B │ 172.16.0.0 - 172.31.255.255 │ 172.16.0.0/12 │ 1,048,576 │
│ C │ 192.168.0.0 - 192.168.255.255 │ 192.168.0.0/16│ 65,536 │
└───────┴─────────────────────────────────┴───────────────┴────────────┘
// Special IP Addresses
127.0.0.0/8 → Loopback (localhost)
0.0.0.0 → Default route / All interfaces
255.255.255.255 → Broadcast
169.254.0.0/16 → APIPA (Auto-configured)
224.0.0.0/4 → MulticastSubnetting divides a network into smaller subnetworks. CIDR (Classless Inter-Domain Routing) uses slash notation for flexible subnet masks.
// CIDR Notation
┌───────┬───────────────────┬────────────────┬───────────┐
│ CIDR │ Subnet Mask │ Hosts │ Wildcard │
├───────┼───────────────────┼────────────────┼───────────┤
│ /8 │ 255.0.0.0 │ 16,777,214 │ 0.255.255.255 │
│ /16 │ 255.255.0.0 │ 65,534 │ 0.0.255.255 │
│ /24 │ 255.255.255.0 │ 254 │ 0.0.0.255 │
│ /25 │ 255.255.255.128 │ 126 │ 0.0.0.127 │
│ /26 │ 255.255.255.192 │ 62 │ 0.0.0.63 │
│ /27 │ 255.255.255.224 │ 30 │ 0.0.0.31 │
│ /28 │ 255.255.255.240 │ 14 │ 0.0.0.15 │
│ /29 │ 255.255.255.248 │ 6 │ 0.0.0.7 │
│ /30 │ 255.255.255.252 │ 2 │ 0.0.0.3 │
│ /32 │ 255.255.255.255 │ 1 (host route) │ 0.0.0.0 │
└───────┴───────────────────┴────────────────┴───────────┘
// Subnetting Formula
Number of Subnets = 2^n (n = borrowed bits)
Hosts per Subnet = 2^h - 2 (h = host bits, -2 for network & broadcast)Original: 192.168.1.0/24 (256 addresses, 254 usable)
Need: 4 subnets → borrow 2 bits → /26
Subnet 1: 192.168.1.0/26 (192.168.1.1 - 192.168.1.62)
Subnet 2: 192.168.1.64/26 (192.168.1.65 - 192.168.1.126)
Subnet 3: 192.168.1.128/26 (192.168.1.129 - 192.168.1.190)
Subnet 4: 192.168.1.192/26 (192.168.1.193 - 192.168.1.254)
Each subnet: 64 addresses, 62 usable hosts128-bit Address Space
IPv6 uses 128-bit addresses, providing 340 undecillion unique addresses. Written in hexadecimal with colons (e.g., 2001:0db8:85a3::8a2e:0370:7334).
// IPv6 Address Format (128 bits = 8 groups of 16 bits)
Full: 2001:0db8:85a3:0000:0000:8a2e:0370:7334
Compressed: 2001:db8:85a3::8a2e:370:7334
// IPv6 Shortening Rules:
1. Leading zeros can be omitted: 0db8 → db8
2. Consecutive zero groups → :: (only once)
// IPv6 Address Types
┌──────────────────┬──────────────────┬──────────────────────┐
│ Type │ Prefix │ Description │
├──────────────────┼──────────────────┼──────────────────────┤
│ Global Unicast │ 2000::/3 │ Public routable │
│ Link-Local │ fe80::/10 │ Same link only │
│ Unique Local │ fc00::/7 │ Private (like RFC1918)│
│ Multicast │ ff00::/8 │ One-to-many │
│ Loopback │ ::1/128 │ Localhost │
│ Unspecified │ ::/128 │ No address │
└──────────────────┴──────────────────┴──────────────────────┘
// IPv4 vs IPv6 Comparison
┌─────────────────┬────────────────────┬────────────────────┐
│ Feature │ IPv4 │ IPv6 │
├─────────────────┼────────────────────┼────────────────────┤
│ Address Size │ 32 bits │ 128 bits │
│ Address Format │ Dotted decimal │ Hexadecimal │
│ Example │ 192.168.1.1 │ 2001:db8::1 │
│ Total Addresses │ ~4.3 billion │ 340 undecillion │
│ NAT Required │ Yes (commonly) │ No │
│ Configuration │ Manual/DHCP │ SLAAC/DHCPv6 │
│ Header Size │ 20-60 bytes │ 40 bytes (fixed) │
│ Broadcast │ Yes │ No (multicast) │
└─────────────────┴────────────────────┴────────────────────┘NAT translates private IP addresses to public IP addresses, allowing multiple devices to share a single public IP.
// NAT Types
┌─────────────┬──────────────────────────────────────────┐
│ Type │ Description │
├─────────────┼──────────────────────────────────────────┤
│ Static NAT │ 1:1 mapping (private ↔ public) │
│ Dynamic NAT │ Pool of public IPs │
│ PAT/NAPT │ Port-based (many:1), most common │
└─────────────┴──────────────────────────────────────────┘
// PAT Example (Port Address Translation)
Inside Local Inside Global Outside
192.168.1.10:5001 203.0.113.5:10001 8.8.8.8:443
192.168.1.11:5002 203.0.113.5:10002 8.8.8.8:443
192.168.1.12:5003 203.0.113.5:10003 8.8.4.4:80Know IPv4 classes and their default subnet masks
Be able to subnet a network given requirements (# of subnets or hosts)
Understand private IP ranges (10.x.x.x, 172.16-31.x.x, 192.168.x.x)
Know IPv6 address types and compression rules
Understand NAT types: Static, Dynamic, PAT