What is a subnet mask?
A subnet mask is a parameter that determines which part of an IPv4 address belongs to the network and which belongs to the hosts within it.
Short version for an interview:
A subnet mask is a 32-bit number that separates the network part of an IP address from the host part. Thanks to the mask, a router understands which network this is and which devices are in it.
What a subnet mask looks like
A mask has the same format as an IPv4 address: four numbers from 0 to 255.
Examples of common masks:
255.0.0.0
255.255.0.0
255.255.255.0
255.255.255.128
255.255.255.252But the shorthand CIDR form is used more often:
/8
/16
/24
/25
/30The meaning of the subnet mask
The mask determines:
- which bits belong to the network → they are set to 1
- which bits belong to the hosts → they are set to 0
Example of the 255.255.255.0 (/24) mask in binary form:
11111111.11111111.11111111.00000000
First 24 bits → network Last 8 bits → hosts
Example of how a subnet mask works
Suppose there is an IP:
192.168.10.25
And a mask:
255.255.255.0 (/24)
This means:
- Network part: 192.168.10
- Host part: 25
Network:
192.168.10.0/24
Broadcast:
192.168.10.255
Host range:
192.168.10.1 - 192.168.10.254
Why a subnet mask is needed
1. To determine subnet boundaries
The router understands:
- which IPs belong to the same network,
- where to send packets,
- where routing is required.
2. To divide a network into subnets
For example, a /24 network can be split into two /25s:
- 192.168.1.0/25
- 192.168.1.128/25
3. To optimize routing
CIDR and VLSM allow routing tables to be reduced.
An important formula
Number of hosts in a network:
2^(number of zero bits in the mask) - 2
Examples:
| Mask | Zeros | Hosts |
|---|---|---|
| /24 | 8 | 254 |
| /25 | 7 | 126 |
| /26 | 6 | 62 |
| /30 | 2 | 2 (for P2P links) |
Common masks and their applications
| Mask | CIDR | Where it is used |
|---|---|---|
| 255.255.255.0 | /24 | Typical office/home subnet |
| 255.255.255.128 | /25 | Splitting a network in half |
| 255.255.255.252 | /30 | Links between two routers |
| 255.0.0.0 | /8 | Huge networks (private range 10.0.0.0) |
Ready answer for an interview
A subnet mask is a 32-bit number showing which part of an IPv4 address belongs to the network and which belongs to the hosts. In the mask, ones denote the network part, zeros denote the host part. The mask allows you to determine subnet boundaries, route traffic, and divide a network into smaller subnets. Example: for the 255.255.255.0 (/24) mask, the network is the first 24 bits, the hosts are the last 8.
Cheat sheet (5 seconds)
- Subnet mask = separates Network from Host.
- In the mask: 1 = network, 0 = hosts.
- Notation: 255.255.255.0 = /24.
- Determines: network, broadcast, host range.
- Hosts = 2ⁿ - 2, where n = number of zeros.
Short Answer
Interview readyA concise answer to help you respond confidently on this topic during an interview.