Subnet Mask - Explained
Image Credit: Hacksland

Subnet Mask - Explained

What is a subnet mask? So that is the subject of my discussion. Before we talk about what a subnet mask is, we must first talk about what an?IP address?is. An IP address is an identifier for a computer or device on a network,every device has to have an IP address for communication purposes. And to be specific, I'm talking about an IPv4 address,an IPv4 address is a 32-bit numeric address written as four numbers separated by periods. Each group of numbers that are separated by periods is called an?octet. The number range in each octet is from 0 to 255. An IP address consists of two parts - the first part is a?network address?and the second part is the?host address. The network address or network ID is a number that's assigned to a network. So every network will have a unique address, the host address or host ID is what's assigned to hosts within that network such as computers, servers, tablets, routers, and so on. So every host will have a unique host address.?

Now the way to tell which portion of the IP address is a network or the host is where the subnet mask comes in. A subnet mask is a number that resembles an IP address. And it reveals how many bits in the IP address are used for the network by masking the network portion of the IP address.?

In the world of computers and networks, IP addresses and subnet masks and this decimal format here are meaningless. And this is because computers and networks don't read them in this format. That's because they only understand numbers in a?binary format, which are 1s and 0s, and these are called bits. So the binary number for this IP address is this number here.

IP Address

192.168.1.0

11000000. 10101000. 00000001. 00000000

Subnet Mask

255.255.255.0

11111111. 11111111. 11111111. 00000000

And the binary number for this subnet mask is this number. These are the numbers that computers and networks only understand.?The next question is how do we get these binary numbers from this IP address and this subnet mask. So here we have an eight-bit octet chart, the bits in each octet are represented by a number.?

No alt text provided for this image

So starting from the right, the first bit has a value of 1, and then the number doubles with each step. So there's 2, then 4, 6, and so on all the way up to 128. Each bit in the octet can be either a 1or a 0, if a number is a 1, then the number that it represents counts. If the number is 0, then the number that it represents does not count. So by manipulating the 1s and 0s in the octet, you can come up with a number range from 0 to 255. So for example, the first octet in this IP address is 192, how do we get a binary number out of 192? First, you look at the octet chart, and then you will put ones under the numbers that were added to the total of 192. So you will put a 1 in the 128 slot, and then a one in the 64 slot. So now if we count all the numbers that we have 1s underneath them, you will get a total of 192. All of the other bits will be 0s, because we don't need to count them since we already have our number. So this number here is the binary bit version of 192.?

No alt text provided for this image

So let's do the next octet, which is 168. So let's put a one on 128 32 and eight, and then all the rest would be zeros. So if we were to add all the numbers that we have 1s underneath them, we will get a total of 168.?

No alt text provided for this image

The next octet is 1, so we'll put a one in the one slot.?

No alt text provided for this image

And when you add up only one you get one and the last octet is zero, which makes things simple because all the binary numbers would be all zeros. So here is the binary number for our IP address.?

No alt text provided for this image

Now the subnet mask binary conversion is exactly the same way. So in this subnet mask, the first three octets are 255. So if we were to look at this subnet mask and binary form, the first three octets would be all ones, because when you count all the numbers in an octet, it will equal 255 and then the last octet will be all 0s.

No alt text provided for this image
No alt text provided for this image

So here we have our IP address and subnet mask and binary form lined up together.?So the way to tell which portion of this IP address is the network part is when a subnet mask or binary digit is a 1, it will indicate the position of the IP address that defines the network. So we'll cross out all the digits in the IP address. to line up with the ones in the subnet mask, and when you do this, it will reveal that the first three octets of the IP address is the network portion. And the remaining is the host portion. So the 1s in the subnet mask indicates the network address, and the 0s indicate the host addresses. So in another example, let's use a different IP address and subnet mask. And let's put them in binary form.?

No alt text provided for this image

So in this example, the first two octets are 255. And the last two octets are zero. So if we cross out all the digits in the IP address, that line up with the ones in a subnet mask will see that the first two octet is the network portion. And the last two octet is the host portion.?

No alt text provided for this image

And let's do one more. And in this subnet mask, the first octet is 255. And the rest are 0s. And then we'll cross out all the digits again. And this time, it reveals that the first octet is the network portion, and the last three octets are for hosts. Now figuring out the network and host parts of an IP address using these default subnet masks was simple because as I stated before when you count all the numbers in an octet, it will equal 255.?

No alt text provided for this image

So we automatically know that the numbers and the octet are all ones. So we really didn't have to see the IP address or subnet mask in its binary format, because it's so simple.?

But what if the subnet mask was this number here, where the first two octets are 255. But the third octet is 224. So this is a little trickier.?

No alt text provided for this image

So here is the binary number for this subnet mask. The first two octets are all ones. And in a third octet, the first three bits are ones, which will equal 224. Because starting from the left, when you add the first three bits in an octet, it adds up to 224. So let's put this subnet mask and IP address in its binary format. And again, if we cross out all the digits in the IP address that line up with the ones in a subnet mask, we'll see that in the IP address the first two octets, and the first three bits and the third octet is the network part. And the 13 remaining bits are used for hosts.

