Course contents

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

Subnet Mask Basics

Your PC can reach one neighbour but cannot reach a server on another floor. Could the subnet mask make it send to the wrong place? Let's read the mask and predict the PC's next step.

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

You'll learn to read an IPv4 mask and prefix, calculate the local network for /24 and /16 examples, and explain how a wrong mask changes the next-hop decision.

Which addresses does the PC treat as local?

PC-A is 192.168.10.10/24. It wants to reach PC-B at 192.168.10.20 and a server at 192.168.20.5. Before it sends anything, it needs to distinguish a local neighbour from a destination reached through router R1.

A subnet is an IP address range with a shared network prefix. On a simple Ethernet or Wi-Fi LAN, hosts in that subnet normally reach one another directly. The address range and the physical connection are separate: matching addresses do not join two disconnected cables.

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

Changing a mask changes what a host believes is local; it does not move devices onto the same physical network. That distinction explains why a broader mask can break a connection rather than make it reach more places.

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 /24 route covers the whole address block, with 254 conventional host addresses.

Four terms that come with every mask

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. A 1 bit marks a network bit; a 0 bit marks a host bit. In /24 and /16 examples, the boundary falls between whole octets.

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)
Figure 1. 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)
Figure 2. 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. For the /24 and /16 LANs here, neither address is assigned to an ordinary host. Special /31 point-to-point links and /32 host routes follow different rules.

Diagram
The network address and the broadcast address
The network address and the broadcast address
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
Read each row across: the left box names the item, the others describe it.

How a device uses the mask, step by step

For a basic host with its connected subnet and a default route, we can explain the decision using the mask. More generally, the host selects a matching route; an explicit, more specific route can change the next hop:

Diagram
Process, step by step
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).

Read in arrow direction. Labels describe each stage or hop; connectors show the sequence, not a complete physical cabling plan or time to scale.

Figure 3. 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)
Figure 4. 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)
Figure 5. 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)
Figure 6. With /16, both addresses produce network 192.168.0.0. This shows the address calculation; it does not connect separate LANs.

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

Diagram
Practice table
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
Read each row across: the left box names the item, the others describe it.

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:

Diagram
Two subnets, one router: the mask decides the path
Two subnets, one router: the mask decides the path
PC-AIP 192.168.10.10/24PC-BIP 192.168.10.20/24Switch 1Router.10.1 | .20.1Switch 2ServerIP 192.168.20.5/24

Device key: PC-A (laptop) · PC-B (computer)

Lines show the example’s network connections. The coloured path and envelope follow the current step; its text identifies the sender, receiver and traffic type.

Reading the addresses

IP labels identify interfaces or destinations. Subnet labels identify networks; /n is the prefix length. A router ID (RID) identifies a routing process and need not be a reachable interface.

An IP address alone is not a URL. A web URL includes a scheme such as https://; an address on a router or printer does not imply a website.

  • PC-A: IP 192.168.10.10/24
  • PC-B: IP 192.168.10.20/24
  • Router: .10.1 | .20.1
  • Server: IP 192.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.
Figure 7. A router connects different subnets; a switch connects devices within one subnet.

One important detail: the ordinary IPv4 header has no subnet-mask field. 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.

Masks you will meet at home and at work

Diagram
Masks you will meet at home and at work
Masks you will meet at home and at work
NetworkTypical settingWhy
Home Wi-Fi192.168.1.0/24254 usable addresses are plenty for a home
Office floor10.20.30.0/24Separate VLANs with routed subnets can limit broadcasts; the mask alone does not
Large campus or lab172.16.0.0/16Up to 65,534 devices in one subnet (rarely a good idea in practice)
Read each row across: the left box names the item, the others describe it.

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

Keep the cables and addresses in place and change only PC-A's mask. This is a useful experiment because it separates the physical network from the PC's idea of that network. In this example there are no extra host routes or proxy ARP replies to hide the mistake.

Diagram
Same cables, different mask, different decision
Same cables, different mask, different decision
Same cables, different mask, different decisionPC-A at 192.168.10.10/24 and PC-B at 192.168.10.20/24 connect to SW1. SW1 connects to router R1 Gi0/0 at 192.168.10.1/24. R1 Gi0/1 at 192.168.20.1/24 connects to a server at 192.168.20.5/24. Local delivery stays within the left LAN; remote delivery uses R1. Port labels sit beside their link ends.Local LAN · 192.168.10.0/24192.168.20.0/24PC-APC-BSW1R1ServerEth0 → Gi0/1Eth0 → Gi0/2Gi0/24Gi0/0Gi0/1Eth0192.168.10.10/24192.168.10.20/24192.168.10.1/24192.168.20.1/24192.168.20.5/24Correct /24: ARP for R1 at 192.168.10.1Wrong /16: ARP for 192.168.20.5 on the left LAN

On small screens, swipe sideways or focus the diagram and use the arrow keys.

With /24, the server is remote. A mistaken /16 makes PC-A try local ARP for the server instead. This is one LAN and one router, with no proxy ARP or more specific host routes.

With the correct /24, PC-A compares 192.168.10.10 with the server at 192.168.20.5 and gets different network prefixes. It therefore selects R1 as the next hop and, if necessary, uses ARP to find the MAC address of 192.168.10.1. ARP means Address Resolution Protocol: it asks which Ethernet address belongs to a nearby IPv4 address.

With the mistaken /16, both addresses appear to belong to 192.168.0.0/16. PC-A now sends an ARP request for the server itself. The request stays on the left LAN; it does not reach the server across R1. The PC has chosen the wrong next receiver before the router gets a chance to forward the data. Correct the mask, then check the route and neighbour entry again rather than assuming a working cable proves the IP settings are right.

Devices that get their address from DHCP receive the mask with it, so wrong masks turn up mostly on addresses typed in by hand: printers, servers and lab machines. Assume the correct setting for PC-A is 192.168.10.10/24.

Diagram
What happens with a wrong mask
What happens with a wrong mask
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 localThere is no ordinary connected subnet containing the gateway. Delivery may fail unless the platform has an explicit on-link route. /32 is useful in other designs, but is not a replacement for this LAN's /24.
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.
Read each row across: the left box names the item, the others describe it.

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. Confirm both PCs belong to the same intended subnet or VLAN first; two PCs in one room can be on different networks.

Five ways to misread a mask

  • 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.
The mask in five lines
  • 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.

Short lab: prove what the mask changes

  1. Read your current settings with Windows ipconfig or Linux ip -4 addr. Record the active interface's address and mask. Do not change a live office network to match this example.
  2. On paper, compare PC-A 192.168.10.10/24 with PC-B 192.168.10.20. Both produce network 192.168.10.0. Compare PC-A with 192.168.20.5: that destination produces 192.168.20.0.
  3. Change only the paper example to /16. Both destinations now produce 192.168.0.0. Explain why PC-A would ask directly for the server, even though the server is really beyond R1.
  4. On Linux, ip route get 192.168.20.5 shows the route your own system would select. A via value names a next-hop router; dev names the outgoing interface. Your result may differ because your real network is different.

The historical Class A, B and C approach tied masks to address ranges. Classless addressing uses an explicit prefix instead. A shorter prefix offers more host addresses, but a large shared LAN also has more devices to manage and more broadcast traffic to consider.

Test yourself: same subnet or not?

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

Technical references

Prefix notation follows RFC 4632. Host local/remote decisions are described in RFC 1122, section 3.3.1.1. Windows display commands follow Microsoft ipconfig documentation. Outputs are illustrative.

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?
They should. If one device has a different mask, it may still reach some addresses, but it can wrongly treat others as local or remote, and that traffic will fail.