Skip to content
We areTOP 1%

What is a subnet mask, and what does CIDR notation such as /24 mean?

MediumConceptIP Addressing & Subnetting
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews

Answer

A subnet mask is a 32-bit pattern of 1s followed by 0s: the 1s mark the network bits of an address and the 0s mark the host bits. CIDR (Classless Inter-Domain Routing) notation writes the same information as a slash followed by the number of 1 bits, called the prefix length, so /24 means the mask 255.255.255.0.

  • A host finds its network address with a bitwise AND of its IP address and the mask. Two hosts are on the same subnet only if they get the same result; otherwise traffic must go through a router.
  • With h = 32 − prefix host bits, a subnet has 2^h addresses and 2^h − 2 usable hosts, because the all-zeros host part is the network address and the all-ones host part is the broadcast address.
  • CIDR replaced fixed classes, so prefixes of any length can be used and many routes can be summarised as one.

Example: For 192.168.1.130/24:

IP     192.168.1.130   11000000.10101000.00000001.10000010
Mask   255.255.255.0   11111111.11111111.11111111.00000000
AND    192.168.1.0     -> network address

Host bits = 32 − 24 = 8, so there are 2^8 = 256 addresses and 256 − 2 = 254 usable hosts (192.168.1.1 to 192.168.1.254); the broadcast address is 192.168.1.255.

More in IP Addressing & Subnetting

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account