# What is a Subnet Mask?

Now that you understand what an IP address is, which is the digital home address of a device, there’s one more question every computer must ask itself before sending data. That question is:

> “Is the destination on my street or in another city?”

In networking terms, this means:

> *“*&#x49;s the other device on my local network, or do I need to send data to the router (gateway) to reach it?*”*

The answer to that question comes from one simple but powerful tool: the Subnet Mask.

<mark style="color:blue;">**What Is a Subnet Mask?**</mark>

The subnet mask is a filter that helps a device interpret its own IP address. It determines which part identifies the network and which part identifies the host, or the specific device.

Just like an ID card that shows both your city and your name, the subnet mask separates these two layers of identity within an IP address.

For example:

| Component   | Example       |
| ----------- | ------------- |
| IP Address  | 192.168.1.10  |
| Subnet Mask | 255.255.255.0 |

Here, the subnet mask doesn’t change your address. It simply clarifies how much of it refers to the network you belong to and how much identifies you as an individual host.

<mark style="color:blue;">**Why It Matters**</mark>

Imagine you are the device **192.168.1.10** and you want to reach **192.168.1.20**.\
Before sending the packet, you first need to know:

> “Is 192.168.1.20 part of my same network”

* If yes, your computer communicates directly over the local network using protocols like ARP to find the other device.
* If no, it sends the data to the Default Gateway, which is the router that connects your network to others.

The subnet mask provides the rule that allows the device to make this decision automatically.

<mark style="color:blue;">**How It Works: The Network and Host Portions**</mark>

A subnet mask looks identical to an IP address, with four decimal numbers separated by dots, but it performs a completely different function.

It uses 255s to cover the network part and 0s to uncover the host part of the IP address.

Example:

| Element     | Value         |
| ----------- | ------------- |
| IP Address  | 192.168.1.10  |
| Subnet Mask | 255.255.255.0 |

In this case:

* The **255s** (192.168.1) indicate the **Network ID**, common to all devices in the same network.
* The **0** (.10) represents the **Host ID**, unique to that individual device.

So:

* **Network** → 192.168.1.0
* **Host** → .10

All IPs starting with **192.168.1.x** belong to the same local network.\
An address like **10.1.1.1** would be part of a completely different network.

<mark style="color:blue;">**Binary View**</mark>

Let’s look at what happens in binary form:

```
IP Address:     192.168.1.10     → 11000000.10101000.00000001.00001010
Subnet Mask:    255.255.255.0    → 11111111.11111111.11111111.00000000
```

When the device uses the mask (a bitwise AND operation), it keeps the bits covered by 1s, which are the network bits. It ignores the bits under the 0s, which are the host bits.

Result:

```
Network ID:     11000000.10101000.00000001.00000000 → 192.168.1.0
```

That’s how the device figures out it belongs to network **192.168.1.0/24**.

<mark style="color:blue;">**CIDR Notation**</mark>

Writing out a full subnet mask each time can be tedious.\
That’s why modern notation uses **CIDR (Classless Inter-Domain Routing)**, which simply shows the number of bits in the subnet mask that are set to 1.

Examples:

* 255.0.0.0 → /8
* 255.255.0.0 → /16
* 255.255.255.0 → /24

So instead of saying:

> 192.168.1.10 with subnet mask 255.255.255.0

we can write:

> **192.168.1.10/24**

This means “24 bits for the network, 8 bits for the host.”

<mark style="color:blue;">**Why It’s Important**</mark>

The subnet mask may seem simple, but it defines the foundation of communication in IP networks. It ensures that:

* Devices know which addresses are local and which require routing.
* Routers can forward packets efficiently.
* Administrators can design, organize, and troubleshoot networks correctly.

Incorrect subnet masks often cause communication failures.\
Two devices can have IPs from the same range but still be unable to reach each other if their subnet masks differ.

The subnet mask doesn’t just identify your network; it also forms the basis of subnetting, which divides a large network into smaller, independent segments. Understanding how the subnet mask defines the network and host portions is the key to mastering subnetting, which we will explore in the next section.
