What is a subnet mask?
A subnet (short for sub-network) is a group of devices that can talk to each other directly, without a router in between. Usually, that means the devices connected to the same switches or the same Wi-Fi network.
A subnet mask is a number that is configured together with every IP address. It tells the device which part of its address identifies the network and which part identifies the host (the device itself). Without the mask, 192.168.10.25 is just four numbers. With the mask 255.255.255.0, it means “device 25 on network 192.168.10”.
💡 In simple terms: take the postal address 25 Oak Street. “Oak Street” is the network part: everyone on that street shares it. “25” is the host part: one house. The mask is the rule that tells you where the street name ends and the house number starts.
Why the mask exists
Every time a device sends something, it has to answer one question first:
“Is the destination on my own subnet, or somewhere else?”
On my subnet → send it straight there. Somewhere else → send it to the router (the default gateway).
The device can only answer this if it knows where its own network part ends. That is the mask's job. The mask also helps routers: instead of storing a route for every single device, a router stores whole networks, such as “192.168.10.0/24 is through this interface”. One route covers 254 devices.
The important parts
Network portion
The left part of the address. Every device on the same subnet has exactly the same network portion. It identifies the network, like a street name.
Host portion
The right part of the address. It is different for every device on the subnet. It identifies one device, like a house number on that street.
Subnet mask
A second 32-bit number, written like an address. Where the mask is 255, that octet belongs to the network; where it is 0, that octet belongs to the host.
Prefix length (/24)
A short way to write the mask: the number of network bits. /24 means the first 24 bits (3 octets) are the network portion, the same as 255.255.255.0.
Reading a mask: network portion and host portion
A mask looks like an IP address, but it means something different. Line it up under the address and compare them octet by octet:
- 255 in the mask → that octet of the address is network.
- 0 in the mask → that octet of the address is host.
Behind the scenes, a mask is 32 bits: a row of 1s (network) followed by a row of 0s (host). 255 is simply eight 1s in binary (11111111), and 0 is eight 0s. The IP address lesson shows these bits.
Learn more: What Is an IP Address?
Slash notation: what /24 means
Writing 255.255.255.0 every time is slow, so you can count the 1 bits instead and write the number after a slash. This is called the prefix length or CIDR notation (Classless Inter-Domain Routing).
| Prefix | Subnet mask | Network part | Host part | Example | Addresses |
|---|---|---|---|---|---|
| /8 | 255.0.0.0 | first octet | last 3 octets | 10.1.2.3/8 | 16,777,216 |
| /16 | 255.255.0.0 | first 2 octets | last 2 octets | 172.16.45.200/16 | 65,536 |
| /24 | 255.255.255.0 | first 3 octets | last octet | 192.168.10.25/24 | 256 |
So 192.168.10.25/24 and “192.168.10.25, mask 255.255.255.0” mean exactly the same thing. Windows shows the dotted mask; Linux and many network devices show the slash.
The network address and the broadcast address
Set all the host bits to 0 and you get the network address, which identifies the subnet itself. Set all the host bits to 1 (255 in each host octet) and you get the broadcast address, which reaches every device on the subnet. Neither address can be assigned to a device.
| Address | Network address | Usable hosts | Broadcast |
|---|---|---|---|
192.168.10.25/24 | 192.168.10.0 | .1 to .254 (254 hosts) | 192.168.10.255 |
172.16.45.200/16 | 172.16.0.0 | 172.16.0.1 to 172.16.255.254 | 172.16.255.255 |
How a device uses the mask, step by step
Here's what a PC does with its mask every time it sends a packet to an address:
Example 1: two addresses with /24
Example 2: the same addresses with /16
Now give the devices a /16 mask. Only the first two octets are compared:
Same two addresses, different answer. Whether two devices are “on the same subnet” is decided by the mask, not by the addresses alone. That is why you must always read an address together with its mask.
Practice table
| My address | Destination | Compare | Result |
|---|---|---|---|
192.168.1.50/24 | 192.168.1.200 | 192.168.1 = 192.168.1 | Same subnet |
192.168.1.50/24 | 192.168.2.50 | 192.168.1 ≠ 192.168.2 | Different subnet |
10.20.5.9/16 | 10.20.200.1 | 10.20 = 10.20 | Same subnet |
10.20.5.9/16 | 10.21.5.9 | 10.20 ≠ 10.21 | Different subnet |
172.16.4.1/24 | 172.16.40.1 | 172.16.4 ≠ 172.16.40 | Different subnet |
What the mask does to real traffic
The diagram shows an office with two subnets connected by a router. PC-A uses its mask to decide where each packet goes:
- 1. Same network part: direct. 192.168.10 matches PC-A's own network part, 192.168.10, so PC-A sends the frame straight to PC-B through the switch. The router is not involved.
- 2. Different network part: to the gateway. 192.168.20 does not match 192.168.10, so PC-A sends the packet to its default gateway, 192.168.10.1.
- 3. The router delivers it. The router has an interface in 192.168.20.0/24 and forwards the packet to the server.
One important detail: the mask is never sent in the packet. The IP header carries the source and destination addresses, but not the mask. Each device uses its own configured mask to make its own decision. That is why a single device with a wrong mask can break its own traffic while every other device works normally.
Real-world examples
| Network | Typical setting | Why |
|---|---|---|
| Home Wi-Fi | 192.168.1.0/24 | 254 usable addresses are plenty for a home |
| Office floor | 10.20.30.0/24 | One subnet per floor or department limits how far broadcasts reach |
| Large campus or lab | 172.16.0.0/16 | Up to 65,534 devices in one subnet (rarely a good idea in practice) |
Real networks also use masks that split an octet, such as /26 or /30, to make smaller subnets. Working those out is called subnetting. It needs binary and is taught in the CCNA course. You can also let the Subnet Calculator do the maths.
Learn more: Subnetting
What happens with a wrong mask
Assume the correct setting for PC-A is 192.168.10.10/24.
| Mistake | What PC-A believes | What breaks |
|---|---|---|
Mask too short: 255.255.0.0 (/16) | Every address starting with 192.168 is local | It tries to reach 192.168.20.5 directly, sends an ARP request for it and gets no answer. Other 192.168.x.x subnets fail, but the internet still works. |
Mask too long: 255.255.255.255 (/32) | Only itself is local | Every packet, even to PC-B on the same switch, goes to the gateway. Many systems refuse this setting, or can't reach the gateway at all. |
Mask typo: 255.255.255.0 typed as 255.255.0.255 | Nothing: this is not a valid mask | The operating system rejects it. A valid mask is always all 1s first, then all 0s. |
Checking the mask on your computer
C:\> ipconfig Ethernet adapter Ethernet: IPv4 Address. . . . . . . . . . . : 192.168.10.10 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 192.168.10.1
255.255.255.0 is the mask in dotted decimal, the same as /24. Together with the IPv4 Address, it tells you the PC is on 192.168.10.0/24.$ ip -4 addr show eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 inet 192.168.10.10/24 brd 192.168.10.255 scope global dynamic eth0 valid_lft 85100sec preferred_lft 85100sec
inet line shows the address with its prefix, 192.168.10.10/24, and the broadcast address (brd 192.168.10.255) worked out from that prefix.$ ip route default via 192.168.10.1 dev eth0 proto dhcp metric 100 192.168.10.0/24 dev eth0 proto kernel scope link src 192.168.10.10 metric 100
192.168.10.0/24 dev eth0 means “this subnet is directly connected to eth0” (local). Every other destination matches the default via 192.168.10.1 line and goes to the gateway.💡 Troubleshooting tip: compare the mask on the broken PC with the mask on a working PC in the same room. They should be identical.
Common mistakes
- Judging “same subnet” by the first three octets every time. That only works for /24. With /16, you compare only the first two octets.
- Forgetting that each device uses its own mask. The mask is not carried in the packet, so a wrong mask on one device only affects that device's decisions.
- Giving a device the network or broadcast address (for example,
192.168.10.0or192.168.10.255on a /24). These addresses identify the subnet and reach all devices, so they cannot be used by one host. - Guessing the mask from the first octet (“10 means /8”). A 10.x.x.x network is often split into /24 subnets, so always read the configured mask.
- Thinking a bigger prefix number means a bigger network. It's the opposite: more network bits leave fewer host bits, so a /24 is smaller than a /16.
- The mask splits an address into a network portion and a host portion.
- 255 in the mask = network octet; 0 = host octet. /24 = 255.255.255.0, /16 = 255.255.0.0.
- Two addresses are on the same subnet if their network portions match, using the sender's mask.
- Same subnet → deliver directly; different subnet → send to the default gateway.
- The mask isn't in the packet. A wrong mask usually breaks only the device that has it.
Check yourself
PC-A is 192.168.10.10/24. Is 192.168.10.200 on the same subnet?
A server is 10.5.1.20/16. Is a PC at 10.5.99.7 on the same subnet?
A router shows an interface as 192.168.10.1/24. Which dotted-decimal mask should you type on a PC on that subnet?
PC-A should be 192.168.10.10/24 but is set to /16. It can't reach 192.168.20.5, a server on another subnet. Why?
Next, learn about the router address that carries traffic to other subnets.
Learn more: The Default Gateway