Routelearn.net
Course menu

Unit 5: IP Addressing BasicsLesson 5.3 (3 of 6 in this unit)27 of 84 in the Network Fundamentals course

Subnet Mask Basics

An IP address on its own doesn't say which network it belongs to. The subnet mask does. Learn how the mask splits an address into a network part and a host part, what /24 means, and how a device uses the mask to decide whether another address is on its own subnet.

Beginner · 12 min read · Before this: What is an IP address?, Public and private IP addresses

Subnet mask is a 32-bit value that marks which bits of an IPv4 address form the network portion (the 1 bits) and which form the host portion (the 0 bits). It is written in dotted decimal, such as 255.255.255.0, or as a prefix length, such as /24.

In simple terms: The mask tells a device which part of an address identifies the network and which part identifies the device. With it, a device can tell whether another address is on its own network or must be reached through the router.

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.
192.168.10.25 with mask 255.255.255.0
192
168
10
25
Subnet mask 255.255.255.0 (/24)
255
255
255
0
Network part (24 bits) Host part (8 bits)
Mask 255.255.255.0: three octets of network (192.168.10), one octet of host (25).
172.16.45.200 with mask 255.255.0.0
172
16
45
200
Subnet mask 255.255.0.0 (/16)
255
255
0
0
Network part (16 bits) Host part (16 bits)
Mask 255.255.0.0: two octets of network (172.16), two octets of host (45.200).

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).

PrefixSubnet maskNetwork partHost partExampleAddresses
/8255.0.0.0first octetlast 3 octets10.1.2.3/816,777,216
/16255.255.0.0first 2 octetslast 2 octets172.16.45.200/1665,536
/24255.255.255.0first 3 octetslast octet192.168.10.25/24256

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.

AddressNetwork addressUsable hostsBroadcast
192.168.10.25/24192.168.10.0.1 to .254 (254 hosts)192.168.10.255
172.16.45.200/16172.16.0.0172.16.0.1 to 172.16.255.254172.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:

1. Take my own address and mask
For example, 192.168.10.10 with 255.255.255.0 (/24).
2. Keep only the network octets of my address
Where the mask is 255: 192.168.10 → my network is 192.168.10.0.
3. Do the same with the destination address, using my own mask
192.168.10.20 → 192.168.10.0. 192.168.20.5 → 192.168.20.0.
4. Compare the two network parts
Identical → same subnet. Different → another subnet.
5. Act on the answer
Same subnet: deliver directly (ARP for the destination). Other subnet: send to the default gateway (ARP for the gateway).
The local-or-remote decision every host makes before it sends a packet.

Example 1: two addresses with /24

PC-A 192.168.10.10
192
168
10
10
PC-B 192.168.10.20
192
168
10
20
Subnet mask 255.255.255.0 (/24)
255
255
255
0
Network part (24 bits) Host part (8 bits)
192.168.10.0 vs. 192.168.10.0: same network, so same subnet (deliver directly)
With /24, compare the first three octets: 192.168.10 = 192.168.10.
PC-A 192.168.10.10
192
168
10
10
Server 192.168.20.5
192
168
20
5
Subnet mask 255.255.255.0 (/24)
255
255
255
0
Network part (24 bits) Host part (8 bits)
192.168.10.0 vs. 192.168.20.0: different networks (send to the default gateway)
The third octet is different (10 vs. 20), so the server is on another subnet.

Example 2: the same addresses with /16

Now give the devices a /16 mask. Only the first two octets are compared:

PC-A 192.168.10.10/16
192
168
10
10
Server 192.168.20.5/16
192
168
20
5
Subnet mask 255.255.0.0 (/16)
255
255
0
0
Network part (16 bits) Host part (16 bits)
192.168.0.0 vs. 192.168.0.0: same network, so same subnet (deliver directly)
With /16, 192.168 = 192.168, so the same two addresses are now on one subnet.

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 addressDestinationCompareResult
192.168.1.50/24192.168.1.200192.168.1 = 192.168.1Same subnet
192.168.1.50/24192.168.2.50192.168.1 ≠ 192.168.2Different subnet
10.20.5.9/1610.20.200.110.20 = 10.20Same subnet
10.20.5.9/1610.21.5.910.20 ≠ 10.21Different subnet
172.16.4.1/24172.16.40.1172.16.4 ≠ 172.16.40Different 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:

PC-A192.168.10.10/24PC-B192.168.10.20/24Switch 1Router.10.1 | .20.1Switch 2Server192.168.20.5/24
  1. 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. 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. 3. The router delivers it. The router has an interface in 192.168.20.0/24 and forwards the packet to the server.
A router connects different subnets; a switch connects devices within one subnet.

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

NetworkTypical settingWhy
Home Wi-Fi192.168.1.0/24254 usable addresses are plenty for a home
Office floor10.20.30.0/24One subnet per floor or department limits how far broadcasts reach
Large campus or lab172.16.0.0/16Up 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.

MistakeWhat PC-A believesWhat breaks
Mask too short: 255.255.0.0 (/16)Every address starting with 192.168 is localIt 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 localEvery 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.255Nothing: this is not a valid maskThe operating system rejects it. A valid mask is always all 1s first, then all 0s.

Checking the mask on your computer

Example output from a Windows PC, shortened and written for this lesson
C:\> ipconfig
Ethernet adapter Ethernet:

   IPv4 Address. . . . . . . . . . . : 192.168.10.10
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.10.1
What to look for: Subnet Mask 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.
Example output from a Linux PC, written for this lesson
$ 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
What to look for: the 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.
Example output from a Linux PC, written for this lesson
$ 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
What to look for: the second line is the mask at work. 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.0 or 192.168.10.255 on 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.
✅ Key takeaways
  • 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

Predict · scenario 1

PC-A is 192.168.10.10/24. Is 192.168.10.200 on the same subnet?

Predict · scenario 2

A server is 10.5.1.20/16. Is a PC at 10.5.99.7 on the same subnet?

Predict · scenario 3

A router shows an interface as 192.168.10.1/24. Which dotted-decimal mask should you type on a PC on that subnet?

Predict · scenario 4

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

FAQ

What does 255.255.255.0 mean?
It means the first three octets of the address are the network portion and the last octet is the host portion. It is the same as /24. On a /24 network, devices that share the first three octets are on the same subnet.
Is the subnet mask sent inside every packet?
No. The IP header carries the source and destination addresses, but not the mask. Each device keeps its own mask in its settings and uses it to make its own decisions. That is why one device with a wrong mask can have problems while every other device works normally.
Are there masks other than 255.0.0.0, 255.255.0.0 and 255.255.255.0?
Yes. Masks such as 255.255.255.192 (/26) split an octet and create smaller subnets. Working those out needs binary and is taught in the Subnetting lesson of the CCNA course. This lesson stays with /8, /16 and /24.
Do both devices need the same mask to talk?
Yes. All devices on one subnet should have the same mask. If one device has a different mask, it may wrongly treat some addresses as local or remote, and part of its traffic will fail.