Skip to content
FALCON CORETECHNOLOGIES

// Lesson 9 of 49 · IPv4 addressing and subnetting

Subnet masks and prefix lengths

Dotted masks vs CIDR prefixes, and how to find the network address, broadcast address and usable host range.
2 min read#ipv4#subnet-mask#cidr

A subnet mask marks which bits of an address are the network part. Mask bits are always a run of 1s followed by 0s. The prefix length (/24) is simply the number of 1s.

Prefix Mask Addresses Usable hosts
/24 255.255.255.0 256 254
/25 255.255.255.128 128 126
/26 255.255.255.192 64 62
/27 255.255.255.224 32 30
/28 255.255.255.240 16 14
/29 255.255.255.248 8 6
/30 255.255.255.252 4 2
/31 255.255.255.254 2 2 (point-to-point links only)
/32 255.255.255.255 1 a single host route

Usable hosts = 2^(host bits) − 2. The two removed addresses are:

  • the network address — all host bits 0 — identifies the subnet itself;
  • the broadcast address — all host bits 1 — reaches every host in the subnet.

(/31 is the exception: RFC 3021 allows both addresses on a point-to-point link.)

Finding the subnet for an address — the block-size method

Example: 192.168.10.77/26

  1. The mask is 255.255.255.192. The "interesting octet" is the one that is neither 255 nor 0 — here the 4th.
  2. Block size = 256 − 192 = 64. Subnets start at multiples of 64: 0, 64, 128, 192.
  3. 77 falls between 64 and 127 → network 192.168.10.64.
  4. Broadcast = next network − 1 = 192.168.10.127.
  5. Usable hosts: .65 – .126 (62 hosts).

Another: 172.16.45.200/20

  1. /20 = 255.255.240.0 → interesting octet is the 3rd.
  2. Block size = 256 − 240 = 16: 0, 16, 32, 48…
  3. 45 is in the 32–47 block → network 172.16.32.0, broadcast 172.16.47.255.
  4. Hosts: 172.16.32.1 – 172.16.47.254 (4094 hosts).

Same subnet or not?

Two hosts can talk directly (without the gateway) only if they are in the same subnet. With 192.168.10.77/26 and 192.168.10.130/26: the first is in .64/26, the second in .128/26 — different subnets, so traffic must go through a router.

A very common real-world fault is a host with the right IP but the wrong mask: it thinks some remote hosts are local and tries to ARP for them instead of using the gateway.

Key points

  • Prefix length = number of 1 bits in the mask.
  • Hosts = 2^h − 2; network = all host bits 0, broadcast = all host bits 1.
  • Block size = 256 − mask value in the interesting octet.
  • Wrong masks cause "some destinations work, others don't" problems.

Sign in to save your lesson progress across devices. You can read every published lesson without an account.