Find Prefix Length from Subnet Mask

Beginner Identify

Question

Given the subnet mask 255.255.240.0, determine the equivalent CIDR prefix length, the number of usable host addresses, and the number of subnet bits in the interesting octet.

Given

{
  "subnet_mask": "255.255.240.0"
}

Answer

{
  "prefix": 20,
  "host_count": 4094,
  "subnet_bits": 4
}

Try to solve it first, then click Reveal Answer

Step-by-Step Explanation

Step 1: Convert each octet to binary

255  →  11111111  (8 ones)
255  →  11111111  (8 ones)
240  →  11110000  (4 ones, 4 zeros)
  0  →  00000000  (0 ones)

Full binary: 11111111.11111111.11110000.00000000

Step 2: Count the consecutive 1 bits from the left

Octet 1: 11111111 → 8 bits
Octet 2: 11111111 → 8 bits
Octet 3: 11110000 → 4 bits  (stop at the first 0)
Octet 4: 00000000 → 0 bits

Total: 8 + 8 + 4 + 0 = 20

Prefix length = /20

Step 3: Count the subnet bits in the interesting octet

The "interesting octet" is the third octet (240). It contributes 4 one-bits to the network portion. These are called the subnet bits within that octet.

240 = 11110000
       ^^^^
       4 subnet bits (network) | 4 host bits

Step 4: Calculate the number of usable host addresses

Total host bits = 32 − 20 = 12

Total addresses  = 2^12 = 4,096
Usable hosts     = 4,096 − 2 = 4,094

(Subtract 2 for the network address and broadcast address.)

Quick reference: common subnet masks

Mask Prefix Host bits Usable hosts
255.255.0.0 /16 16 65,534
255.255.128.0 /17 15 32,766
255.255.192.0 /18 14 16,382
255.255.224.0 /19 13 8,190
255.255.240.0 /20 12 4,094
255.255.248.0 /21 11 2,046
255.255.252.0 /22 10 1,022

Summary

Field Value
Prefix length /20
Usable hosts 4,094
Subnet bits in interesting octet 4

Related Terms

More Identify Worksheets