An IP Address alone is meaningless. Without a Subnet Mask, a computer doesn't know if the destination `192.168.1.50` is a neighbor on the local LAN (talk directly) or a server in Japan (send to Router). The Subnet Mask draws the line between the Network ID (Street Name) and the Host ID (House Number).
The Logic (AND Operation)
Data travels in binary (1s and 0s). The Subnet Mask is a filter.
IP: 11000000.10101000.00000001.00000101 (192.168.1.5)
Mask: 11111111.11111111.11111111.00000000 (255.255.255.0)
Result: 11000000.10101000.00000001.00000000 (192.168.1.0)
The computer performs a Bitwise AND. Where the Mask is 1, the IP is kept. Where the Mask is 0, the IP is ignored.
1. Slash Notation (CIDR)
Typing `255.255.255.0` is tedious. Network engineers count the number of 1s in the binary mask.
255.255.255.0 has 24 ones. So we write /24.
255.0.0.0 has 8 ones. So we write /8.
2. Calculating Usable Hosts
Formula: 2^(Host Bits) - 2.
Why minus 2?
1. The first address is the Network ID (e.g., .0). It represents the wire itself.
2. The last address is the Broadcast Address (e.g., .255). It is used to shout to everyone.
| CIDR | Mask | Total IPs | Usable Hosts |
|---|---|---|---|
| /32 | 255.255.255.255 | 1 | 1 (Specific Host) |
| /24 | 255.255.255.0 | 256 | 254 |
| /16 | 255.255.0.0 | 65,536 | 65,534 |
| /8 | 255.0.0.0 | 16,777,216 | 16,777,214 |
3. Variable Length Subnet Masking (VLSM)
Sometimes you need exactly 22 hosts. A /24 (254 hosts) is wasteful.
You can split networks.
A /27 mask (255.255.255.224) provides 32 IPs (30 usable). This is perfect for small departments.