Networking - Subnet Masks and CIDR in networking
1. What is a Subnet Mask?
A subnet mask is used in IP addressing to separate the network portion and the host portion of an IP address.
Key Points
-
An IP address = Network ID + Host ID
-
Subnet mask determines which part is for the network and which part is for hosts.
-
Written in dotted decimal format (e.g.,
255.255.255.0
).
Example
IP Address: 192.168.1.10
Subnet Mask: 255.255.255.0
Octet | Binary | Meaning |
---|---|---|
192 | 11000000 |
Network |
168 | 10101000 |
Network |
1 | 00000001 |
Network |
10 | 00001010 |
Host |
Explanation:
-
255.255.255.0
in binary →11111111.11111111.11111111.00000000
-
1's → Network part
-
0's → Host part
So, here:
-
Network ID =
192.168.1.0
-
Host Range =
192.168.1.1
→192.168.1.254
-
Broadcast Address =
192.168.1.255
2. Subnetting
Subnetting is dividing a big network into smaller networks for better management and security.
Example:
If you have 192.168.1.0/24
with 254 hosts, you can divide it into four subnets of 62 hosts each using 255.255.255.192
.
3. What is CIDR (Classless Inter-Domain Routing)?
CIDR notation is a compact way to represent an IP address and its subnet mask.
Format
IP Address / Prefix Length
-
Example:
192.168.1.10/24
-
/24
→ means first 24 bits are network bits. -
Equivalent Subnet Mask:
255.255.255.0
CIDR Examples
CIDR | Subnet Mask | Network Bits | Host Bits | No. of Hosts |
---|---|---|---|---|
/8 |
255.0.0.0 | 8 | 24 | 16,777,214 |
/16 |
255.255.0.0 | 16 | 16 | 65,534 |
/24 |
255.255.255.0 | 24 | 8 | 254 |
/30 |
255.255.255.252 | 30 | 2 | 2 |
Formula:
Hosts per Subnet = 2^(Host bits) - 2
(Subtract 2 for network and broadcast addresses)
4. Difference Between Subnet Mask and CIDR
Aspect | Subnet Mask | CIDR |
---|---|---|
Format | Dotted decimal | Slash notation |
Example | 255.255.255.0 |
/24 |
Purpose | Separates network & host bits | Represents network size |
Usage | Traditional addressing | Modern addressing |
5. Example Calculation
Scenario:
You are given 192.168.10.0/26
.
Step 1 → Subnet Mask
-
/26
→ 26 network bits → Subnet Mask =255.255.255.192
Step 2 → Number of Hosts
-
Host bits =
32 - 26 = 6
-
Hosts =
2^6 - 2 = 62
Step 3 → Subnets
-
Original
/24
had 256 IPs. -
New
/26
gives256 ÷ 64 = 4
subnets.
Step 4 → Subnet Ranges
Subnet | Network ID | Host Range | Broadcast |
---|---|---|---|
1 | 192.168.10.0 | 192.168.10.1 → 62 | 192.168.10.63 |
2 | 192.168.10.64 | 192.168.10.65 → 126 | 192.168.10.127 |
3 | 192.168.10.128 | 192.168.10.129 → 190 | 192.168.10.191 |
4 | 192.168.10.192 | 192.168.10.193 → 254 | 192.168.10.255 |
6. Diagram
IP: 192.168.10.0/26
Subnet Mask: 255.255.255.192
┌────────────────────────────┬────────────────────────────┬─────────────┐
| Network Bits (26) | Host Bits (6) | Example |
└────────────────────────────┴────────────────────────────┴─────────────┘
Network ID: 192.168.10.0
Host Range: 192.168.10.1 → 192.168.10.62
Broadcast: 192.168.10.63