Computer Networks · Module 5 — Network Layer
Subnet masks and CIDR
An IP address alone does not tell you where the network part ends.
Sign in to track your score
Aisha's laptop wants to reach 192.168.1.57. Before it does anything else, it has to answer one question: is that address on my own network, or somewhere else?
Why & what
Why a mask is needed. An IP address alone does not tell you where the network part ends.
192.168.1.42 could be split after 8 bits, 16 bits or 24 bits. Different splits mean completely different networks.
So every address travels with a second number that marks the boundary.
What a subnet mask is. A subnet mask is 32 bits where every network bit is 1 and every host bit is 0, with no mixing.
255.255.255.0 is 11111111.11111111.11111111.00000000: the first 24 bits are network.
What CIDR notation is. Writing out 255.255.255.0 is tedious, so CIDR (Classless Inter-Domain Routing) just counts the 1s.
192.168.1.42/24 means the same thing: 24 network bits, 8 host bits.
The two formulas you need.
- Total addresses in a block = 2^(32 − prefix)
- Usable host addresses = 2^(32 − prefix) − 2
The minus 2 removes the network address (all host bits 0) and the broadcast address (all host bits 1).
For /24: 2^8 = 256 addresses, 254 usable.
Common masks worth memorising:
| CIDRMask | AddressesUsable | ||
|---|---|---|---|
| /24 | 255.255.255.0 | 256 | 254 |
| /25 | 255.255.255.128 | 128 | 126 |
| /26 | 255.255.255.192 | 64 | 62 |
| /27 | 255.255.255.224 | 32 | 30 |
| /28 | 255.255.255.240 | 16 | 14 |
| /30 | 255.255.255.252 | 4 | 2 |
How it works
To find which network an address belongs to:
- Write the IP in binary.
- Write the mask in binary underneath, lined up.
- AND them: a bit in the result is 1 only if both bits above it are 1.
- Convert the result back to dotted decimal. That is the network address.
- To test if two addresses are on the same network, do this for both. Same result means same network.
Aisha's laptop does exactly this for every packet it sends.
Check A: sending to Rahul, 1G2.168.1.57.
- 192.168.1.42 AND 255.255.255.0 = 192.168.1.0
- 192.168.1.57 AND 255.255.255.0 = 192.168.1.0
- Same. So Aisha ARPs for Rahul directly and sends the frame straight to him. The router is never involved.
Check B: sending to college.edu, 203.0.113.10.
- 192.168.1.42 AND the mask = 192.168.1.0
- 203.0.113.10 AND the mask = 203.0.113.0
- Different. So the packet goes to the default gateway instead: which is exactly why Topic 4.5 had her ARP for 192.168.1.1 and not for the server.
Same address, different mask, different answer. Give that same laptop a /26 mask instead.
- 192.168.1.42/26 sits in network 192.168.1.0
- 192.168.1.57/26 sits in network 192.168.1.0 too: both are under .64
But 192.168.1.70/26 would land in 192.168.1.64, a different network, even though the first three numbers are identical. The mask decides, not the dots.

Common confusion
Students think a bigger prefix number means a bigger network. Actually, a bigger prefix means a SMALLER network.
The prefix counts network bits, so the bits left over for hosts shrink as it grows.
- /16 leaves 16 host bits → 65,534 usable addresses.
- /24 leaves 8 host bits → 254 usable.
- /30 leaves 2 host bits → 2 usable.
Every step up in prefix halves the block. Read /30 as "tiny", not "huge".
Interview angle
Asked as: "What is a subnet mask?" and "How many hosts in a /26?" The second is a calculation they expect you to do in your head.
Model answer:
A subnet mask marks where the network part of an address ends and the host part begins. It is 32 bits, with the network bits set to 1 and the host bits to 0. CIDR notation just writes the count of 1 bits, so 255.255.255.0 is /24. To find the network address you AND the IP with the mask. Two devices are on the same network if that result matches, which is how a host decides whether to send directly or via the gateway. The number of addresses in a block is 2 to the power of the host bits, minus 2 for the network and broadcast addresses. So a /26 has 6 host bits, giving 64 addresses and 62 usable.
- 1.
How many usable host addresses does a /26 give?
- 2.
Which mask matches /25?
- 3.
Why subtract 2 when counting usable hosts?
- 4.
Which is the smaller network?