Subnetting 101
Step 4 — CIDR Notation
CIDR (Classless Inter-Domain Routing) notation is the modern, compact way to express subnet masks. Instead of writing 255.255.255.0, you write /24.
What is CIDR?
CIDR notation appends a slash and number to an IP address. The number represents how many bits are in the network portion.
The /24 means "the first 24 bits are the network, the remaining 8 bits are for hosts."
CIDR to Decimal Subnet Mask
Here's the complete conversion table. Memorize at least /8 through /30:
| CIDR | Subnet Mask | Host Bits | Hosts |
|---|---|---|---|
| /8 | 255.0.0.0 | 24 | 16,777,214 |
| /16 | 255.255.0.0 | 16 | 65,534 |
| /20 | 255.255.240.0 | 12 | 4,094 |
| /24 | 255.255.255.0 | 8 | 254 |
| /25 | 255.255.255.128 | 7 | 126 |
| /26 | 255.255.255.192 | 6 | 62 |
| /27 | 255.255.255.224 | 5 | 30 |
| /28 | 255.255.255.240 | 4 | 14 |
| /29 | 255.255.255.248 | 3 | 6 |
| /30 | 255.255.255.252 | 2 | 2 |
| /31 | 255.255.255.254 | 1 | 2* |
| /32 | 255.255.255.255 | 0 | 1 |
* /31 is a special case used for point-to-point links (RFC 3021)
Quick Conversion Method
To convert CIDR to decimal without memorization:
Example: Convert /27 to decimal
- /27 means 27 network bits
- Fill octets with 1s: 8 + 8 + 8 = 24 bits →
255.255.255.??? - Remaining bits: 27 - 24 = 3 bits in the 4th octet
- 3 bits of 1s =
11100000= 128 + 64 + 32 = 224 - Result:
255.255.255.224
Example: Convert /22 to decimal
- /22 means 22 network bits
- Fill octets: 8 + 8 = 16 bits →
255.255.???.0 - Remaining bits: 22 - 16 = 6 bits in the 3rd octet
- 6 bits of 1s =
11111100= 128+64+32+16+8+4 = 252 - Result:
255.255.252.0
Calculating Number of Hosts
The formula for usable hosts in a subnet:
Hosts = 2host bits - 2
We subtract 2 for the network address and broadcast address
| CIDR | Host Bits | Calculation | Usable Hosts |
|---|---|---|---|
| /24 | 8 | 2⁸ - 2 = 256 - 2 | 254 |
| /25 | 7 | 2⁷ - 2 = 128 - 2 | 126 |
| /26 | 6 | 2⁶ - 2 = 64 - 2 | 62 |
| /27 | 5 | 2⁵ - 2 = 32 - 2 | 30 |
| /28 | 4 | 2⁴ - 2 = 16 - 2 | 14 |
| /29 | 3 | 2³ - 2 = 8 - 2 | 6 |
| /30 | 2 | 2² - 2 = 4 - 2 | 2 |
Calculating Number of Subnets
When you borrow bits from the host portion to create subnets:
Subnets = 2borrowed bits
Example: Divide a /24 into /26 subnets
- Borrowed bits: 26 - 24 = 2 bits
- Number of subnets: 2² = 4 subnets
- Hosts per subnet: 2⁶ - 2 = 62 hosts each
Practice Exercises
- Convert
/28to decimal subnet mask - Convert
255.255.255.224to CIDR notation - How many usable hosts in a /26 network?
- How many /28 subnets can you create from a /24?
- You need 50 hosts per subnet. What's the smallest CIDR?
Show Answers
255.255.255.240/27(224 = 11100000 = 3 bits in last octet, 24+3=27)- 62 hosts (2⁶ - 2 = 64 - 2)
- 16 subnets (28 - 24 = 4 borrowed bits, 2⁴ = 16)
- /26 (gives 62 hosts, /27 only gives 30)
Checkpoint
Before moving on, make sure you can:
- Convert between CIDR and decimal subnet masks
- Calculate usable hosts for any CIDR prefix
- Calculate how many subnets you can create when subdividing
- Choose the right CIDR based on host requirements