IPv4/IPv6 Addressing, Subnetting & CIDR
---
1. IPv4 Addressing
An IPv4 address is a 32-bit number, typically written in dotted-decimal notation (4 octets separated by dots):
192.168.10.50 = 11000000.10101000.00001010.00110010
IPv4 Address Classes (Classful — Legacy)
| Class | First Octet Range | Default Subnet Mask | Network Bits | Host Bits | Typical Use |
|---|---|---|---|---|---|
| A | 1–126 | 255.0.0.0 (/8) | 8 | 24 | Large ISPs |
| B | 128–191 | 255.255.0.0 (/16) | 16 | 16 | Universities |
| C | 192–223 | 255.255.255.0 (/24) | 24 | 8 | Small offices |
| D | 224–239 | N/A | Multicast | — | Group messaging |
| E | 240–255 | N/A | Reserved | — | Research |
Special note: 127.x.x.x is reserved for loopback (localhost testing).
---
2. Subnet Mask and CIDR Notation
A subnet mask identifies which bits of an IP address belong to the network and which to the host:
- Binary
1bits = network portion - Binary
0bits = host portion
CIDR notation (Classless Inter-Domain Routing) uses /prefix-length to indicate the number of network bits:
192.168.1.0/24= subnet mask255.255.255.010.0.0.0/8= subnet mask255.0.0.0172.16.0.0/12= subnet mask255.240.0.0
---
3. Subnetting Worked Example
Problem: A company has the network 192.168.10.0/24 and needs 4 equal subnets. Find:
- The new subnet mask
- The subnet addresses
- The usable host range for each subnet
- The broadcast address for each subnet
Solution:
Step 1: We need 4 subnets. Since 2^n ≥ 4, we need n = 2 additional subnet bits.
- Original prefix:
/24→ New prefix:/24 + 2 = /26 - New subnet mask:
/26=255.255.255.192
Step 2: Block size = 256 − 192 = 64 (the last octet increments by 64 for each subnet)
Step 3: Calculate the 4 subnets:
| Subnet | Subnet Address | Usable Host Range | Broadcast Address | Usable Hosts |
|---|---|---|---|---|
| 1 | 192.168.10.0 | 192.168.10.1 – .62 | 192.168.10.63 | 62 |
| 2 | 192.168.10.64 | 192.168.10.65 – .126 | 192.168.10.127 | 62 |
| 3 | 192.168.10.128 | 192.168.10.129 – .190 | 192.168.10.191 | 62 |
| 4 | 192.168.10.192 | 192.168.10.193 – .254 | 192.168.10.255 | 62 |
Formula: Usable hosts per subnet = 2^(host bits) − 2 = 2^6 − 2 = 62 (Subtract 2 for network address and broadcast address)
Exam Tip: The subnetting formula: Hosts =2^h − 2where h = number of host bits. Subnets =2^swhere s = number of borrowed bits. Always subtract 2 from hosts (network ID + broadcast). Very common exam question — practice until it's automatic.
---
4. Private IP Address Ranges (RFC 1918)
| Range | CIDR | Use |
|---|---|---|
10.0.0.0 – 10.255.255.255 | 10.0.0.0/8 | Large enterprises |
172.16.0.0 – 172.31.255.255 | 172.16.0.0/12 | Medium enterprises |
192.168.0.0 – 192.168.255.255 | 192.168.0.0/16 | Home / small office |
Private addresses are not routable on the public internet — they require NAT to communicate outside their network.
---
5. IPv6 Addressing
IPv6 Address Format
128 bits, written as 8 groups of 4 hexadecimal digits separated by colons:
2001:0db8:85a3:0000:0000:8a2e:0370:7334
Simplification rules:
- Leading zeros: Remove within each group →
2001:db8:85a3:0:0:8a2e:370:7334 - Consecutive all-zero groups: Replace with
::(only once) →2001:db8:85a3::8a2e:370:7334
IPv6 Address Types
| Type | Prefix | Description |
|---|---|---|
| Global Unicast | 2000::/3 | Publicly routable (like public IPv4) |
| Link-Local | FE80::/10 | Only valid on local link (auto-assigned) |
| Loopback | ::1/128 | Equivalent to IPv4 127.0.0.1 |
| Multicast | FF00::/8 | One-to-many delivery |
| Unspecified | ::/128 | Unassigned address |
IPv6 has no broadcast — replaced by multicast (e.g., FF02::1 = all hosts on link).
SLAAC (Stateless Address Autoconfiguration)
IPv6 hosts can configure their own global address without DHCP:
- Generate a link-local address (FE80:: + EUI-64 from MAC)
- Receive Router Advertisement with network prefix from router
- Combine prefix + interface identifier → global unicast address
---
6. ARP (Address Resolution Protocol)
ARP maps a known IP address to an unknown MAC address within the same subnet.
| Step | Action |
|---|---|
| 1 | Host wants to send to IP 192.168.1.5 but doesn't know its MAC |
| 2 | Host broadcasts ARP Request: "Who has 192.168.1.5? Tell 192.168.1.10" |
| 3 | Host with IP 192.168.1.5 replies: "I have that IP, my MAC is XX:XX:XX:XX:XX:XX" |
| 4 | Requestor caches {IP → MAC} in its ARP cache |
| 5 | Sends frame using cached MAC address |
ARP Cache: Entries expire after a timeout (typically 2–20 minutes). arp -a displays the cache.
Gratuitous ARP: A host announces its own IP-to-MAC mapping proactively (used for duplicate detection and cache update after IP change).
---
Study Deep: Subnetting in Practice
- VLSM (Variable-Length Subnet Masking): Allows different subnets within the same network to have different sizes — assign /30 (2 hosts) to router-to-router links, /24 (254 hosts) to workstation LANs, etc. More efficient than equal-size subnetting.
- Route summarisation: Contiguous subnets can be summarised into a single routing table entry, reducing router memory and CPU usage — critical for scalability.
- IPv6 transition: Dual-stack (both IPv4 and IPv6 running simultaneously) and tunnelling (encapsulating IPv6 in IPv4 packets) are the main transition mechanisms. Most major internet sites now support both.