From the course: CompTIA Network+ (N10-009) Cert Prep
Subnet masks
From the course: CompTIA Network+ (N10-009) Cert Prep
Subnet masks
- I've got a little network right here in front of me. Now, if you take a look at this network, first of all, I got one, two, three, four computers on this network and they're all plugged together into this switch in the center. But I also have a router. Now, this router also has an IP address because routers always have an IP address that's part of one local area network, but it also has another IP address, which I don't have on here right now that helps it go out into the big internet. Now here's the issue. Now we know about ARP from the previous episode, but the challenge we have is how do we ARP? For example, if this computer right here wants to talk to this computer right here, he would normally just broadcast out an ARP, get the IP address and everything would be great. However, what if this computer right here wants to talk to somebody way out on the internet? In that case, he's still going to have to ARP, but he's going to have to ARP to get to his default gateway to his router. So what we need is something built into every network that identifies it as its own local area network, and also a mechanism that allows an individual computer to determine, hey, if I'm talking to this IP address, this is a local call. Just go ahead and ARP. However, if it's a long distance call, go ahead and talk through your default gateway through your router to get out to the internet, and that's where your subnet mask really comes into play. Now to help get us all wrapped around on this concept, I've got something laid out right here I'd like you to take a look at. Now what we're looking at down here is what we're going to call my network ID. The network ID is the part of the network numbering system that has to be identical for every computer on this particular network. Now, on my network, which I've decided to set up this way, all the computers are going to be 232.25.208 and then here I put zero. The idea behind this is that when I'm setting up these network IDs, no computer can have just a zero as part of its numbering system because it's reserved for what we call the network ID. So I could have a computer in this network ID that's called 232.25.208.14, but no computer could be called 232.25.208.0. That's reserved for this network ID. Now the part over here that changes for every individual computer is going to be called the host ID. So what I'm going to do is I'm going to put a little skewer here to kind of separate it, and that's where this guy called the subnet mask comes into play. A subnet mask is a string of ones followed by a certain number of zeros. Everywhere there is a one, the numbers have to stay the same. Anywhere there's a zero, you can change the values. So in this particular case, our subnet mask is going to be 255 255 255 0. Now I need to warn you about something for a minute. Always remember, computers don't use the dotted decimal notation. It's just for us human beings, when we type in 255 255 255 0 into our computers, he instantaneously changes it into what it really is, 24 ones followed by eight zeros. So let's take a look at this example one more time. Now, in this particular example, the way we've got it set up is that the first three numbers are identical, and then the last number can be anywhere from 1 to 254. We can't use zero and we can't use 255, but watch this. So what I've done here is I've replaced the third set of ones with all zeros. So let me go ahead and get the right value in there. And what we now have is a subnet mask of 255 255 00. Now as you're looking at this stuff, there's one thing you need to keep in mind. We always use these terms two five fives and zeros, but we know that the computer just uses all ones and zeros. So what we can do is we can simply, instead of saying 255 255 255 0 or 255 255 00, we can talk like the cool kids and simply count the number of ones. So taking a look at this, we'll see we've got 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16. So what is commonly done is then we simply say this is a WAC 16 subnet. That little slash is what I call a WAC, and that is common terminology, so you want to get used to it. The cool part now is that when we change the subnet mask to something like this, we could literally, if we wanted to, say only the first two numbers have to be the same, you can use any other two numbers that you want to use, it doesn't matter because they're all going to work. So with a WAC 16 subnet, that means only the first two digits have to be the same for all the computers. So our network ID could be anything from I guess 232.25.1.1 to 232.25.255.254. I mean, think how many different computers we could have on this little tiny network. So usually the subnet mask gets smaller for really huge networks and it gets longer like a WAC 24, 255 255 255 0 for smaller networks. In fact, we know these things ahead of time. For example, if we use a WAC 24 subnet mask, remember 255 255 255 0, we get exactly 254 hosts. So that means the smallest network, at least based on what we know so far we could make, would have up to 254 hosts in it. Remember, you can't use 0 or 255, okay? So this really makes things a big deal when it comes to making these subnets right at what we call the dots, where it's only two five fives and zeros. We've got other episodes coming up where we're going to make it a little bit more interesting. So basically, in order to make our network work, all of the computers within this one broadcast domain, within this one network ID are all going to have to have the same subnet mask. And wherever there's a 255 in the subnet mask, they're going to have to have the exact numbers. Now, this gets put into every computer in existence. So what I want to do right now is take a moment and walk you through a Mac, a Windows system and a Linux box to see where these numbers exist on your computer. Here's an example of network settings on a modern Mac system. You'll see that we have an IP address, a subnet mask, and what they call the router is the default gateway. Now, taking a look at Windows, here you can see again, now you got to dig a little bit to find it, but I have an IPv4 address as they call it, and then I see my subnet mask, and if we look down a little bit more, you can actually see where it says default gateway. Last is Linux. With a Linux system, you'll see that we have an IP address, we have a subnet mask, and what they call the default route is the default gateway. Now that we've got these values punched into our operating system, let's put all of this to work. Now, in this particular example, I've got all of these computers and what they're on is a network ID of 232.25.208 with a WAC 24 or 255 255 255.0 subnet. Now, let's say this computer right here wants to talk to, I don't know, 232.25.208.14. Got it? So what he'll do is work with the subnet mask to determine whether this is a local call or if he needs to send it out to the default gateway. Now, I've changed the board here a little bit. Let's watch this in action. So what we have here is, this is my local computer. He's going to be 232.25.208.22 in this case. So the subnet mask here is going to be 255 255 255.0, or for us cool kids, a WAC 24. Remember it's 24 ones followed by eight zeros. Now in this one particular example, he wants to talk to a computer with the IP address of 232.25.208.9. Yeah, I know I said 14. Let's make it nine instead. The subnet mask allows my local computer to take a look at the address that he's going to and determine if it's a local call or a long distance call. So with the subnet mask, anywhere there's a one, the numbers have to be the same. Anywhere there's a zero, they can be different. So in this particular case, comparing my IP address to who I want to talk to, the first three values, the first three octets are the same as mine. Therefore, I know that it's a local call, and since it's a local call, all I need to do is ARP out onto the network, get the MAC address of whoever I want to talk to, and off it goes. So that's easy. Now, what happens when it's not within my network ID? Okay, so once again, this row right here is my local computer, 232.25.208.22. This time, he wants to talk to a computer at 232.52.208.9. So I want you to look at this very, very closely because it looks very similar to the previous example. But look at the difference right here. The big difference is that we have changed one of the values on the left hand side on the network ID side. Now, I could have put a big complicated, much different number in there, but that would've been too easy for you. It's just like if you're dialing somebody and you accidentally transpose two numbers and you end up calling somebody in a far away place, well, the exact same thing happens here when it comes to IP addresses. So let's look and let's run through the system and let's use the subnet mask and determine is this a local or a long distance call? Here we go. So we take a look at the subnet mask. Remember, anything where there's a one, that numbers have to be identical. Anywhere on this side, they could be different. So as we compare these two numbers, 232, they're the same. But look right here. This is 25 and this is 52. The numbers are different. Instantaneously, we know that this address right here is not a part of our local area network. We're going to have to send all of this information out through the default gateway because it ain't local. Now, the thing you need to remember about all this is that we're really not changing the IP packet part. We're not changing the IP addresses. All we're doing is we're telling the individual host who to ARP for. If it's not a local call, it needs to ARP to the default gateway, and it knows the default gateway's IP address because you typed it in when you set the system up. And that's why we have to type in the default gateway. That is your router, and that's where all this information comes from. So when you're working with computers, the most important thing to remember is number one, you're going to have to have an IP address. Number two, you're going to have to have a subnet mask. And number three, you're going to have to have a default gateway because all of these guys work together to make sure your data goes where it needs to go. Thanks subnet mask. - Great job, Mike. But let me cover a couple of new topics. What we have been talking about so far in this video has been what's called fixed length subnet masking, otherwise known as FLSM. An alternative is an approach called variable length subnet mask or VLSM. A VLSM allows for a more effective use of IP addressing. As we just discussed, an FLSM applies to every subnet of a fixed size in the network. For example, if there are two subnets on a network, one with a host and one with 48 hosts, the same subnet mask could be used for both subnets. And as we just learned, each of these subnets could have up to 254 hosts available, each with its own IP address. Using VLSM though, we can create sub subnets, so it's like the smaller version of the subnet each with its own different subnet mask. In our example network with two subnets of 48 and eight hosts respectively, we can assign a subnet mask of 255.255.255.192, or a /26 to the larger subnet of a subnet mask, along with 255.255.255.240. See, we get to divide these up in different ways. That is the benefit of VLSM. There are still 178 hosts available for future subnets with the subnet mask of 255.255.255.0 or /24. The main thing that you want to take note of with VLSM is that you don't want to waste any subnet masks or hosts. You get to preserve them and actually map them to only the essential amount of networks and hosts that you need.