Fresh IPv4 news just dropped โ€” ๐ŸŽ‰ see what you’re missing

Subnet Mask Cheat Sheet

Reviewed by Marek Dvoล™รกk, Network engineer

The conversions and mental arithmetic used daily. For the complete table including host counts and every prefix length, see the CIDR chart.

The eight octet values

Every subnet mask octet is one of nine values. Memorising the eight non-trivial ones removes the need to look anything up.

Octet valueBitsBlock sizeBinary
128112810000000
19226411000000
22433211100000
24041611110000
2485811111000
2526411111100
2547211111110
2558111111111

Block size is always 256 โˆ’ octet value. That single relationship is the whole of the magic-number method below.

Mask to prefix, /16 to /32

The range people actually configure.

PrefixSubnet maskAddressesUsableSubnets per /24
/16255.255.0.065,53665,534โ€”
/17255.255.128.032,76832,766โ€”
/18255.255.192.016,38416,382โ€”
/19255.255.224.08,1928,190โ€”
/20255.255.240.04,0964,094โ€”
/21255.255.248.02,0482,046โ€”
/22255.255.252.01,0241,022โ€”
/23255.255.254.0512510โ€”
/24255.255.255.02562541
/25255.255.255.1281281262
/26255.255.255.19264624
/27255.255.255.22432308
/28255.255.255.240161416
/29255.255.255.2488632
/30255.255.255.2524264
/31255.255.255.25422128
/32255.255.255.25511256

/31 and /32 are the exceptions to “usable equals total minus two”. A /31 is a point-to-point link under RFC 3021 with both addresses assignable; a /32 is a single host route.

Subnet boundaries by prefix

Where the networks start in the interesting octet.

PrefixBlock sizeBoundaries
/251280, 128
/26640, 64, 128, 192
/27320, 32, 64, 96, 128, 160, 192, 224
/28160, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240
/298every 8 from 0 to 248
/304every 4 from 0 to 252

The magic-number method

Working out which subnet an address belongs to, without a calculator.

1. Find the block size. Subtract the interesting octet of the mask from 256. For 255.255.255.192, that is 256 โˆ’ 192 = 64.

2. Count up in that increment. Boundaries are 0, 64, 128, 192.

3. Find the boundary at or below your address. That is the network address.

4. The broadcast is the next boundary minus one. Usable hosts sit between them.

Worked example for 10.1.1.100/26:

Mask            255.255.255.192
Block size      256 โˆ’ 192 = 64
Boundaries      .0   .64   .128   .192
100 falls in    .64 โ€“ .127
Network         10.1.1.64
First host      10.1.1.65
Last host       10.1.1.126
Broadcast       10.1.1.127

The same method works in any octet. For 172.20.36.5/18, the mask is 255.255.192.0, block size 64 in the third octet, boundaries 0, 64, 128, 192 โ€” so 36 falls in the first block and the network is 172.20.0.0/18.

Wildcard masks

The bitwise inverse of the netmask, used in Cisco ACLs and OSPF network statements. Subtract each octet from 255.

PrefixSubnet maskWildcard mask
/24255.255.255.00.0.0.255
/25255.255.255.1280.0.0.127
/26255.255.255.1920.0.0.63
/27255.255.255.2240.0.0.31
/28255.255.255.2400.0.0.15
/29255.255.255.2480.0.0.7
/30255.255.255.2520.0.0.3

A set bit in a wildcard mask means “ignore this bit when matching”, which is why the pattern looks inverted compared with everything else in a router configuration.

Related

Last updated on