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.

192.168.1.0/24

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:

CIDRSubnet MaskHost BitsHosts
/8255.0.0.02416,777,214
/16255.255.0.01665,534
/20255.255.240.0124,094
/24255.255.255.08254
/25255.255.255.1287126
/26255.255.255.192662
/27255.255.255.224530
/28255.255.255.240414
/29255.255.255.24836
/30255.255.255.25222
/31255.255.255.25412*
/32255.255.255.25501

* /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

  1. /27 means 27 network bits
  2. Fill octets with 1s: 8 + 8 + 8 = 24 bits → 255.255.255.???
  3. Remaining bits: 27 - 24 = 3 bits in the 4th octet
  4. 3 bits of 1s = 11100000 = 128 + 64 + 32 = 224
  5. Result: 255.255.255.224

Example: Convert /22 to decimal

  1. /22 means 22 network bits
  2. Fill octets: 8 + 8 = 16 bits → 255.255.???.0
  3. Remaining bits: 22 - 16 = 6 bits in the 3rd octet
  4. 6 bits of 1s = 11111100 = 128+64+32+16+8+4 = 252
  5. 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

CIDRHost BitsCalculationUsable Hosts
/2482⁸ - 2 = 256 - 2254
/2572⁷ - 2 = 128 - 2126
/2662⁶ - 2 = 64 - 262
/2752⁵ - 2 = 32 - 230
/2842⁴ - 2 = 16 - 214
/2932³ - 2 = 8 - 26
/3022² - 2 = 4 - 22

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

  1. Convert /28 to decimal subnet mask
  2. Convert 255.255.255.224 to CIDR notation
  3. How many usable hosts in a /26 network?
  4. How many /28 subnets can you create from a /24?
  5. You need 50 hosts per subnet. What's the smallest CIDR?
Show Answers
  1. 255.255.255.240
  2. /27 (224 = 11100000 = 3 bits in last octet, 24+3=27)
  3. 62 hosts (2⁶ - 2 = 64 - 2)
  4. 16 subnets (28 - 24 = 4 borrowed bits, 2⁴ = 16)
  5. /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