Subnet mask cheat sheet Print

  • subnet mask, cidr, networking, reference
  • 0

A quick reference for IPv4 subnet masks and prefix lengths. Useful when configuring an address on a server — see How to add an additional IP address on Linux — or when working out how many addresses a block contains.

Prefix lengths and masks

Usable hosts are two fewer than the total addresses in a block: one address is the network address and one is the broadcast address.

Prefix Addresses Usable hosts Netmask In /24 blocks
/3211255.255.255.255single host
/3122255.255.255.254point-to-point
/3042255.255.255.2521/64
/2986255.255.255.2481/32
/281614255.255.255.2401/16
/273230255.255.255.2241/8
/266462255.255.255.1921/4
/25128126255.255.255.1281/2
/24256254255.255.255.01
/23512510255.255.254.02
/2210241022255.255.252.04
/2120482046255.255.248.08
/2040964094255.255.240.016
/1981928190255.255.224.032
/181638416382255.255.192.064
/173276832766255.255.128.0128
/166553665534255.255.0.0256

/32 denotes a single address and is what you use for a firewall rule covering one host. /31 is used for point-to-point links, where both addresses are usable.

Sub-blocks within a /24

Where a /24 is divided, the block boundaries fall on multiples of the block size. The pattern for the common cases:

Prefix Blocks First block Second block Boundaries at
/252.1–.126, bcast .127.129–.254, bcast .255every 128
/264.1–.62, bcast .63.65–.126, bcast .127every 64
/278.1–.30, bcast .31.33–.62, bcast .63every 32
/2816.1–.14, bcast .15.17–.30, bcast .31every 16
/2932.1–.6, bcast .7.9–.14, bcast .15every 8
/3064.1–.2, bcast .3.5–.6, bcast .7every 4

In each case the network address is the boundary itself and the broadcast address is the one before the next boundary.

Working it out on the server

Rather than calculating by hand, ask the system:

ipcalc 192.0.2.10/27

Most distributions provide ipcalc or sipcalc, which print the network address, broadcast address and usable range for any block.

Note on your own server

Use the netmask given in your server's details rather than assuming /24. Configuring the wrong netmask produces a server that reaches some addresses and not others — which is more confusing to diagnose than one with no network at all.

See RFC 4632 for the CIDR specification.


Was this answer helpful?

« Back