Back to all articles
IP AddressingSubnettingNetworking BasicsLayer 3

What is a Subnet Mask and Why Does It Matter?

Alex MorganMay 8, 2024

If you've ever set up a static IP address or poked around your router's configuration panel, you've inevitably encountered a field labeled Subnet Mask. And if you're like most people, you probably saw the default value—almost always 255.255.255.0—shrugged, left it exactly as it was, and hoped for the best.

It works, so why question it?

But understanding what that string of numbers actually does is one of those "aha" moments in networking. It bridges the gap between knowing *that* IP addresses work and knowing *how* they work.

The Problem: Who is Local and Who is Remote?

To understand subnet masks, we have to revisit how computers talk to each other.

When your computer (let's say its IP is 192.168.1.10) wants to send data to another computer (let's say 192.168.1.50), it needs to make a crucial decision immediately: Is the destination on my local network, or is it somewhere out on the internet?

If the destination is on the local network (like the printer in the next room), your computer can just shout the data directly across the WiFi or Ethernet switch.

If the destination is on the internet (like a Google server), your computer cannot reach it directly. It has to send the data to your Default Gateway (your router), and rely on the router to forward it out to the world.

But how does your computer know if 192.168.1.50 is local or remote? Just looking at the IP address isn't enough. An IP address is just a 32-bit number. It doesn't inherently contain boundaries.

This is where the Subnet Mask comes in.

Splitting the IP Address in Half

Every IP address is actually composed of two distinct parts:

1. The Network Portion: Identifies the specific network the device belongs to (like the street name).

2. The Host Portion: Identifies the specific device on that network (like the house number).

The problem is that the dividing line between the Network Portion and the Host Portion isn't fixed. It can be anywhere.

The subnet mask's entire job is to explicitly define where that dividing line is. It acts as a literal mask over the IP address.

Let's look at the classic example:

IP Address: 192.168.1.10

Subnet Mask: 255.255.255.0

In a subnet mask, a 255 essentially means "This part is the Network." A 0 means "This part is the Host."

So, if we overlay the mask on the IP address:

  • 192 aligns with 255 (Network)
  • 168 aligns with 255 (Network)
  • 1 aligns with 255 (Network)
  • 10 aligns with 0 (Host)
  • Thanks to the subnet mask, your computer now knows that its network is 192.168.1, and its specific ID on that network is 10.

    Making the Decision

    Now we go back to the original problem. Your computer (192.168.1.10 with mask 255.255.255.0) wants to talk to 192.168.1.50.

    Your computer looks at the destination IP. It applies its own subnet mask to it. It sees that the destination's network portion is also 192.168.1.

    "Aha!" your computer says. "My network is 192.168.1. Their network is 192.168.1. We are on the same network! I will send the data directly to them."

    Now imagine you want to visit a website at 142.250.190.46. Your computer applies the mask and sees the network portion is 142.250.190.

    "Wait," your computer says. "My network is 192.168.1. Their network is 142.250.190. We are NOT on the same network. I must send this packet to the router and let the router deal with it."

    That is the magic of the subnet mask. It is a mathematical filter that allows a device to instantly determine whether an IP address is a local neighbor or a distant stranger.

    Looking Under the Hood: Binary

    To truly appreciate subnet masks, you have to look at them in binary, because computers don't read "255". They read 1s and 0s.

    An IPv4 address is 32 bits long. Let's convert 255.255.255.0 to binary:

    11111111.11111111.11111111.00000000

    A subnet mask is always a contiguous string of 1s followed by a contiguous string of 0s. The 1s represent the network portion. The 0s represent the host portion.

    Because writing out binary or typing out 255.255.255.0 gets tedious, network engineers often use CIDR notation (Classless Inter-Domain Routing). Instead of writing the full mask, you just write a slash followed by the number of 1s in the mask.

    Since 255.255.255.0 has exactly twenty-four 1s, we write it as /24.

    So, 192.168.1.10/24 tells you everything you need to know in a few characters: "My IP is 192.168.1.10, and the first 24 bits represent the network."

    Why Change the Subnet Mask?

    If 255.255.255.0 works perfectly fine at home, why would anyone ever use a different subnet mask?

    It comes down to network sizing. A /24 network uses 8 bits for the host (the zeroes at the end). With 8 binary bits, you can have a maximum of 256 unique combinations (0 to 255). Because the lowest and highest addresses are reserved for special purposes, a standard home subnet can hold exactly 254 devices.

    For a house, 254 devices is plenty. But what if you are building the network for a university campus with 10,000 students, all carrying laptops and phones? A /24 subnet will run out of IP addresses almost instantly.

    A network engineer can fix this by sliding the subnet mask to the left. They might use a subnet mask of 255.255.0.0 (which is a /16).

    In binary: 11111111.11111111.00000000.00000000

    Now, 16 bits are reserved for the network, and 16 bits are available for the hosts. This single network can now hold 65,534 devices.

    Conversely, if an engineer is connecting two routers directly together with a single wire, they only need two IP addresses. Giving them a full /24 network would waste 252 IP addresses. Instead, they use a 255.255.255.252 mask (a /30), which provides exactly two usable addresses.

    The Architecture of the Internet

    Subnetting—the process of manipulating the mask to break large networks into smaller ones or combine small ones into larger ones—is how the internet scales. It allows organizations to efficiently hand out IP addresses without wasting them, keeping global routing tables manageable.

    So next time you see 255.255.255.0, you'll know it's not just a random string of maximum values. It's the fence that defines the borders of your digital neighborhood.