Subnetting
Table of Contents
Subnetting
Subnetting is the process of taking a large network and splitting it up into many individual smaller subnetworks or subnets.
By the end of this lesson, you'll be able to explain why subnetting is necessary and describe how subnet masks extend what's possible with just network and host IDs. You'll also be able to discuss how a technique known as CIDR allows for even more flexibility than plain subnetting. Lastly, you'll be able to apply some basic binary math techniques to better understand how all of this works. Incorrect subnetting setups are a common problem you might run into as an IT support specialist, so it's important to have a strong understanding of how this works.That's a lot, so let's dive in. As you might remember from the last lesson, address classes give us a way to break the total global IP space into discrete networks.
If you want to communicate with the IP address 9.100.100.100, core routers on the Internet know that this IP belongs to the 9.0.0.0 Class A Network. They then route the message to the gateway router responsible for the network by looking at the network ID. A gateway router specifically serves as the entry and exit path to a certain network. You can contrast this with core internet routers, which might only speak to other core routers.
![](https://img.haomeiwen.com/i1519536/0d87b0870df2f19d.gif)
Once your packet gets to the gateway router for the 9.0.0.o Class A network, that router is now responsible for getting that data to the proper system by looking at the host ID. This all makes sense until you remember that a single Class A network contains 16,777,216 individual IPs. That's just way too many devices to connect to the same router. This is where subnetting comes in. With subnets you can split your large network up into many smaller ones. These individual subnets will all have their own gateway routers serving as the ingress and egress point for each subnet.
![](https://img.haomeiwen.com/i1519536/fc2a9411dfac0b16.gif)
Subnet Masks
So far, we've learned about network IDs, which are used to identify networks, and host IDs, which are used to identify individual hosts. If we want to split things up even further, and we do, we'll need to introduce a third concept, the subnet ID.At the internet level, core routers only care about the network ID and use this to send the datagram along to the appropriate gateway router to that network. That gateway router then has some additional information that it can use to send that datagram along to the destination machine or the next router in the path to get there. Finally, the host ID is used by that last router to deliver the datagram to the intended recipient machine. Subnet IDs are calculated via what's known as a subnet mask. Just like an address
Subnet masks are 32-bit numbers that are normally written now as four octets in decimal.
The easiest way to understand how subnet masks work is to compare one to an IP address.
Let's work with the IP address 9.100.100.100 again. You might remember that each part of an IP address is an octet, which means that it consists of eight bits. The number 9 in binary is just 1001. But since each octet needs eight bits, we need to pad it with some zeros in front. As far as an IP address is concerned, having a number 9 as the first octet is actually represented as 0000 1001.Other numerals are similar ways.
![](https://img.haomeiwen.com/i1519536/3917d9fd1c52a16e.png)
A subnet mask is a binary number that has two sections. The beginning part, which is the mask itself is a string of ones just zeros come after this, the subnet mask, which is the part of the number with all the ones, tells us what we can ignore when computing a host ID. The part with all the zeros tells us what to keep. Let's use the common subnet mask of 255.255.255.0. This would translate to 24 ones followed by eight zeros. The purpose of the mask or the part that's all ones is to tell a router what part of an IP address is the subnet ID.
A single eight-bit number can represent 256 different numbers, or more specifically, the numbers 0-255. This is a good time to point out that, in general, a subnet can usually only contain two less than the total number of host IDs available. Again, using a subnet mask of 255.255.255.0, we know that the octet available for host IDs can contain the numbers 0-255, but zero is generally not used and 255 is normally reserved as a broadcast address for the subnet. This means that, really, only the numbers 1-254 are available for assignment to a host.
Other ways to present subnet mask, let's say we're dealing with our old friend 9.100.100.100 with a subnet mask of 255.255.255.224. Since that subnet mask represents 27 ones followed by five zeros, a quicker way of referencing this is with the notation /27. The entire IP and subnet mask can be written now as 9.100.100.100/27.
![](https://img.haomeiwen.com/i1519536/8de8765ccbda7687.png)
Basic Binary Math
Binary numbers can seem intimidating at first, since they look so different from decimal numbers. But, as far as the basics go the math behind counting, adding, or subtracting binary numbers is exactly the same as with decimal numbers.
![](https://img.haomeiwen.com/i1519536/db73907e09163c13.png)
There's a pretty simple trick to figure out how many decimal numbers can be represented by a certain number of bits. If you have an eight bit number you can just perform the math two to the power of eight, this gives you 256 which lets you know that an eight bit number can represent 256 decimal numbers, or put another way the numbers zero through 255. A 4 bit number would be two to the power of four, or 16 total numbers. A 16 bit number would be two to the power of 16 or 65,536 numbers.
In fact, binary addition is even simpler than any other base since you only have four possible scenarios. Zero plus zero equals zero just like in decimal. Zero plus one equals one, and one plus zero equals one should also look familiar.
One plus one equals one zero looks a little different, but should still make sense. You carried digit to the next column once you reached 10 in doing decimal edition, you carry a digit to the next column once you reach 2 when doing binary edition.
![](https://img.haomeiwen.com/i1519536/844c9b1639341fd6.png)
Addition is what's known as an operator and there are many operators that computers use to make calculations. Two of the most important operators are OR and AND. In computer logic, a one represents true and a zero represents false.
- The way the OR operator works is you look at each digit, and if either of them is true, the result is true.The basic equation is X or Y equals Z. Which could be read as, if either X or Y is true then Z is true, otherwise, it's false. Therefore one or zero equals one, but zero or zero equals zero.
- The operator AND does what it sounds like it does, it returns true if both values are true. Therefore, one and one equals one, but one and zero equals zero, and zero and zero equals zero, and so on.
![](https://img.haomeiwen.com/i1519536/8a65e1c68037e0c6.gif)
Now you might be wondering why we've covered all of this. No, it's not to confuse you. It's all really to help explain subnet masks a bit more.
A subnet mask is a way for a computer to use and operators to determine if an IP address exists on the same network.
This means that the host ID portion is also known, since it will be anything left out. Let's use the binary representation of our favorite IP address 9.100.100.100 and our favorite subnet mask 255.255.255.0. Once you put one on top of the other and perform a binary and operator on each column, you'll notice that the result is the network ID and subnet ID portion of our IP address or 9.100.100. The computer that just performed this operation can now compare the results with its own network ID to determine if the address is on the same network or a different one.
![](https://img.haomeiwen.com/i1519536/76c746ea76946851.png)
CIDR
Classless Inter-Domain Routing (CIDR /ˈsaɪdər/) is a method for allocating IP addresses and for IP routing.
Address classes were the first attempt at splitting up the global Internet IP space. Subnetting was introduced when it became clear that address classes themselves weren't as efficient way of keeping everything organized. But as the Internet continued to grow, traditional subnetting just couldn't keep up. With traditional subnetting and the address classes, the network ID is always either 8 bit for class A networks, 16 bit for class B networks, or 24 bit for class C networks.
![](https://img.haomeiwen.com/i1519536/c87818f93f8117df.png)
This means that there might only be 254 classing networks in existence, but it also means there are 2,970,152 potential class C networks. That's a lot of entries in a routing table. To top it all off, the sizing of these networks aren't always appropriate for the needs of most businesses. 254 hosts in a class C network is too small for many use cases, but the 65,534 hosts available for use in a class B network is often way too large. Many companies ended up with various adjoining class C networks to meet their needs. That meant that routing tables ended up with a bunch of entries for a bunch of class C networks that were all actually being routed to the same place. This is where CIDR or classless inter-domain routing comes into play. CIDR is an even more flexible approach to describing blocks of IP addresses. It expands on the concept of subnetting by using subnet masks to demarcate networks. To demarcate something means to set something off. When discussing computer networking, you'll often hear the term demarcation point to describe where one network or system ends and another one begins.
In our previous model, we relied on a network ID, subnet ID, and host ID to deliver an IP datagram to the correct location. With CIDR, the network ID and subnet ID are combined into one. CIDR is where we get this shorthand slash notation that we discussed in the earlier video on subnetting. This slash notation is also known as CIDR notation. CIDR basically just abandons the concept of address classes entirely, allowing an address to be defined by only two Individual IDs. Let's take 9.100.100.100 with a net mask of 255.255.255.0. Remember, this can also be written as 9.100.100.100/24.
![](https://img.haomeiwen.com/i1519536/cdaa6795f6ee7f92.png)
CIDR allows for networks themselves to be differing sizes. Before this, if a company needed more addresses than a single class C could provide, they need an entire second class C. With CIDR, they could combine that address space into one contiguous chunk with a net mask of /23 or 255.255.254.0. This means, that routers now only need to know one entry in their routing table to deliver traffic to these addresses instead of two. It's also important to call out that you get additional available host IDs out of this practice. Remember that you always lose two host IDs per network. So, if a /24 network has two to the eight or 256 potential hosts, you really only have 256 minus two, or 254 available IPs to assign. If you need two networks of this size, you have a total of 254 plus 254 or 508 hosts. A single /23 network, on the other hand, is two to the nine or 512. 512 minus two, 510 hosts.
![](https://img.haomeiwen.com/i1519536/2b89f21b2b180bc9.png)
References:
https://www.coursera.org/learn/computer-networking/lecture/z23kl/subnetting
https://www.coursera.org/learn/computer-networking/lecture/vdyzA/subnet-masks
https://www.coursera.org/learn/computer-networking/lecture/NFndv/basic-binary-math
https://www.coursera.org/learn/computer-networking/lecture/4mPiD/cidr
网友评论