Module 4: Websites and subnetsLesson 13 of 136 min read
Subnet masks and CIDR: counting addresses in a network
198.51.100.0/24 and the mask 255.255.255.0 say the same thing in two notations: the first 24 bits of the address identify the network, the last 8 identify hosts on it. From that one number you can work out how many devices fit, where the network starts and ends, and how to cut it into smaller pieces. The arithmetic is all powers of two.
From classes to prefixes
Early IPv4 had fixed network sizes, the classes A, B and C, read from the first bits of the address. RFC 4632, the current description of Classless Inter-domain Routing (CIDR), notes that only three network sizes were available that way. CIDR replaced them with an explicit prefix length, so a network can be any power-of-two size and routing protocols carry the mask with each route.
The prefix can be written as a slash number or as a dotted mask. RFC 4632's own example uses 10.24.8.0/22 with the mask 255.255.252.0: 22 one-bits followed by 10 zero-bits. The leftover host bits decide the size.
The two formulas
Total addresses in a /p: 2^(32 − p). Usable hosts: 2^(32 − p) − 2, because the first address names the network and the last is the broadcast address. Examples: /24 → 256 total, 254 usable. /26 → 64 total, 62 usable. /22 → 1,024 total, 1,022 usable. /30 → 4 total, 2 usable.
Reading a mask in binary
Each octet of a mask is 8 bits. 255 is 11111111, so the whole octet belongs to the network; 0 is 00000000, all host. Values in between are the boundary: 128, 192, 224, 240, 248, 252 and 254 have 1 to 7 leading ones.
The wildcard mask is the inverse, used by some router and firewall configurations: for /24 it is 0.0.0.255, for /26 0.0.0.63. And a mask must be contiguous, all ones then all zeros; 255.0.255.0 is not a valid subnet mask.
An address that isn't the network address
Input: 10.0.0.17 with mask 255.255.240.0. The third octet 240 is 11110000, so the prefix is 8 + 8 + 4 = /20 and the block is 2^12 = 4,096 addresses. Blocks of 16 in the third octet start at 0, 16, 32 and so on, so 10.0.0.17 lies in 10.0.0.0/20: network 10.0.0.0, broadcast 10.0.15.255, usable 10.0.0.1 to 10.0.15.254, 4,094 hosts. It is a private address from RFC 1918's 10/8 block.
Worked example: splitting a /24 into four
An office has 198.51.100.0/24 and wants four separate networks of similar size. Four is 2^2, so add 2 bits to the prefix: /24 becomes /26, and each piece has 2^(32 − 26) = 64 addresses, 62 usable. The new mask is 255.255.255.192.
- 198.51.100.0/26: hosts .1 to .62, broadcast .63
- 198.51.100.64/26: hosts .65 to .126, broadcast .127
- 198.51.100.128/26: hosts .129 to .190, broadcast .191
- 198.51.100.192/26: hosts .193 to .254, broadcast .255
Check your split
The subnets must add up to the original: 4 × 64 = 256. Each one starts on a multiple of its size (0, 64, 128, 192), and each broadcast is one less than the next network address. If a planned subnet doesn't start on a multiple of its size, it isn't a valid block.
The /31 and /32 exceptions
On a link between exactly two routers, a /30 wastes half its addresses: 4 in total, 2 usable. RFC 3021 allows a /31 on point-to-point links. A 31-bit prefix leaves only two possible addresses, and since such a link has no need for a broadcast, both are used, one per end.
A /32 is a single address, used for one host in routes and firewall rules. Neither has a separate network or broadcast address.
The same idea in IPv6
IPv6 uses the same slash notation over 128 bits. RFC 4291 makes 64 bits the standard size of the interface identifier for ordinary unicast addresses, so a single network such as one home LAN is a /64. Shorter prefixes are counted in /64s: a /48 contains 2^(64 − 48) = 65,536 of them, and a /56 contains 256.
There is no broadcast address in IPv6, so nothing is subtracted. The question that matters is how many /64 networks a prefix provides, not how many hosts fit in one.
Work through the examples above. The tool opens with 192.168.1.0/24: compare Total addresses with Usable hosts, read Subnet mask and Wildcard mask, and look at the mask In binary. Then choose /26 under Split into (optional) and press Calculate to see the four subnets with their first, last and broadcast addresses.
Subnet calculatorQuick check
Three questions. Pick an answer to see why.
How many usable host addresses does a /27 IPv4 network have?
Show the answer
Answer: 30 2^5 − 2 = 30 usable hosts.
You split 203.0.113.0/24 into /26 subnets. Which of these is the broadcast address of the third subnet?
Show the answer
Answer: 203.0.113.191 The third /26 is 203.0.113.128/26, covering .128 to .191; the last address is the broadcast.
Why can a /31 be used on a link between two routers?
Show the answer
Answer: RFC 3021 allows both of its two addresses to be used, since a point-to-point link needs no broadcast With no network or broadcast address reserved, each end of the link gets one of the two addresses.
Standards, not guesses
These guides explain how the internet's plumbing works, using the published standards (RFCs) and official documentation. Each guide shows the date it was last checked.
Sources
- RFC 4632: Classless Inter-domain Routing (CIDR): The Internet Address Assignment and Aggregation Plan
- RFC 3021: Using 31-Bit Prefixes on IPv4 Point-to-Point Links
- RFC 1918: Address Allocation for Private Internets
- RFC 4291: IP Version 6 Addressing Architecture
Last checked October 28, 2026