Module 2.2 50 minBeginner

Subnet masks and prefix length

Memorize the prefix-to-mask table and you have memorized half of subnetting. This chapter gives you the table, the trick to derive any mask from scratch, and the formulas for hosts-per-subnet and subnets-per-supernet.

Course plan — preview

What you'll learn

  • Convert any /n prefix to its dotted-decimal mask without a calculator.
  • Compute usable hosts for any prefix in two seconds.
  • Recognize /30, /31, and /32 by use case.

The mask table — your first piece of muscle memory

A subnet mask is 32 bits: a run of 1s covering the network bits, then 0s covering the host bits. The prefix length is just the count of 1s, so /24 and 255.255.255.0 are the same mask written two ways. The table lists the masks you will meet most, including the ones whose interesting octet is the second or third.

Prefix, mask and usable hosts
PrefixMaskUsable hosts
/8255.0.0.016,777,214
/12255.240.0.01,048,574
/16255.255.0.065,534
/20255.255.240.04,094
/21255.255.248.02,046
/22255.255.252.01,022
/23255.255.254.0510
/24255.255.255.0254 — the classic LAN
/25255.255.255.128126
/26255.255.255.19262
/27255.255.255.22430
/28255.255.255.24014
/29255.255.255.2486
/30255.255.255.2522 — point-to-point links
/31255.255.255.2542 — point-to-point links (RFC 3021)
/32255.255.255.2551 — a loopback or a host route

Why 'hosts = 2^h − 2'

If h is the number of host bits, the subnet has 2^h total addresses. Two are reserved: the all-zeros address is the network identifier and the all-ones address is the broadcast. Everything in between is usable for hosts.

RFC 3021 added a special exception: a /31 has only two addresses, but on a strict point-to-point link they can both be used as host addresses. Most modern routers accept /31 today.

8 more sections in this chapter, plus a 4-question quiz and a hands-on lab.

Course plan

Modules 2–8 are part of the Course & Lab Pass and All-Access Max — start with a free account

You can see the title, summary, learning objectives and the opening sections. The rest of this chapter, like all of modules 2–8, comes with the Course & Lab Pass and All-Access Max. A free account opens Module 1: How Networks Work end-to-end and saves your labs — start there, no card required.

  • Read every chapter in Module 1 — How Networks Work
  • Save labs of up to 5 devices
  • Save up to 3 topologies
  • See the full course syllabus + chapter titles

Free account · no card required · compare plans any time

Build it step by step