IP Addressing and Subnetting
IP Addressing and Subnetting¶
Overview¶
An IP (Internet Protocol) address is a logical address that uniquely identifies each device on a network. In this lesson, we will learn about the structure of IPv4 addresses, class-based addressing, subnet masks, CIDR notation, public/private IPs, and IPv6 basics. Subnetting is one of the most important skills in network design and management.
Difficulty: ⭐⭐ (Beginner-Intermediate)
Table of Contents¶
- IP Address Concept
- IPv4 Address Structure
- IP Address Classes
- Subnet Mask
- CIDR Notation
- Public IP vs Private IP
- IPv6 Basics
- Practice Problems
1. IP Address Concept¶
What is an IP Address?¶
┌─────────────────────────────────────────────────────────────────┐
│ IP Address │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Definition: Logical address that uniquely identifies each │
│ device on a network using Internet Protocol │
│ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ MAC Address vs IP Address │ │
│ │ │ │
│ │ MAC Address (Physical Address): │ │
│ │ ┌─────────────────────────────────────────────────┐ │ │
│ │ │ • Fixed in hardware (assigned during NIC mfg) │ │ │
│ │ │ • 48 bits (6 bytes) │ │ │
│ │ │ • Used for communication within same network │ │ │
│ │ │ • Example: 00:1A:2B:3C:4D:5E │ │ │
│ │ └─────────────────────────────────────────────────┘ │ │
│ │ │ │
│ │ IP Address (Logical Address): │ │
│ │ ┌─────────────────────────────────────────────────┐ │ │
│ │ │ • Assigned by software (changeable) │ │ │
│ │ │ • 32 bits (IPv4) or 128 bits (IPv6) │ │ │
│ │ │ • Used for inter-network communication │ │ │
│ │ │ • Example: 192.168.1.100 │ │ │
│ │ └─────────────────────────────────────────────────┘ │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ Analogy: │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ MAC Address = Social Security Number (fixed, unique) │ │
│ │ IP Address = Home Address (changeable, hierarchical) │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
IP Address Components¶
┌─────────────────────────────────────────────────────────────────┐
│ IP Address Components │
├─────────────────────────────────────────────────────────────────┤
│ │
│ IP Address = Network Portion + Host Portion │
│ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ 192.168.1.100 │ │
│ │ ├───────┤ ├─┤ │ │
│ │ Network Host │ │
│ │ Portion Portion │ │
│ │ │ │
│ │ Network Portion: Identifies which network │ │
│ │ Host Portion: Identifies specific device on network │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ Example - Comparison with Postal Address: │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ Seoul Gangnam-gu Yeoksam-dong 123 │ │
│ │ ├──────────────┤ ├────────────┤ │ │
│ │ Network Portion Host Portion │ │
│ │ (Region/Town) (Specific Location) │ │
│ │ │ │
│ │ 192.168.1 .100 │ │
│ │ ├───────────┤ ├──┤ │ │
│ │ Network ID Host ID │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ Important: Devices on same network must have same network ID │
│ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ 192.168.1.10 ─┐ │ │
│ │ 192.168.1.20 ─┼─► Same network (192.168.1.0) │ │
│ │ 192.168.1.30 ─┘ │ │
│ │ │ │
│ │ 192.168.2.10 ───► Different network (192.168.2.0) │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
2. IPv4 Address Structure¶
32-bit Address System¶
┌─────────────────────────────────────────────────────────────────┐
│ IPv4 Address Structure (32-bit) │
├─────────────────────────────────────────────────────────────────┤
│ │
│ IPv4 Address: 32 bits = 4 octets (8 bits each) │
│ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ Dotted Decimal Notation: │ │
│ │ │ │
│ │ 192 . 168 . 1 . 100 │ │
│ │ ↓ ↓ ↓ ↓ │ │
│ │ 11000000 10101000 00000001 01100100 │ │
│ │ ├──8bit──┤ ├──8bit──┤ ├──8bit──┤ ├──8bit──┤ │ │
│ │ Octet 1 Octet 2 Octet 3 Octet 4 │ │
│ │ │ │
│ │ Total 32 bits (4 bytes) │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ Each octet range: 0 ~ 255 (2^8 = 256 values) │
│ │
│ Decimal-Binary Conversion Example: │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ 192 = 128 + 64 = 2^7 + 2^6 = 11000000 │ │
│ │ 168 = 128 + 32 + 8 = 2^7 + 2^5 + 2^3 = 10101000 │ │
│ │ 1 = 2^0 = 00000001 │ │
│ │ 100 = 64 + 32 + 4 = 2^6 + 2^5 + 2^2 = 01100100 │ │
│ │ │ │
│ │ Bit positions and weights: │ │
│ │ ┌─────┬─────┬────┬────┬────┬────┬────┬────┐ │ │
│ │ │ 2^7 │ 2^6 │2^5 │2^4 │2^3 │2^2 │2^1 │2^0 │ │ │
│ │ ├─────┼─────┼────┼────┼────┼────┼────┼────┤ │ │
│ │ │ 128 │ 64 │ 32 │ 16 │ 8 │ 4 │ 2 │ 1 │ │ │
│ │ └─────┴─────┴────┴────┴────┴────┴────┴────┘ │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ Total IP addresses: 2^32 = 4,294,967,296 (~4.3 billion) │
│ │
└─────────────────────────────────────────────────────────────────┘
Special IP Addresses¶
┌─────────────────────────────────────────────────────────────────┐
│ Special IP Addresses │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌───────────────────┬─────────────────────────────────────┐ │
│ │ Address │ Purpose │ │
│ ├───────────────────┼─────────────────────────────────────┤ │
│ │ 0.0.0.0 │ All addresses (default route, DHCP) │ │
│ ├───────────────────┼─────────────────────────────────────┤ │
│ │ 127.0.0.1 │ Loopback (self, localhost) │ │
│ │ 127.0.0.0/8 │ Loopback range │ │
│ ├───────────────────┼─────────────────────────────────────┤ │
│ │ 255.255.255.255 │ Limited broadcast (local network) │ │
│ ├───────────────────┼─────────────────────────────────────┤ │
│ │ x.x.x.0 │ Network address (all host bits 0) │ │
│ ├───────────────────┼─────────────────────────────────────┤ │
│ │ x.x.x.255 │ Broadcast (all host bits 1) │ │
│ │ (varies by subnet)│ │ │
│ ├───────────────────┼─────────────────────────────────────┤ │
│ │ 169.254.0.0/16 │ APIPA (automatic private IP) │ │
│ │ │ Auto-assigned when DHCP fails │ │
│ └───────────────────┴─────────────────────────────────────┘ │
│ │
│ Network Address and Broadcast Address: │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ Network: 192.168.1.0/24 │ │
│ │ │ │
│ │ 192.168.1.0 ← Network address (cannot assign) │ │
│ │ 192.168.1.1 ← First usable host │ │
│ │ 192.168.1.2 │ │
│ │ ... │ │
│ │ 192.168.1.253 │ │
│ │ 192.168.1.254 ← Last usable host │ │
│ │ 192.168.1.255 ← Broadcast address (cannot assign) │ │
│ │ │ │
│ │ Usable hosts: 254 (256 - 2) │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
3. IP Address Classes¶
Classful Addressing¶
┌─────────────────────────────────────────────────────────────────┐
│ IP Address Classes (Classful Addressing) │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Early IP addresses classified into 5 classes (now use CIDR) │
│ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ Class A: │ │
│ │ ┌─┬───────────────────────────────────────────────────┐│ │
│ │ │0│ Network (7 bits) │ Host (24 bits) ││ │
│ │ └─┴───────────────────────────────────────────────────┘│ │
│ │ First bit: 0 │ │
│ │ Range: 1.0.0.0 ~ 126.255.255.255 │ │
│ │ Default mask: 255.0.0.0 (/8) │ │
│ │ Networks: 126 (2^7 - 2) │ │
│ │ Hosts: 16,777,214 (2^24 - 2) │ │
│ │ │ │
│ │ Class B: │ │
│ │ ┌──┬──────────────────┬────────────────────────────────┐│ │
│ │ │10│ Network (14 bits) │ Host (16 bits) ││ │
│ │ └──┴──────────────────┴────────────────────────────────┘│ │
│ │ First 2 bits: 10 │ │
│ │ Range: 128.0.0.0 ~ 191.255.255.255 │ │
│ │ Default mask: 255.255.0.0 (/16) │ │
│ │ Networks: 16,384 (2^14) │ │
│ │ Hosts: 65,534 (2^16 - 2) │ │
│ │ │ │
│ │ Class C: │ │
│ │ ┌───┬─────────────────────────┬────────────────────────┐│ │
│ │ │110│ Network (21 bits) │ Host (8 bits) ││ │
│ │ └───┴─────────────────────────┴────────────────────────┘│ │
│ │ First 3 bits: 110 │ │
│ │ Range: 192.0.0.0 ~ 223.255.255.255 │ │
│ │ Default mask: 255.255.255.0 (/24) │ │
│ │ Networks: 2,097,152 (2^21) │ │
│ │ Hosts: 254 (2^8 - 2) │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ Class D & E: │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ Class D (first 4 bits: 1110): │ │
│ │ Range: 224.0.0.0 ~ 239.255.255.255 │ │
│ │ Purpose: Multicast │ │
│ │ │ │
│ │ Class E (first 4 bits: 1111): │ │
│ │ Range: 240.0.0.0 ~ 255.255.255.255 │ │
│ │ Purpose: Reserved (research/experimental) │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
Class Identification Method¶
┌─────────────────────────────────────────────────────────────────┐
│ Class Identification Method │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Identify class by first octet: │
│ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ ┌─────────┬────────────────┬─────────────────────────┐│ │
│ │ │ Class │ First Octet │ First Bit Pattern ││ │
│ │ ├─────────┼────────────────┼─────────────────────────┤│ │
│ │ │ A │ 1 ~ 126 │ 0xxxxxxx ││ │
│ │ │ B │ 128 ~ 191 │ 10xxxxxx ││ │
│ │ │ C │ 192 ~ 223 │ 110xxxxx ││ │
│ │ │ D │ 224 ~ 239 │ 1110xxxx ││ │
│ │ │ E │ 240 ~ 255 │ 1111xxxx ││ │
│ │ └─────────┴────────────────┴─────────────────────────┘│ │
│ │ │ │
│ │ * 127 (0111 1111) is reserved for loopback │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ Examples: │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ 10.20.30.40 → First octet 10 → Class A │ │
│ │ 172.16.0.1 → First octet 172 → Class B │ │
│ │ 192.168.1.1 → First octet 192 → Class C │ │
│ │ 224.0.0.1 → First octet 224 → Class D (Multicast)│ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ Classful Problems: │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ 1. IP address waste │ │
│ │ - Class A: 16M hosts → mostly unused │ │
│ │ - Class C: 254 hosts → too few │ │
│ │ │ │
│ │ 2. Lack of flexibility │ │
│ │ - Difficult to create appropriately-sized networks │ │
│ │ │ │
│ │ Solution: CIDR (Classless Inter-Domain Routing) │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
Class Summary Table¶
| Class | First Octet | Network Bits | Host Bits | Networks | Hosts |
|---|---|---|---|---|---|
| A | 1-126 | 8 | 24 | 126 | 16,777,214 |
| B | 128-191 | 16 | 16 | 16,384 | 65,534 |
| C | 192-223 | 24 | 8 | 2,097,152 | 254 |
| D | 224-239 | - | - | Multicast | - |
| E | 240-255 | - | - | Reserved | - |
4. Subnet Mask¶
Subnet Mask Concept¶
┌─────────────────────────────────────────────────────────────────┐
│ Subnet Mask │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Definition: Value that separates network and host portions │
│ of an IP address │
│ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ IP Address: 192.168.1.100 │ │
│ │ Subnet Mask: 255.255.255.0 │ │
│ │ │ │
│ │ Binary representation: │ │
│ │ IP: 11000000.10101000.00000001.01100100 │ │
│ │ Mask: 11111111.11111111.11111111.00000000 │ │
│ │ ├─────── Network ────────┤├─ Host ─┤ │ │
│ │ (Consecutive 1s) (Consecutive 0s) │ │
│ │ │ │
│ │ Rules: │ │
│ │ - Subnet mask 1s → Network portion │ │
│ │ - Subnet mask 0s → Host portion │ │
│ │ - 1s must be consecutive (no 0s in between) │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ Calculate network address using AND operation: │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ IP Address: 192.168.1.100 │ │
│ │ 11000000.10101000.00000001.01100100 │ │
│ │ │ │
│ │ Subnet Mask: 255.255.255.0 │ │
│ │ 11111111.11111111.11111111.00000000 │ │
│ │ ──────────────────────────────────── │ │
│ │ AND Operation: 11000000.10101000.00000001.00000000 │ │
│ │ │ │
│ │ Network Address: 192.168.1.0 │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
Subnet Mask Values¶
┌─────────────────────────────────────────────────────────────────┐
│ Subnet Mask Value Table │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Valid subnet mask values (per octet): │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ ┌──────────┬──────────────┬──────────────────────────┐│ │
│ │ │ Decimal │ Binary │ Bit Count ││ │
│ │ ├──────────┼──────────────┼──────────────────────────┤│ │
│ │ │ 0 │ 00000000 │ 0 bits (all host) ││ │
│ │ │ 128 │ 10000000 │ 1 bit ││ │
│ │ │ 192 │ 11000000 │ 2 bits ││ │
│ │ │ 224 │ 11100000 │ 3 bits ││ │
│ │ │ 240 │ 11110000 │ 4 bits ││ │
│ │ │ 248 │ 11111000 │ 5 bits ││ │
│ │ │ 252 │ 11111100 │ 6 bits ││ │
│ │ │ 254 │ 11111110 │ 7 bits ││ │
│ │ │ 255 │ 11111111 │ 8 bits (all network) ││ │
│ │ └──────────┴──────────────┴──────────────────────────┘│ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ Default subnet masks: │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ ┌─────────┬─────────────────────┬────────────────────┐│ │
│ │ │ Class │ Subnet Mask │ CIDR Notation ││ │
│ │ ├─────────┼─────────────────────┼────────────────────┤│ │
│ │ │ A │ 255.0.0.0 │ /8 ││ │
│ │ │ B │ 255.255.0.0 │ /16 ││ │
│ │ │ C │ 255.255.255.0 │ /24 ││ │
│ │ └─────────┴─────────────────────┴────────────────────┘│ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
Subnetting Example¶
┌─────────────────────────────────────────────────────────────────┐
│ Subnetting Example │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Problem: Divide 192.168.1.0 network into 4 subnets │
│ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ Original network: 192.168.1.0/24 │ │
│ │ Required subnets: 4 │ │
│ │ │ │
│ │ Step 1: Calculate required bits │ │
│ │ 2^n >= 4 → n = 2 (need 2 bits) │ │
│ │ │ │
│ │ Step 2: New subnet mask │ │
│ │ /24 + 2 = /26 │ │
│ │ 255.255.255.192 (11111111.11111111.11111111.11000000) │ │
│ │ │ │
│ │ Step 3: Subnet size │ │
│ │ 256 - 192 = 64 (64 addresses per subnet) │ │
│ │ Usable hosts: 64 - 2 = 62 │ │
│ │ │ │
│ │ Step 4: Subnet ranges │ │
│ │ ┌──────────────────────────────────────────────────┐ │ │
│ │ │ Subnet Network Usable Range Broadcast││ │ │
│ │ ├──────────────────────────────────────────────────┤ │ │
│ │ │ Subnet 1 192.168.1.0 .1 ~ .62 .63 │ │ │
│ │ │ Subnet 2 192.168.1.64 .65 ~ .126 .127 │ │ │
│ │ │ Subnet 3 192.168.1.128 .129 ~ .190 .191 │ │ │
│ │ │ Subnet 4 192.168.1.192 .193 ~ .254 .255 │ │ │
│ │ └──────────────────────────────────────────────────┘ │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ Visual representation: │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ 192.168.1.0/24 (original) │ │
│ │ ├── 192.168.1.0/26 (Subnet 1: .0 ~ .63) │ │
│ │ ├── 192.168.1.64/26 (Subnet 2: .64 ~ .127) │ │
│ │ ├── 192.168.1.128/26 (Subnet 3: .128 ~ .191) │ │
│ │ └── 192.168.1.192/26 (Subnet 4: .192 ~ .255) │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
5. CIDR Notation¶
CIDR (Classless Inter-Domain Routing)¶
┌─────────────────────────────────────────────────────────────────┐
│ CIDR Notation │
├─────────────────────────────────────────────────────────────────┤
│ │
│ CIDR: Classless Inter-Domain Routing │
│ Subnet mask represented by number of bits with slash (/)│
│ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ 192.168.1.0/24 │ │
│ │ ├──────────┤├─┤ │ │
│ │ IP Address Prefix Length (network bit count) │ │
│ │ │ │
│ │ /24 = 24 network bits │ │
│ │ = 255.255.255.0 │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ CIDR notation and subnet mask correspondence: │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ ┌────────┬─────────────────────┬───────────────────┐ │ │
│ │ │ CIDR │ Subnet Mask │ Host Count │ │ │
│ │ ├────────┼─────────────────────┼───────────────────┤ │ │
│ │ │ /8 │ 255.0.0.0 │ 16,777,214 │ │ │
│ │ │ /16 │ 255.255.0.0 │ 65,534 │ │ │
│ │ │ /20 │ 255.255.240.0 │ 4,094 │ │ │
│ │ │ /21 │ 255.255.248.0 │ 2,046 │ │ │
│ │ │ /22 │ 255.255.252.0 │ 1,022 │ │ │
│ │ │ /23 │ 255.255.254.0 │ 510 │ │ │
│ │ │ /24 │ 255.255.255.0 │ 254 │ │ │
│ │ │ /25 │ 255.255.255.128 │ 126 │ │ │
│ │ │ /26 │ 255.255.255.192 │ 62 │ │ │
│ │ │ /27 │ 255.255.255.224 │ 30 │ │ │
│ │ │ /28 │ 255.255.255.240 │ 14 │ │ │
│ │ │ /29 │ 255.255.255.248 │ 6 │ │ │
│ │ │ /30 │ 255.255.255.252 │ 2 │ │ │
│ │ │ /31 │ 255.255.255.254 │ 2 (P2P link) │ │ │
│ │ │ /32 │ 255.255.255.255 │ 1 (single host) │ │ │
│ │ └────────┴─────────────────────┴───────────────────┘ │ │
│ │ │ │
│ │ Host count = 2^(32-prefix) - 2 │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
CIDR Calculation Examples¶
┌─────────────────────────────────────────────────────────────────┐
│ CIDR Calculation Examples │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Example 1: Calculate network info for 172.16.50.25/20 │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ IP: 172.16.50.25 │ │
│ │ 172 . 16 . 50 . 25 │ │
│ │ 10101100.00010000.00110010.00011001 │ │
│ │ │ │
│ │ /20 mask: │ │
│ │ 11111111.11111111.11110000.00000000 │ │
│ │ 255.255.240.0 │ │
│ │ │ │
│ │ AND operation (network address): │ │
│ │ 10101100.00010000.00110000.00000000 │ │
│ │ = 172.16.48.0 │ │
│ │ │ │
│ │ Broadcast address (all host bits 1): │ │
│ │ 10101100.00010000.00111111.11111111 │ │
│ │ = 172.16.63.255 │ │
│ │ │ │
│ │ Results: │ │
│ │ - Network address: 172.16.48.0/20 │ │
│ │ - First host: 172.16.48.1 │ │
│ │ - Last host: 172.16.63.254 │ │
│ │ - Broadcast: 172.16.63.255 │ │
│ │ - Host count: 2^12 - 2 = 4,094 │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ Example 2: Choose appropriate CIDR for 500 hosts needed │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ Required hosts: 500 │ │
│ │ │ │
│ │ 2^n - 2 >= 500 │ │
│ │ 2^9 - 2 = 510 >= 500 ✓ │ │
│ │ 2^8 - 2 = 254 < 500 ✗ │ │
│ │ │ │
│ │ Host bits: 9 │ │
│ │ Network bits: 32 - 9 = 23 │ │
│ │ CIDR: /23 │ │
│ │ Subnet mask: 255.255.254.0 │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
CIDR Aggregation (Supernetting)¶
┌─────────────────────────────────────────────────────────────────┐
│ CIDR Aggregation (Supernetting) │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Summarize multiple networks into one larger network │
│ (reduces routing table size) │
│ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ Before aggregation: │ │
│ │ 192.168.0.0/24 (192.168.0.0 ~ 192.168.0.255) │ │
│ │ 192.168.1.0/24 (192.168.1.0 ~ 192.168.1.255) │ │
│ │ 192.168.2.0/24 (192.168.2.0 ~ 192.168.2.255) │ │
│ │ 192.168.3.0/24 (192.168.3.0 ~ 192.168.3.255) │ │
│ │ │ │
│ │ After aggregation: │ │
│ │ 192.168.0.0/22 (192.168.0.0 ~ 192.168.3.255) │ │
│ │ │ │
│ │ Binary verification: │ │
│ │ 192.168.0.x = 11000000.10101000.000000xx.xxxxxxxx │ │
│ │ 192.168.1.x = 11000000.10101000.000001xx.xxxxxxxx │ │
│ │ 192.168.2.x = 11000000.10101000.000010xx.xxxxxxxx │ │
│ │ 192.168.3.x = 11000000.10101000.000011xx.xxxxxxxx │ │
│ │ └───── First 22 bits identical ─────┘ │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ Advantages: │
│ - Reduced routing table size │
│ - Reduced routing update traffic │
│ - Router memory savings │
│ │
└─────────────────────────────────────────────────────────────────┘
6. Public IP vs Private IP¶
Public and Private IP¶
┌─────────────────────────────────────────────────────────────────┐
│ Public IP vs Private IP │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Public IP: │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ • Unique address that can communicate directly on │ │
│ │ the Internet │ │
│ │ • Assigned by ISP (paid) │ │
│ │ • Globally unique │ │
│ │ • Routable on the Internet │ │
│ │ │ │
│ │ Examples: 8.8.8.8 (Google DNS), 1.1.1.1 (Cloudflare) │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ Private IP: │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ • Used only within internal networks │ │
│ │ • Not routable directly on the Internet │ │
│ │ • Free to use │ │
│ │ • Internet access through NAT │ │
│ │ • Can be duplicated in different networks │ │
│ │ │ │
│ │ RFC 1918 Private IP Ranges: │ │
│ │ ┌──────────────────────────────────────────────────┐ │ │
│ │ │ Class │ Range │ CIDR │ │ │
│ │ ├─────────┼──────────────────────────┼────────────┤ │ │
│ │ │ A │ 10.0.0.0 ~ 10.255.255.255│ /8 │ │ │
│ │ │ B │ 172.16.0.0 ~ 172.31.255.255│ /12 │ │ │
│ │ │ C │ 192.168.0.0 ~192.168.255.255│ /16 │ │ │
│ │ └──────────────────────────────────────────────────┘ │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
NAT (Network Address Translation)¶
┌─────────────────────────────────────────────────────────────────┐
│ NAT (Network Address Translation) │
├─────────────────────────────────────────────────────────────────┤
│ │
│ NAT: Translates private IP to public IP for Internet comm │
│ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ Private Network Internet │ │
│ │ │ │
│ │ ┌───────────┐ │ │
│ │ │ PC1 │ 192.168.1.10 │ │
│ │ └─────┬─────┘ │ │
│ │ │ │ │
│ │ ┌───────────┐ │ │
│ │ │ PC2 │ 192.168.1.20 │ │
│ │ └─────┬─────┘ │ │
│ │ │ │ │
│ │ ┌─────┴─────┐ ┌─────────────┐ ┌───────────────┐ │ │
│ │ │ │ │ │ │ │ │ │
│ │ │ Switch ├───┤ Router ├────┤ Internet │ │ │
│ │ │ │ │ (NAT) │ │ │ │ │
│ │ └───────────┘ └─────────────┘ └───────────────┘ │ │
│ │ │ │ │
│ │ Inside: 192.168.1.1 │ │
│ │ Outside: 203.0.113.5 (Public IP) │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ NAT operation: │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ Outgoing packet: │ │
│ │ Source: 192.168.1.10:5000 → 203.0.113.5:40000 │ │
│ │ Dest: 8.8.8.8:53 (no change) │ │
│ │ │ │
│ │ Incoming packet: │ │
│ │ Source: 8.8.8.8:53 (no change) │ │
│ │ Dest: 203.0.113.5:40000 → 192.168.1.10:5000 │ │
│ │ │ │
│ │ NAT table: │ │
│ │ ┌─────────────────────────┬─────────────────────────┐ │ │
│ │ │ Inside Address │ Outside Address │ │ │
│ │ ├─────────────────────────┼─────────────────────────┤ │ │
│ │ │ 192.168.1.10:5000 │ 203.0.113.5:40000 │ │ │
│ │ │ 192.168.1.20:5001 │ 203.0.113.5:40001 │ │ │
│ │ └─────────────────────────┴─────────────────────────┘ │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ NAT Types: │
│ • Static NAT: 1:1 mapping (fixed) │
│ • Dynamic NAT: N:N mapping (assigned from pool) │
│ • PAT (Port Address Translation): N:1 mapping (port-based) │
│ │
└─────────────────────────────────────────────────────────────────┘
Other Special IP Ranges¶
┌─────────────────────────────────────────────────────────────────┐
│ Other Special IP Ranges │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌────────────────────┬─────────────────────────────────────┐ │
│ │ Range │ Purpose │ │
│ ├────────────────────┼─────────────────────────────────────┤ │
│ │ 0.0.0.0/8 │ This Network │ │
│ │ 127.0.0.0/8 │ Loopback │ │
│ │ 169.254.0.0/16 │ APIPA (Link-Local) │ │
│ │ 224.0.0.0/4 │ Multicast │ │
│ │ 240.0.0.0/4 │ Reserved │ │
│ │ 255.255.255.255/32 │ Limited broadcast │ │
│ │ 100.64.0.0/10 │ Carrier-Grade NAT (CGN) │ │
│ │ 192.0.0.0/24 │ IETF Protocol Assignments │ │
│ │ 192.0.2.0/24 │ Documentation (TEST-NET-1) │ │
│ │ 198.51.100.0/24 │ Documentation (TEST-NET-2) │ │
│ │ 203.0.113.0/24 │ Documentation (TEST-NET-3) │ │
│ └────────────────────┴─────────────────────────────────────┘ │
│ │
│ APIPA (Automatic Private IP Addressing): │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ • Auto-assigned when DHCP server not found │ │
│ │ • Range: 169.254.1.0 ~ 169.254.254.255 │ │
│ │ • Can only communicate with APIPA hosts on same net │ │
│ │ • No Internet access │ │
│ │ │ │
│ │ If you see APIPA address → Check DHCP problem! │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
7. IPv6 Basics¶
IPv6 Background¶
┌─────────────────────────────────────────────────────────────────┐
│ IPv6 Background │
├─────────────────────────────────────────────────────────────────┤
│ │
│ IPv4 Limitations: │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ 1. Address Exhaustion │ │
│ │ - IPv4: ~4.3 billion addresses │ │
│ │ - World population: 8 billion + billions of IoT │ │
│ │ - 2011: IANA IPv4 addresses exhausted │ │
│ │ - 2019: RIPE NCC (Europe) addresses exhausted │ │
│ │ │ │
│ │ 2. NAT Complexity │ │
│ │ - Difficult end-to-end connectivity │ │
│ │ - Some application compatibility issues │ │
│ │ - Complex configuration and management │ │
│ │ │ │
│ │ 3. Lack of Security Features │ │
│ │ - IPsec is optional │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ IPv6 Features: │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ 1. Huge Address Space │ │
│ │ 128 bits = 2^128 addresses │ │
│ │ ≈ 340 undecillion (340 x 10^36) │ │
│ │ = 6.5 x 10^23 per m² of Earth's surface │ │
│ │ │ │
│ │ 2. Auto-configuration (SLAAC) │ │
│ │ - Auto address config without DHCP │ │
│ │ │ │
│ │ 3. Simplified Header │ │
│ │ - Fixed 40-byte header │ │
│ │ - Extension headers for options │ │
│ │ │ │
│ │ 4. Built-in IPsec Support │ │
│ │ │ │
│ │ 5. No Broadcast │ │
│ │ - Replaced with multicast and anycast │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
IPv6 Address Structure¶
┌─────────────────────────────────────────────────────────────────┐
│ IPv6 Address Structure │
├─────────────────────────────────────────────────────────────────┤
│ │
│ 128 bits = 8 groups of 16 bits (hexadecimal notation) │
│ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ Full notation: │ │
│ │ 2001:0db8:0000:0000:0000:0000:0000:0001 │ │
│ │ ├──┤├──┤├──┤├──┤├──┤├──┤├──┤├──┤ │ │
│ │ 8 groups of 16 bits each (colon-separated) │ │
│ │ │ │
│ │ Abbreviation rules: │ │
│ │ 1. Leading zeros in each group can be omitted │ │
│ │ 0db8 → db8 │ │
│ │ 0001 → 1 │ │
│ │ │ │
│ │ 2. Consecutive zero groups can be abbreviated as :: │ │
│ │ once only │ │
│ │ :0000:0000:0000: → :: │ │
│ │ │ │
│ │ Abbreviated result: │ │
│ │ 2001:0db8:0000:0000:0000:0000:0000:0001 │ │
│ │ → 2001:db8::1 │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ Abbreviation examples: │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ fe80:0000:0000:0000:0000:0000:0000:0001 │ │
│ │ → fe80::1 │ │
│ │ │ │
│ │ 2001:0db8:0001:0000:0000:0000:0000:0001 │ │
│ │ → 2001:db8:1::1 │ │
│ │ │ │
│ │ 0000:0000:0000:0000:0000:0000:0000:0001 │ │
│ │ → ::1 (loopback) │ │
│ │ │ │
│ │ 0000:0000:0000:0000:0000:0000:0000:0000 │ │
│ │ → :: (unspecified address) │ │
│ │ │ │
│ │ Warning: :: can only be used once per address! │ │
│ │ 2001::1::2 (incorrect) │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
IPv6 Address Types¶
┌─────────────────────────────────────────────────────────────────┐
│ IPv6 Address Types │
├─────────────────────────────────────────────────────────────────┤
│ │
│ 1. Unicast: │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ Global Unicast: │ │
│ │ - Globally unique address on the Internet │ │
│ │ - 2000::/3 range (2000:: ~ 3fff::) │ │
│ │ - Similar to IPv4 public IP │ │
│ │ │ │
│ │ Link-Local: │ │
│ │ - fe80::/10 range │ │
│ │ - Valid only on same link │ │
│ │ - Auto-generated │ │
│ │ - Does not cross routers │ │
│ │ │ │
│ │ Unique Local (ULA): │ │
│ │ - fc00::/7 range │ │
│ │ - Similar to IPv4 private IP │ │
│ │ - Not routable on Internet │ │
│ │ │ │
│ │ Loopback: ::1 │ │
│ │ - Same as IPv4 127.0.0.1 │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ 2. Multicast: │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ - ff00::/8 range │ │
│ │ - Sent to all devices in a group │ │
│ │ - Replaces IPv4 broadcast functionality │ │
│ │ │ │
│ │ Common multicast addresses: │ │
│ │ ff02::1 - All Nodes │ │
│ │ ff02::2 - All Routers │ │
│ │ ff02::fb - mDNS │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ 3. Anycast: │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ - Same address assigned to multiple nodes │ │
│ │ - Routed to nearest node │ │
│ │ - Used for load balancing, DNS, etc. │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ * IPv6 has no broadcast! │
│ │
└─────────────────────────────────────────────────────────────────┘
IPv4 vs IPv6 Comparison¶
┌─────────────────────────────────────────────────────────────────┐
│ IPv4 vs IPv6 Comparison │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────┬───────────────┬───────────────────┐ │
│ │ Item │ IPv4 │ IPv6 │ │
│ ├─────────────────────┼───────────────┼───────────────────┤ │
│ │ Address Length │ 32 bits │ 128 bits │ │
│ │ Address Count │ ~4.3 billion│ ~340 undecillion│ │
│ │ Notation │ Dotted dec │ Colon hex │ │
│ │ Example │ 192.168.1.1 │ 2001:db8::1 │ │
│ │ Header Size │ 20-60 bytes │ 40 bytes (fixed)│ │
│ │ Checksum │ Yes │ No │ │
│ │ Broadcast │ Yes │ No │ │
│ │ Multicast │ Optional │ Mandatory │ │
│ │ IPsec │ Optional │ Built-in │ │
│ │ Auto-config │ DHCP │ SLAAC/DHCPv6 │ │
│ │ Fragmentation │ At routers │ Source only │ │
│ │ ARP │ Uses │ NDP replaces │ │
│ └─────────────────────┴───────────────┴───────────────────┘ │
│ │
│ NDP (Neighbor Discovery Protocol): │
│ - Replaces ARP, ICMP Router Discovery, etc. in IPv6 │
│ - Based on ICMPv6 │
│ - Router discovery, auto-config, duplicate address detection │
│ │
└─────────────────────────────────────────────────────────────────┘
8. Practice Problems¶
Basic Problems¶
1. Identify the class of the following IP addresses: - (a) 10.0.0.1 - (b) 172.16.0.1 - (c) 192.168.1.1 - (d) 224.0.0.1
2. What is the CIDR notation for subnet mask 255.255.255.192?
3. For the 192.168.1.0/24 network, find the range and count of usable host IP addresses.
4. Which of the following is NOT a private IP address? - (a) 10.255.255.255 - (b) 172.32.0.1 - (c) 192.168.0.1 - (d) 172.16.0.1
Applied Problems¶
5. Calculate the network address, broadcast address, first/last host addresses for 172.16.50.100/20.
6. A company has 200 PCs. Choose an appropriate subnet mask and CIDR from the 192.168.10.0 network.
7. When subnetting 10.0.0.0/8 network to /16, how many subnets are created?
Advanced Problems¶
8. Aggregate (Supernet) the following 4 subnets into one: - 192.168.4.0/24 - 192.168.5.0/24 - 192.168.6.0/24 - 192.168.7.0/24
9. Convert IPv6 address 2001:0db8:0000:0000:0000:ff00:0042:8329 to abbreviated form.
10. Explain why NAT is needed and the advantages/disadvantages of NAT.
Answers
**1.** - (a) 10.0.0.1 - Class A - (b) 172.16.0.1 - Class B - (c) 192.168.1.1 - Class C - (d) 224.0.0.1 - Class D (Multicast) **2.** /26 (255.255.255.192 = 11111111.11111111.11111111.11000000 = 26 ones) **3.** - Range: 192.168.1.1 ~ 192.168.1.254 - Count: 254 (2^8 - 2) **4.** (b) 172.32.0.1 (Private IP range: 172.16.0.0 ~ 172.31.255.255) **5.** - IP: 172.16.50.100 - /20 mask: 255.255.240.0 - Network address: 172.16.48.0 - Broadcast address: 172.16.63.255 - First host: 172.16.48.1 - Last host: 172.16.63.254 **6.** - 200 PCs needed - 2^8 - 2 = 254 >= 200 ✓ - Subnet mask: 255.255.255.0 - CIDR: /24 **7.** - /8 → /16: Borrowed 16 - 8 = 8 bits - Subnet count: 2^8 = 256 **8.** - 192.168.4.0 = 11000000.10101000.00000100.00000000 - 192.168.5.0 = 11000000.10101000.00000101.00000000 - 192.168.6.0 = 11000000.10101000.00000110.00000000 - 192.168.7.0 = 11000000.10101000.00000111.00000000 - First 22 bits identical: 192.168.4.0/22 **9.** - 2001:0db8:0000:0000:0000:ff00:0042:8329 - Remove leading zeros: 2001:db8:0:0:0:ff00:42:8329 - Abbreviate consecutive zeros: 2001:db8::ff00:42:8329 **10.** - Need: Solve IPv4 address exhaustion, protect private networks - Advantages: IP address conservation, hide internal network (security) - Disadvantages: Difficult end-to-end connectivity, some protocol compatibility issues, configuration complexityNext Steps¶
- 07_Subnetting_Practice.md - Subnetting Calculation Practice
References¶
- TCP/IP Illustrated (W. Richard Stevens)
- RFC 791: Internet Protocol
- RFC 1918: Private Address Space
- RFC 8200: IPv6
- IANA IPv4 Address Space