Understanding IP Subnetting and CIDR Notation
Networking doesn't have to be confusing. Demystify Classless Inter-Domain Routing (CIDR), network masks, and binary host calculations with this practical guide.
What is an IP Address and Subnetting?
An **IPv4 address** is a 32-bit binary number, typically written as four decimal octets separated by dots (e.g., `192.168.1.1`). Subnetting is the practice of dividing a physical network into smaller, logical sub-networks (subnets). This division improves security, reduces broadcast traffic, and helps manage IP address allocation efficiently.
The Role of the Subnet Mask
Every IP address on a network is accompanied by a **subnet mask**. The mask tells network routing hardware which part of the 32-bit IP address belongs to the **Network Portion** (identifying the specific street) and which part belongs to the **Host Portion** (identifying the individual house).
A subnet mask is also a 32-bit binary number. Standard subnet masks consist of continuous binary `1`s followed by continuous binary `0`s:
- Binary `1`s represent the network address space.
- Binary `0`s represent the space available for host devices (computers, servers, routers).
Dotted Decimal vs. CIDR Notation
Traditionally, subnet masks were written in dotted decimal notation, such as `255.255.255.0`. Today, **CIDR (Classless Inter-Domain Routing)** is the industry standard. CIDR represents the mask by appending a slash followed by the count of active network bits (the binary `1`s).
| CIDR Shorthand | Subnet Mask (Decimal) | Subnet Mask (Binary Representation) | Total Addresses | Usable Hosts |
|---|---|---|---|---|
| /32 | 255.255.255.255 | 11111111.11111111.11111111.11111111 | 1 | 1 (Host route) |
| /30 | 255.255.255.252 | 11111111.11111111.11111111.11111100 | 4 | 2 (Point-to-point) |
| /28 | 255.255.255.240 | 11111111.11111111.11111111.11110000 | 16 | 14 |
| /24 | 255.255.255.0 | 11111111.11111111.11111111.00000000 | 256 | 254 |
| /16 | 255.255.0.0 | 11111111.11111111.00000000.00000000 | 65,536 | 65,534 |
How Subnet Math Works
When calculating network values, routers use binary logical operations:
- Network Address: Calculated by performing a bitwise logical **AND** operation between the IP address and the subnet mask. The result isolates the network portion.
- Broadcast Address: Calculated by performing a bitwise logical **OR** between the IP address and the bitwise inversion of the subnet mask (known as the wildcard mask).
- Usable Hosts: Calculated using the formula $2^H - 2$, where $H$ is the number of host bits (binary zeros in the mask). We subtract $2$ because the very first address is reserved to identify the network itself, and the final address is reserved for broadcast messages.
Step-by-Step Example Calculation
Let's find the subnet parameters for the IP `192.168.1.100` with mask `/26` (which corresponds to `255.255.255.192`):
- Determine host bits: A `/26` mask uses 26 bits for the network, leaving $32 - 26 = 6$ host bits.
- Calculate total addresses: $2^6 = 64$ total addresses.
- Calculate usable hosts: $2^6 - 2 = 62$ usable host addresses.
- Find Network boundary: In binary, the last octet of the IP (100) is `01100100`. The mask octet (192) is `11000000`. Performing logical AND:
01100100 & 11000000 = 01000000(which is 64 in decimal). So the network address is **192.168.1.64**. - Find Broadcast boundary: Setting all 6 host bits to binary `1` gives the binary octet `01111111` (which is 127 in decimal). So the broadcast address is **192.168.1.127**.
- Identify Usable Range: The address right after the network address and up to the address right before the broadcast address. In this case, **192.168.1.65** to **192.168.1.126**.
Related Guide: Learn more about IP subnetting and CIDR notation