Skip to content

Masks and CIDR notation

Module
Subnetting Foundations
Difficulty
Easy
Updated
Tested on
Ubuntu 24.04.5 LTS, netlab 1.0, GNU Bash 5.2.21, tcpdump 4.99.4
On this page

One settings screen says /24. Another says 255.255.255.0. They describe the same boundary between network and host bits. Learning both forms lets you compare settings without assuming that different writing means a different network size.

Finish Practice: Understanding IPv4 Addresses and Binary where it helps. Keep the starting lab up, with modes off, and use the VM terminal. You will read router’s existing routes, without changing any settings.

A subnet mask is a separate 32-bit setting with ones for the network part followed by zeros for the host part. It describes which bits of an address belong to each part. Like an address, it is usually printed as four decimal octets. Those numbers describe a boundary; they do not name another interface.

A subnet is a network that a prefix carves out of a larger address range. CIDR notation, short for Classless Inter-Domain Routing notation, writes an address, a slash and its prefix length. Read 192.0.2.0/24 as an address with 24 leading network bits. A route line starting with a subnet in CIDR notation, such as laptop’s 10.77.10.0/24 dev eth0 … from Reading a machine’s network settings, names a subnet the machine reaches directly through that interface. Reaching Another Device explains the rest of the line.

The prefix number is a bit count. It is not a decimal mask value, a device count or the number of octets. You can find the host bit count by subtracting it from 32. A longer prefix leaves fewer host bits and therefore a smaller range.

For /24, write 24 ones followed by eight zeros. Group them into octets: 11111111 11111111 11111111 00000000. The first three groups each become 255; the last becomes 0. The dotted mask is 255.255.255.0.

Going back, write each mask octet in binary and count the leading ones. Three full groups give 24, so the prefix is /24. Keep counting across dots. A dot separates the written octets but does not stop the network part.

For /26, the first 24 ones still fill three groups. The remaining two ones begin the fourth group: 11000000. Its included place values are 128 and 64, giving 192. The complete mask is 255.255.255.192; six bits remain for hosts.

Reverse that conversion by counting eight ones in each 255 and two in 192. The result is 8 + 8 + 8 + 2 = 26. Keep the trailing zeros in the binary group so you can see exactly where the host part begins.

The ones must stay together on the left. After the first zero, every remaining bit must be zero. 255.0.255.0 is not a mask: its third octet starts ones again after the zeros of its second octet. Four numbers within octet limits are not enough.

This rule gives you a useful error check. A partial octet can be 128, 192, 224, 240, 248, 252 or 254. After it, later octets are zero. Before it, earlier octets are 255. Read the whole setting before accepting a conversion.

The network bits equal the prefix number. The last column records network bits plus host bits, always totaling 32. Use the table to check your method rather than trying to memorize every row.

Prefix Mask Network + host bits
/8 255.0.0.0 8 + 24
/12 255.240.0.0 12 + 20
/16 255.255.0.0 16 + 16
/20 255.255.240.0 20 + 12
/22 255.255.252.0 22 + 10
/23 255.255.254.0 23 + 9
/24 255.255.255.0 24 + 8
/25 255.255.255.128 25 + 7
/26 255.255.255.192 26 + 6
/27 255.255.255.224 27 + 5
/28 255.255.255.240 28 + 4
/29 255.255.255.248 29 + 3
/30 255.255.255.252 30 + 2

“The mask is part of the address.” It is a separate setting describing the address. The same address written with another prefix has a different boundary without changing its four address numbers.

“A mask can be any four numbers.” The interrupted ones in 255.0.255.0 disprove that rule. Valid octet format and a valid mask are different checks.

Many settings screens on home computers and routers ask for a mask, while the ip tools print CIDR notation. Both state the same boundary, so /24 on one screen and 255.255.255.0 on another agree.

Write masks for /12, /20, /23, /25, /28, /30. Then write prefixes for 255.0.0.0, 255.255.0.0, 255.255.252.0, 255.255.255.224, 255.255.255.248, and 255.0.255.0; reject any non-mask with a reason. Run netlab shell router -- ip route (the replay below repeats it). Then write each subnet line as its network address plus a dotted mask, and compare with your table.

Read the subnets in router routes
learner@rootvolt:~$ netlab shell router -- ip route[sudo] password for learner: 10.77.10.0/24 dev eth0 proto kernel scope link src 10.77.10.1 
10.77.20.0/24 dev eth1 proto kernel scope link src 10.77.20.1 learner@rootvolt:~$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, networking lab (netlab 1.0), GNU Bash 5.2.21. Read the two connected subnets from router's route list.
Steps (6)
  1. Type netlab shell router -- ip route
  2. Press Enter
  3. Output: [sudo] password for learner:
  4. Type the password (the terminal shows nothing)
  5. Press Enter
  6. Output: 10.77.10.0/24 dev eth0 proto kernel scope link src 10.77.10.1 10.77.20.0/24 dev eth1 proto kernel scope link src 10.77.20.1
Solution

The six masks are 255.240.0.0, 255.255.240.0, 255.255.254.0, 255.255.255.128, 255.255.255.240, 255.255.255.252. The reverse set gives /8, /16, /22, /27, /29, then a rejection because ones restart after zeros. Router lists 10.77.10.0/24 and 10.77.20.0/24. Each uses mask 255.255.255.0.

  • A mask has leading ones followed by zeros.
  • CIDR notation counts those leading ones.
  • Preserve the boundary when translating between the two forms.

Next, Subnet ranges finds the addresses inside that boundary.