SR1

How does a Subnet mask work?

SR1

A subnet mask works like a filter, helping to route traffic inside a subnet. Basically, the subnet mask tells the router which numbers it should look at and which ones it should ignore beneath the mask.

For example, when a binary mask is laid over an IP address also translated into binary, a 1 over a number tells the router to look at the number beneath, and a 0 says to ignore the number. The subnet mask tells a router which bits to pay attention to when calculating the network ID portion of an IP address.

Calculating subnets by hand

By default, the subnet mask for a Class C IP address class is set to 255.255.255.0, meaning that the first 3 octets (24 bits) in an IP address are used to identify the network ID, and the last octet (8 bits) are dedicated to the host ID.

That means that on this particular subnet, there are 256 possible IP addresses. How did we figure this out? Remember that 255 is the highest number that can be represented in binary with 8 bits. To get to 255, all of the 8 bits must be set to 1, each one representing a number in decimal (1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 = 255). When you include the number zero that makes 256 possible values.

blog98

But if we had a subnet mask of 255.255.255.192, that would mean there are only 6 bits available to us (we get 192 because the bits representing 128 and 64 are masked out). Because 63 is the highest decimal value that can be represented with 6 binary bits (1 + 2 + 4 + 8 + 16 + 32), when you add the zero, that makes 64 possible values.

blog97

How to calculate hosts or subnets based on the subnet mask

A quicker way to figure out how many hosts will exist on a particular subnet is to use the formula 2n-2, where n is the number of bits available to the host ID, where 2n represents 2 raised to the nth power. You must then subtract two from the result because 2 addresses are reserved for the network ID and broadcast address or ID.

So in our examples above:

2^8 – 2 = 254

2^6 – 2 = 62

But you don’t have to do that work manually. If you’re going to calculate a subnet mask, ere’s a quick cheat sheet to help you figure out how many host addresses are available depending upon the CIDR notation.

CIDR notation Available IP Addresses Hosts Netmask
/30 4 2 255.255.255.252
/29 8 6 255.255.255.248
/28 16 14 255.255.255.240
/27 32 30 255.255.255.224
/26 64 62 255.255.255.192
/25 128 126 255.255.255.128
/24 256 254 255.255.255.0
/23 512 510 255.255.254.0
/22 1,024 1,022 255.255.252.0
/21 2,048 2,046 255.255.248.0
/20 4,096 4,094 255.255.240.0
/19 8,192 8,190 255.255.224.0
/18 16,384 16,382 255.255.192.0

 

/17 32,768 32,766 255.255.128.0
/16 65,536 65,534 255.255.0.0
/15 131,072 131,070 255.254.0.0
/14 262,144 262,142 255.252.0.0
/13 524,288 524,286 255.248.0.0
/12 1,048,576 1,048,574 255.240.0.0
/11 2,097,152 2,097,150 255.224.0.0
/10 4,194,304 4,194,302 255.192.0.0
/9 8,388,608 8,388,606 255.128.0.0
/8 16,777,216 16,777,214 255.0.0.0
/7 33,554,432 33,554,430 254.0.0.0
/6 67,108,864 67,108,862 252.0.0.0
/5 134,217,728 134,217,726 248.0.0.0
/4 268,435,456 268,435,454 240.0.0.0
/3 536,870,912 536,870,910 224.0.0.0
/2 1,073,741,824 1,073,741,822 192.0.0.0
/1 2,147,483,648 2,147,483,646 128.0.0.0
/0 4,294,967,296 4,294,967,294 0.0.0.0

So based on this 4 Pillar subnet mask is below

/22 1,024 1,022 255.255.252.0

So our IP will be from 172.16.0.0 – 172.16.3.254

One thought on “How does a Subnet mask work?

  1. Noгmally І don’t learn article on blogs, but
    I wish to sɑy that this write-up verу compelled me to check out and do so!

    Your writing tɑste has been amazed me. Thanks, very nice article.

Leave a Reply

Your email address will not be published. Required fields are marked *