IP & Subnetting
Learn the mechanics of IP addressing and subnetting. Explore IPv4 vs. IPv6, RFC 1918 private ranges, CIDR notation, and step-by-step subnet calculations.
What is an IP Address?
An IP (Internet Protocol) Address is a logical numerical label assigned to every device connected to a computer network that uses the Internet Protocol for communication. Operating at Layer 3 (Network Layer) of the OSI model, an IP address serves two primary functions: host or network interface identification, and location addressing (providing the logical path to reach the device).
Unlike physical MAC addresses, which are static and burned into hardware, IP addresses are logical and assigned dynamically via software (such as DHCP) or configured statically. This allows devices to move across different networks and maintain communication.
IPv4 vs. IPv6 Comparison
Due to the explosive growth of the Internet, the original addressing system (IPv4) ran out of unassigned addresses, prompting the development of the next-generation protocol (IPv6):
| Aspect | IPv4 (Internet Protocol Version 4) | IPv6 (Internet Protocol Version 6) |
|---|---|---|
| Address Size | 32 bits. | 128 bits. |
| Address Format | Four decimal octets separated by dots (e.g., 192.168.1.1). | Eight hexadecimal groups separated by colons (e.g., 2001:db8::ff00:42:8329). |
| Total Addresses | \(2^{32}\) (~4.3 Billion addresses). | \(2^{128}\) (~340 Undecillion addressesโeffectively infinite). |
| Configuration | Manual or dynamic assignment via DHCP. | Supports SLAAC (Stateless Address Autoconfiguration) and DHCPv6. |
| Security (IPsec) | Optional security add-on. | Built-in security support as part of the core standard. |
Classful Addressing & Private IP Ranges (RFC 1918)
In the early days of the Internet, IPv4 addresses were divided into five distinct **Classes** based on the first octet, defining how many bits belonged to the network portion versus the host portion:
- Class A: Octet range 1โ126. Subnet mask `255.0.0.0` (/8). Designed for massive networks (16.7 million hosts per network).
- Class B: Octet range 128โ191. Subnet mask `255.255.0.0` (/16). Designed for medium-large networks (65,536 hosts per network).
- Class C: Octet range 192โ223. Subnet mask `255.255.255.0` (/24). Designed for small networks (254 hosts per network).
- Class D: Octet range 224โ239. Reserved for multicast traffic.
- Class E: Octet range 240โ254. Reserved for experimental and research use.
Loopback Address: The IP range `127.0.0.0/8` is reserved for loopback testing. The address 127.0.0.1 refers to your own local computer ("localhost"). Private IP Address Ranges (RFC 1918)
To slow down the exhaustion of IPv4 addresses, **RFC 1918** reserved specific ranges of IP addresses for private internal networks. These private addresses are not routable on the public Internet. Internal routers and firewalls translate them to a single public IP address using NAT before sending traffic to the Internet:
- Class A Private Range:
10.0.0.0to10.255.255.255 - Class B Private Range:
172.16.0.0to172.31.255.255 - Class C Private Range:
192.168.0.0to192.168.255.255
Subnetting Mathematics: CIDR and Calculations
Classful addressing was highly inefficient. If an organization needed 300 hosts, they were forced to take a Class B network block (65,536 IPs), wasting over 65,000 addresses. To solve this, the industry introduced **CIDR (Classless Inter-Domain Routing)** and **Subnetting**โthe mathematical process of splitting a single large network block into smaller, custom-sized sub-networks (subnets).
A subnet mask is a 32-bit sequence of 1s followed by 0s. The 1s represent the **Network portion** of the address, and the 0s represent the **Host portion**. In CIDR notation, the subnet mask is written as a slash followed by the number of 1-bits (e.g., `/24` represents a subnet mask of 24 ones: `255.255.255.0`).
Subnet Calculation Formula
To calculate the sizes of subnets, we use powers of 2:
- Total IP Addresses in a subnet: \(2^{(32 - n)}\), where \(n\) is the CIDR prefix number.
- Usable Host Addresses in a subnet: \(2^{(32 - n)} - 2\). We must subtract two because the **first address** is reserved as the **Network Address** (identifying the subnet), and the **last address** is reserved as the **Broadcast Address** (used to send packets to all hosts in the subnet simultaneously).
Step-by-Step Subnetting Example
Let's take the IP block 192.168.10.0 /26 and calculate the subnet details:
- Determine the prefix length: The CIDR is `/26`. The subnet mask contains 26 ones and 6 zeros.
Binary: `11111111.11111111.11111111.11000000`
Decimal: `255.255.255.192` - Calculate total and usable hosts:
Total IPs = \(2^{(32 - 26)} = 2^6 = 64\) addresses.
Usable hosts = \(64 - 2 = 62\) host addresses. - Find the Network Address: The first address in this block.
Network Address:192.168.10.0 - Find the Broadcast Address: The last address in the block.
Broadcast Address = Network Address + (Total IPs - 1) =192.168.10.63. - Determine the Usable Host Range: All addresses lying between the network and broadcast addresses.
Usable Host Range:192.168.10.1through192.168.10.62.
Frequently Asked Questions (FAQ)
โ What is the purpose of subnetting?
Subnetting serves three key purposes:
- Security: Isolating sensitive departments (like finance or HR) into separate subnets to prevent unauthorized traffic access.
- Performance: Limiting the size of broadcast domains. Fewer devices on a subnet means less broadcast traffic, reducing local network congestion.
- Address Conservation: Efficiently allocating address blocks to departments without wasting large numbers of IP addresses.
โ What is an APIPA address?
APIPA (Automatic Private IP Addressing) is a feature in Windows and other operating systems. If a device is configured to get an IP address dynamically (DHCP) but cannot contact the DHCP server, it automatically assigns itself an IP address in the link-local range **169.254.0.1 to 169.254.255.254**. If you see a `169.254.x.x` IP address, it indicates your computer failed to connect to the router's DHCP server.
โ What is a default gateway?
The default gateway is the IP address of the local router interface connected to your subnet. When your computer wants to send packets to an IP address outside its local subnet (such as a public website), it sends those packets to the default gateway router, which handles routing it across network boundaries.
โ Why does IPv6 eliminate the need for NAT?
IPv6 has a massive address space (\(3.4 \times 10^{38}\) IPs). This allows every single device on Earth to have a unique, public, globally routable IP address. NAT was created as a temporary workaround to conserve the limited IPv4 address pool. Because IPv6 removes this limit, NAT is no longer required, restoring end-to-end direct communication between hosts.
What's Next?
Advance your network routing studies:
- Learn how private IP addresses are translated to public IPs in NAT & PAT Explained.
- Explore how routers forward packets between subnets in Routing & Switching.
- Learn about the transport protocols carrying packets in Network Protocols.
- Explore the conceptual 7-layer model in OSI Model.