## Brief

You subnet mask is used to **define your local network or subnetwork**. You can access everything within the same subnet directly, but everything that is not on your subnet requires the request to go via a **gateway**.

So, for a home user your subnet will be your home network - your computers and wireless devices can all talk directly to one-another. But, the internet is outside your subnet, so all communication has to go via your gateway (usually a router) first.

## Slightly Technical

A subnet is a 32-bit long bit mask (as touched upon by Manaf Abo.Rous), normally written as four 8-bit bytes. Note that `255`

is `11111111`

(8 ones) in binary.

The mask basically means **"only those IP addresses that have the same numbers in the places, as defined by the subnet mask, are in my local network"**.

So a subnet of `255.255.255.0`

means every IP address that matches the first three bytes is your local network, with your given numbers this is anything matching `192.168.001.###`

. Alternatively a wider subnet of `255.255.0.0`

would make your local network `192.168.###.###`

.

## More Technical

The byte values don't *always* have to be 255, you could have `255.255.255.240`

, which is 28 one's and 4 zero's. This means the first 28 bits of another IP must match your's to be in the same subset. A subnet mask must *always* be a certain number of 1's followed by only zeros to make 32-bits, and this is why it can be represented as `/28`

as well (in this case anyway) with the value showing how many 1's the mask contains - this is normally used in the context of the IP, such as `192.168.1.2/28`

So, if your IP is `192.168.1.2`

with the subnet mask `255.255.255.240`

, your subnet is the IP range of `192.168.1.0`

to `192.168.1.15`

(although the lowest and highest are generally not used for devices as they have special functions). If your IP was `192.168.1.53`

your network would be the range `192.168.1.48`

to `192.168.1.63`

.

Notice how both these sets contain 16 unique addresses? The subnet also defined how *large* the subnet is because it defines how many IP addresses are available.

## And now, with Binary

Finally, to paraphrase Manaf Abo.Rous's answer, let's look at the binary.

We'll start by using the mask `255.255.255.0`

, here it is in binary:

```
11111111 11111111 11111111 00000000
```

So given your IP you know that every IP in local network matches those first 24 ones, so lets check your IP (`192.168.1.2`

) in binary:

```
11000000 10101000 00000001 00000010
```

Now, we only look where the 1's in the subnet are, to get your subnet number:

```
11000000 10101000 00000001 --------
```

And now we know *every* IP in your local network starts with your subnet number, and can have anything in the missing values at the end.

Finally, lets look at a second example, using IP `192.168.1.53`

and subnet `255.255.255.240`

:

```
11111111 11111111 11111111 11110000 [subnet]
11000000 10101000 00000001 00110101 [IP]
11000000 10101000 00000001 0011---- [subnet number]
```

And again, your local IP's would have anything in the last four binary values - which are `0000`

,`0001`

,etc up to `1111`

- or in decimal `0`

to `15`

- but remember they would have `0011`

in front to make a full byte, so really the IP's available are `00110000`

(48), `00110001`

(49) and so on up to `00111111`

, which is 63.