An IP address is incomplete without its corresponding subnet mask. The subnet mask acts as a boundary line with the following responsibilities:
Structure: IPv4 subnet masks are 32 bits in length, while IPv6 masks are 128 bits.
Identification: It separates the Network portion (the neighborhood) from the Host portion (the specific house) of an IP address.
Capacity: It helps networking devices determine the total number of networks and usable IP addresses available.
Routing: It allows a sender to determine if a destination IP is on the local network or if the packet needs to be forwarded to the default gateway.
Class A: 255.0.0.0 (Binary: 11111111.00000000.00000000.00000000)
Class B: 255.255.0.0 (Binary: 11111111.11111111.00000000.00000000)
Class C: 255.255.255.0 (Binary: 11111111.11111111.11111111.00000000)
You will often see IP addresses written with a slash at the end (e.g., 10.10.1.2/8). This is known as the network prefix (or CIDR notation).
The network prefix simply represents the total number of continuous 1s in the binary format of the subnet mask.
Example: 255.255.224.0
Octet 1 (255) = 11111111
Octet 2 (255) = 11111111
Octet 3 (224) = 11100000
Octet 4 (0) = 00000000
Total 1s = 19. Therefore, the prefix is /19.
Just because two devices are plugged into the same physical switch does not mean they can communicate. They must be on the same logical Layer 3 network (Network ID).
To find the Network ID, routers and computers perform a logical binary operation called ANDing against the IP address and the Subnet Mask.
0 AND 0 = 0
0 AND 1 = 0
1 AND 0 = 0
1 AND 1 = 1
If a PC's Network ID calculation results in 192.168.1.0/25, but the Router's calculation results in 192.168.1.128/25, the devices are on different logical networks and cannot communicate without reconfiguration.
Assigning a massive default Class C network (254 usable IPs) to a small department with only 15 computers wastes over 200 IP addresses. On a global scale, this leads to rapid IPv4 exhaustion. Subnetting solves this by:
Efficiently distributing IP addresses with the least amount of wastage.
Creating smaller broadcast domains. Large broadcast domains cause network congestion, high latency, and dropped packets. Subnetting breaks one massive network into smaller, faster, and more secure segments.
When creating subnets, you "borrow" bits from the host portion (changing 0s to 1s) to create new networks. Memorize these three formulas:
Number of Subnets = 2^N (Where N is the number of borrowed bits/new network bits)
Total IPv4 Addresses = 2^H (Where H is the number of remaining host bits)
Usable IPv4 Addresses = 2^H - 2 (We subtract 2 because the Network ID and Broadcast Address cannot be assigned to a device)
Important Guidelines for Subnet Ranges:
First Usable IP: Network ID + 1
Broadcast Address: Next Network ID - 1
Last Usable IP: Broadcast Address - 1
Sometimes, even a subnetted network is too large. For example, point-to-point WAN links between two routers only ever need 2 usable IP addresses. Assigning a standard subnet that provides 30 usable IPs to a WAN link wastes 28 addresses.
VLSM is the process of "subnetting a subnet." By pushing the network prefix all the way to a /30 (255.255.255.252), we leave exactly 2 host bits.
Calculation: 2^2 - 2 = 2 usable IP addresses.
This provides a perfect, zero-waste IP block specifically designed for router-to-router WAN links.