Another question is why does an IP address have a network and a host part? Why can't it just have a host part to uniquely assign each device an IP address? So why does it have a network part also? Now the reason for this is manageability. It's for breaking down a large network into smaller networks or sub-networks, which is known as?subnetting. So for example, let's say that there were no small networks, let's say that an organization has a large number of computers in one huge network. Now when a computer wants to talk to another computer, it needs to know how and where to reach that computer. And it does this by using a?broadcast. A broadcast is when a computer sends out data to all computers on a network so we can locate and talk to a certain computer. So for example, let's say that computer?A?wanted to communicate with computer?B?over a network. So what happens next is that computer?A?will send out a broadcast out on the network asking the target computer?B?to identify itself so it can communicate with it. But the problem with this is that every computer on the network will also receive the broadcast because they are all on the same network. So as you can imagine, if every computer on the large network was broadcasting to every other computer just to communicate, it would be chaos, it would slow down the network and potentially bring it to a halt because of the tremendous amount of broadcast traffic it would cause. And it might even cause fires. Well, not really but whatever problem was to happen on the network, it would be very difficult to pinpoint because the network is so big. So in order to prevent this, networks need to be broken down into smaller networks, and networks are broken down and physically separated by using?routers. And by using routers, this would alleviate the problem of excess traffic. Because broadcasts do not go past routers, broadcasts only stay within a network. So now instead of one large network, this network is broken down into sub-networks or subnets. So now if computer?A?wanted to communicate with computer?B?in another sub-network, the computer will send out a broadcast that only the computers in its sub-network can receive. But since the target computer is on a different subnetwork, the data will be sent to the default gateway, which is the router, and then the router will intelligently route the data to the destination. So this is why IP addresses have a network portion and a host portion. So networks can be logically broken down into smaller networks, which is known as?subnetting.

Hey guys, I just want to break in here and tell you that if you're a beginner and you want to learn more about networking, I highly recommend an audiobook that will help you do that-?https://amzn.to/3zUZJn5. You can download and listen to it for free, just get the book by signing up for the free 30 day trial of Amazon audible Premium Plus, but even if you cancel your Audible membership at any time, during the 30 days, the audiobook is still yours to keep forever without paying anything. So once again, it's completely free.?

So let's do an example here. So let's say that you have a small business and that this is your IP address and subnet mask. Now let's say that your small business has a total of 12 computers. And all 12 of these computers are on a single network. And these computers belong to different departments. But let's say that you wanted to separate the computers into 3 different networks so that each department won't see the other departments' network traffic. So instead of having one network in your business, you want to break it down into three smaller networks. So the way to break this network down into smaller networks is by?subnetting. Subnetting is done by changing the default subnet mask by borrowing some of the bits that were designated for our hosts and using them to create subnets. So in this subnet mask, we're going to change some of the zeros in the host portion into ones so we can create more networks. So if we leave the subnet mask the way it is, it will give us one network with 256 hosts. Now technically, we have to subtract two hosts because the values that are all ones and zeros are reserved for the broadcast and network address respectively. So we actually have 254 usable hosts. But we need to change this subnet mask, so we can produce the three networks that we need. So for example, let's borrow one bit from the host portion. So here is our new subnet mask. So now the fourth octet is 128. Because when you count the first bit and an octet, it equals 128. So by borrowing one bit, this will divide the network and half. So now instead of having one network with 254 hosts, this will give us two networks, or subnets, with 126 hosts in each subnet.?

No alt text provided for this image

Image credit: powercert

Now just to be clear, this writeup is about subnet masks. This is not a full lesson on subnetting because there's a little more to subtending than what is here. I'm just showing you how subnet masks relate to subnetting.?

No alt text provided for this image

Image credit: Powercert

IP addresses and subnet masks come in five different classes, which are classes A through E. However, three of these classes are for commercial use. So here is a chart of the IP addresses and default subnet masks, which are Class A, B, and C. And you can tell by the number in the first octet of the IP address and by the default subnet mask which class they belong to. Now when an organization needs networking, they will need an IP address class according to the needs of that organization, which is based on how many hosts they have. So if an organization has a very large amount of hosts, it will need a Class A IP address that can produce up to 16 million hosts. A class B IP address can produce up to 65,000 hosts this class is given to medium to large organizations, and a class C IP address can produce 254 hosts. class C IP addresses are used in small organizations and homes that don't have a lot of hosts.?

Now subnet masks can also be expressed in a different method called?CIDR. And CIDR stands for?classless inter-domain routing, which is also known as slash notation. Slash notation is a shorter way to write a subnet mask. And it does this by writing a forward slash and then a number counting the ones in a subnet mask. So for example, if you see an IP address like this 192.168.1.0 /24 with a CIDR notation of /24, this means that the subnet mask is 24 bits in length, meaning it has 24 1s. If the CIDR notation is /25, this means that the subnet mask is 25 bits in length, or if it's /26, this means that the subnet mask is 26 bits in length, or if the CIDR notation is /8. This means that the subnet mask is eight bits in length.?

Thomas Hauck

Java Developer at Chrysler Group LLC

1 年

The following page explains the purpose of subnetting and subnet masks. https://www.seotrance.com/web-technologies/module4/purpose-subnetting-subnetMasks.php

要查看或添加评论,请登录

社区洞察

其他会员也浏览了