CHAPTER 7: TCP/IP and Routing 306 you recall, there are some instances when information is broadcast on a net- work. Imagine broadcasts to and from 16 million hosts. The network would come to a grinding halt from all that traffic. Therefore, although a company may have a Class A network ID, it will segment (divide) that network to avoid having 16 million hosts per network. This process of segmenting is called subnetting. Each segment or subnet must have a unique identifier so that traffic can be sent to the correct location. Because the network ID is a fixed number assigned by the InterNIC, a method was devised to subdivide the assigned network ID by borrowing bits from the host address space, not the network address space. An assigned Class A network assigns the net- work ID using only the first octet. A subnetted Class A network might use bits from the second and third octets to create new subnetworks. Although it’s theoretically possible to use any host octet bits, in practice they are always used starting from the left-most host address space bit mov- ing to the right. In other words, we take the high-order host address bits first. Table 7.9 shows the resulting number of subnets and number of host bits used when subnetting a Class A network. The process is identical to extend the number of subnets on a Class A net- work beyond 256 by taking additional host address bits from the next octet (where w.x and y are used for network and only z is left for host addresses). This process is similar for Class B and Class C networks as well, although the number of subnets and hosts will vary. We can identify the number of bits used for the network by notating how many total bits (counting left to right) are used in the network address. From there, we can calculate how many bits remain for host addresses. A Class A Table 7.9 Subnets Using Host ID Bits Number of Subnets Number of Host Bits Used in Network ID Binary (network ID in bold) 0 0 01000010 . 00000000 . 00000000 . 00000000 1–2 1 01000010 . 00000000 . 00000000 . 00000000 3–4 2 01000010 . 00000000 . 00000000 . 00000000 5–8 3 01000010 . 00000000 . 00000000 . 00000000 9–16 4 01000010 . 00000000 . 00000000 . 00000000 17–32 5 01000010 . 00000000 . 00000000 . 00000000 33–64 6 01000010 . 00000000 . 00000000 . 00000000 65–128 7 01000010 . 00000000 . 00000000 . 00000000 129–256 8 01000010 . 00000000 . 00000000 . 00000000 Understanding Subnetting 307 network subdivided to allow up to 16 subnets uses 12 bits for the network ID, leaving 20 bits for host addresses. This is commonly denoted with a /12 to show that 12 bits are used for the network ID. An example of this nota- tion is 66.192.15.4/12. This is sometimes referred to verbally as “slash 12”. As a reminder, your understanding of subnet masks is important. For the exam, you will not need to do very hard calculations, and you will not need to understand IP addressing at the level explained within this chapter. You will be asked questions that are far less complex than those within this chapter’s exercises. The point of the chapter is to get you so good at IP addressing and give you such a solid explanation of it that when you do get IP addressing questions on your Network exam, you can annihilate them with ease and waste little time on what will be common knowledge to you come test time. HEAD OF THE CLASS… Calculating the Number of Hosts When you begin subnetting, each bit you take from the host address space reduces the number of hosts by a fac- tor of 2. If you can have a maximum of 65,534 hosts and you take 1 bit from the host address space, you reduce the number of hosts you can have by approximately half, or 32,767 (65,534/2). If you keep this in mind, you’ll have an easier time assessing correct scenarios on the exam and in configuring subnets on the job. There are two ways to calculate the total number of possible hosts on any given network. First, you can determine the number of host address bits and total the bit values for each bit position that is a host bit. Although we’ve discussed only the weighted binary val- ues up to 128, they extend far beyond that. To extend these values further to the left (writing this in reverse order to make it easier to read), we would have 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384, and so on. To place this sequence in the proper order, we simply write it from right to left: 16384, 8192, 4096, 2048, and so on. If we want to calculate the number of hosts, we just keep adding, from right to left, the number of host bits. Because a traditional Class A net- work uses the first octet (w) as the network address, that generally leaves 24 bits for host addresses. You would have to extend the previous example out to 24 bits (the previous example goes out to only 15 bits), doubling the previous number. Remember, though, that you must subtract 2 from any result because legal addresses cannot be all 0s or all 1s in the classful addressing scheme. Another way to calculate this, which is much faster and easier if you have a scientific calculator function available to you, is to use the formula [(2 n ) – 2]. Most people can’t do this kind of math in their heads but you can use the x^y function on the Windows Calculator. Start the calculator by selecting Start | Run and typing calc in the Run dialog box, and then pressing Enter. Choose View | Scientific from the menu. Enter the number 2, click the button labeled x^y, then enter the number of bits used for the problem and press Enter or click =. For instance, 2 21 equals 2,097,152. If you’re using 21 bits for the host address space, you will have (2,097,152 – 2) bits available to you, or 2,097,150. The same holds true for network addresses. So, rather than memorizing the many different configurations, use this formula to check your logic, your math, and your answers. To become familiar with the conversions, we rec- ommend creating conversion tables for yourself by writing a conversion on an index card and running through these flash cards until you’re doing conversion in your sleep. CHAPTER 7: TCP/IP and Routing 308 UNDERSTANDING SUBNET MASKING Large networks are subdivided to create smaller subnetworks to reduce over- all network traffic by keeping local traffic on the local subnet and sending all nonlocal traffic to the router. Supernetting is the process of combining smaller networks into one larger network. To create a subnetwork or a super- net, we need to have a system for addressing that allows us to use the net- work ID and host ID within the class-based system. This is accomplished through the use of a subnet mask. In essence, a subnet mask is a 32-bit number that is combined with the IP address (network address and host address) to shield or mask certain bits, thus creating a new, unique number. The 32-bit IP address is composed of the network ID and the host ID. The number of host IDs on a network is variable, but the network ID must be the same for all hosts on a segment. For example, in a Class C network, you can have from 1 to 254 hosts. Suppose you wanted to divide your Class C network into two networks with 100 hosts each? You could use your Class C network ID with a subnet mask and virtually divide your network into two parts. This is done by borrowing bits from the host ID portion of the IP address. When you take bits from the host address space, you reduce the number of potential host addresses roughly by a factor of two. If this sounds a bit confusing, don’t worry. We’re going to walk through this step by step. The underlying concept of subnets and subnet masking involves a binary process called bitwise ANDing. ANDing is actually a fairly simple concept to understand and perform. How Bitwise ANDing Works The term ANDing comes from a form of mathematics called Boolean alge- bra. Computers use Boolean operators in their circuitry. Integrated circuits contain components known as gates and inverters. A gate (or inverter) has one or more inputs. Their output is based on the state of those inputs. The state can only be off (0) or on (1). In Boolean terms, it can only be true (1) or false (0). AND gates will return (or output) 1 if all inputs are 1 and will return 0 if any input is not 1. An OR gate will return 1 if any input is 1 and will return 0 only if no input signals are 1. You may be familiar with Boolean operators in using search engines. You can refine your search by using Boolean operators, including AND and OR. There are other, less commonly used operators such as NAND (not AND) and XOR (exclusive OR), but these are outside the scope of this discussion. Bitwise ANDing simply means that we are performing the logical AND function on each bit. The simple AND statements can be expressed as Understanding Subnet Masking 309 shown here. Rather than a mathematical plus function, this is a comparison between two (or more) values. 0 0 0 0 1 0 1 0 0 1 1 1 Notice that the logical AND function results in a 1 only when both inputs are 1; otherwise, the result is 0. Next, let’s take a slightly more complicated example, still using bitwise ANDing. Look at Table 7.10 to see the results. Again, the result is 1 only when both inputs are 1; otherwise the result is 0. Now let’s explore how bitwise ANDing is used in subnetting. EXERCISE 7.2 Bitwise Anding Exercise 7.2 is designed to give you practice with bitwise ANDing. Each question is followed by a step-by-step answer. What is the result of the following bitwise ANDing? Convert your 1. answer from binary to dotted decimal. Compare 146.64.160.9 and 255.255.224.0. Answer: The result is 146.64.160.0 As you can see, the result from our bitwise ANDing of an IP address and our subnet mask is the underlying network ID, in this case 146.64.160.0. Once you have delineated your subnet IDs and Inputs Dotted Decimal Notation Binary Notation IP address 146.64.160.9 10010001.01000000.10100000.00001001 Subnet mask 255.255.224.0 11111111.11111111.11100000.00000000 Result 146.64.160.0 10010001.01000000.10100000.00000000 Table 7.10 Calculating the results of ANDing First input 1010 1010 1010 Second input 0001 1000 1100 Result of ANDing 0000 1000 1000 CHAPTER 7: TCP/IP and Routing 310 determined your subnet mask, you can check your work by perform- ing the ANDing process to verify the result is the underlying subnet network ID. What is the result of the following bitwise ANDing? Convert your 2. answer from binary to dotted decimal. Compare 146.64.195.36 and 255.255.224.0. Answer: The result is 146.64.192.0 In this example, the underlying network ID was not readily apparent. By using bitwise ANDing, we were able to extract the net- work ID. What is the network ID of this IP address: 146.64.187.112/20? As 3. you recall, the notation /20 indicates we’re using 20 bits from the network address space. Thus, we know that our subnet mask must use 1 in the left-most 20 locations. Our bitwise ANDing results in a network ID of: Default Subnet Mask A subnet mask is a four-octet number used to identify the network ID por- tion of a 32-bit IP address. A subnet mask is required on all class-based net- works, even on networks that are not subnetted. A default subnet mask is Inputs Dotted Decimal Notation Binary Notation IP address 146.64.195.36 10010001.01000000.11000011.00100100 Subnet mask 255.255.224.0 11111111.11111111.11100000.00000000 Result 146.64.192.0 10010001.01000000.11000000.00000000 Inputs Dotted Decimal Notation Binary Notation IP address 146.64.187.112 10010001.01000000.10111011.01110000 Subnet mask 255.255.240.0 11111111.11111111.11110000.00000000 Result 146.64.176.0 10010001.01000000.10110000.00000000 Note You will not need to know ANDing for the Network+ exam; it’s only needed to help with the conversion of IP addresses, testing, and so on. You will need to know how to perform ANDing for your own purposes, but will not be asked direct questions on its function. Understanding Subnet Masking 311 based on the IP address classes we discussed earlier and is used on networks that are not subdivided. If your network is not subnetted, you must use the subnet mask associated with your IP address class. The default subnet masks are shown in dotted decimal format in Table 7.11. We’ve already discussed the fact that a Class A network uses the first octet as the network address. You can see from the default subnet mask shown in the preceding table that the first octet is set to all 1s (dotted deci- mal 255). Recall that a network ID cannot be set to all 1s. Thus, when you use logical ANDing with any Class A network and the default subnet mask, it will always yield the Class A network ID. For example, if the Class A net- work ID is 66.x.y.z, it would be represented as 01000010.x.y.z. The default subnet mask is represented as 11111111.x.y.z. The logical AND function, shown in Table 7.12, yields 01000010.x.y.z. Custom Subnet Mask Most networks are subnetted because the number of hosts allowed in both Class A and Class B networks is well beyond what could be used in practical application. Subnetting is accomplished by using bits from the host address space for the network address space. The custom subnet mask (also called a variable length subnet mask) is used to identify the bits used for a network address versus the bits used for a host address. Custom subnet masks are used when subnetting or supernetting. As we’ve discussed, subnetting is the process of dividing one network into many. Supernetting uses a single IP address to represent many unique IP addresses. Supernetting is the process of allocating a range or block of network IDs (typi- cally Class C) instead of a single Class A or B network ID to preserve Class A and B networks for uses that require a large number of host addresses. Table 7.11 Default Subnet Masks IP Address Class Default Subnet Mask Class A 255.0.0.0 Class B 255.255.0.0 Class C 255.255.255.0 Table 7.12 ANDing Network ID and Default Subnet Mask Class A Network ID = 66 01000010 Default Subnet Mask = 255 11111111 Bitwise AND result = 66 01000010 CHAPTER 7: TCP/IP and Routing 312 To determine the appropriate custom subnet mask (typically referred to simply as subnet mask) for a network, you must first: Determine the 1. number of host bits to be used for subnetting. Determine the 2. new subnetted network IDs. Determine the 3. IP addresses for each new subnet. Determine the appropriate 4. subnet mask. Determine the Number of Host Bits to Be Used We can create a subnet mask by using bits that would normally be used for host addresses. The number of required subnets will determine the number of host bits to be used. An important element of this process is determining the maximum number of subnets you may need in the future, to avoid having to reassign addresses when your network grows. Allow for more subnets than you plan to use, within reason. Also keep in mind that the more host bits you use for subnets, the fewer host IDs you’ll have left for assigning to your connected devices. There is a trade-off between allowing for adequate subnet growth and retaining adequate host IDs for all connected devices. Let’s look at an example using a Class B network, which uses the two left- most octets for the network ID and the two right-most octets for the host ID. If you had no subnets, you would have 65,534 host addresses available to use. Suppose you wanted to have two subnets? How would you determine your subnet mask and how many host IDs would you have available to you? If you take one bit from the host address space, you would be able to cre- ate two networks, each with 32,768 host addresses. If you take two bits from the host address space, you can create three to four subnets of 16,384 host addresses per subnet. Remember, we can’t use host addresses with all 0s or all 1s, so the number of available host addresses is reduced by two each time. Note The rule that network IDs could not consist of all 0s or all 1s came about because at one point in time, router software wasn’t capable of handling such network IDs. The routers being made today are perfectly capable of handling network IDs of all 0s or all 1s, so this rule – while still imposed by Microsoft on their networks – no longer is a technical limita- tion, but merely one of convention. However, although network IDs of all 0s and all 1s are permissible now, you still cannot use host IDs that consist of all 0s or all 1s. Understanding Subnet Masking 313 For this section, we’re going to use the following data. We’re going to use a Class B network with the IP address of 145.64.0.0. We’ll assume we need up to eight subnets to handle our future expansion. We’ll also assume that having up to 8,190 host addresses per subnet will be acceptable for our configuration. We’ve determined our maximum number of subnets and the resulting number of host addresses per subnet. Now that we’ve decided we need a maximum of eight subnets, we must next determine how many host bits we’ll need to use to accomplish this. Thus, we use bits from the third octet (y) and determine how many we’ll need to create eight (remember, counting starts with 0). We can see that we need three bits from the third octet to give us up to eight subnets. We know that 00000111 7. As we’re including 0, using three bits would allow a total of eight subnets. It’s important not to get confused between bit values and number of bits. At this point, we simply need to figure out how many bits are needed, so we start on the right. If we needed 64 net- works, we’d need six bits (00111111 63) and so on. Table 7.13 shows the bit configuration for up to eight subnets using our sample network 145.64.0.0. Notice that we used three bits – the three bits contiguous to our origi- nal network ID. Essentially these bits extend the network address space by three bits. An important thing to remember is that these bits retain their original bit value and that they stay in their original octet – we don’t move the decimal place. For example, the left-most bit of the third octet, while incorporated into the network ID, still retains its value of 128. When we add together the values of the four left-most bits from the third octet, it results in 224 (128 64 32), yielding our highest network ID. Table 7.13 Dotted Decimal and Binary Configuration for Subnetted Networks Network Dotted Decimal Binary (network address in bold) Subnet Range 145.64.0.0 10010001.01000000.00000000.00000000 Undivided Class B network 145.64.0.0 10010001.01000000.00000000.00000000 First subnet address 145.64.224.0 10010001.01000000.11100000.00000000 Last subnet address CHAPTER 7: TCP/IP and Routing 314 Determine the New Subnetted Network IDs Once we’ve taken the number of host address bits we need to create our req- uisite number of subnets, we must determine the resulting addresses of our new subnets. There are two steps in this process. List all the possible binary combinations of the bits taken from the 1. host address space. Calculate the incremental value to each subnet and add to the 2. network address. The possible combinations of the four bits taken from the host address space are shown in Table 7.14. The number of combinations can be denoted as 2 n , where n is the number of bits. In this case, we could represent all pos- sible combinations as 2 3 or 8. Next, we need to calculate the incremental values. Again, we begin with the bit that is contiguous with the original network ID. Table 7.15 shows the results. Determine the IP Addresses for Each New Subnet Earlier we learned that we could denote the number of network ID bits by using the convention w.x.y.z/## where ## is the total number of net- work ID bits. In this case, we have a Class B network, so we know we’re starting with 16 bits for the network. We’ve taken three bits from the host address space, so our total network bits are now 19. Thus, we can denote our new subnetted network in this way: 146.64.0.0/19. Each of Table 7.14 Binary Combinations Combination Number Binary Representation 1 000 2 001 3 010 4 011 5 100 6 101 7 110 8 111 Understanding Subnet Masking 315 Table 7.15 Incremental Binary Values Network Dotted Decimal Binary (network address in bold) 145.64.0.0 10010001.01000000.00000000.00000000 10010001.01000000.00000000.00000000 10010001.01000000.00100000.00000000 10010001.01000000.01000000.00000000 10010001.01000000.01100000.00000000 10010001.01000000.10000000.00000000 10010001.01000000.10100000.00000000 10010001.01000000.11000000.00000000 10010001.01000000.11100000.00000000 Table 7.16 Incremental Dotted Decimal and Binary Values Network Dotted Decimal Binary (network address in bold) 145.64.0.0 /19 10010001.01000000.00000000.00000000 145.64.0.0 /19 10010001.01000000.00000000.00000000 145.64.32.0 /19 10010001.01000000.00100000.00000000 146.64.64.0 /19 10010001.01000000.01000000.00000000 146.64.96.0 /19 10010001.01000000.01100000.00000000 146.64.128.0 /19 10010001.01000000.10000000.00000000 146.64.160.0 /19 10010001.01000000.10100000.00000000 146.64.192.0 /19 10010001.01000000.11000000.00000000 146.64.224.0 /19 10010001.01000000.11100000.00000000 the subsequent subnet IDs can be denoted in a similar fashion as shown in Table 7.16. Test Day Tip As a reminder, you do not have to be able to subnet networks on the Network+ exam, but understanding how they are created is essential to your job and your future in the networking job market. Understanding subnetting will help you to prepare for your exam and eliminate any wrong answers that you may see. . network into two parts. This is done by borrowing bits from the host ID portion of the IP address. When you take bits from the host address space, you reduce the number of potential host addresses. 00000000 9–16 4 01000010 . 00000000 . 00000000 . 00000000 17–32 5 01000010 . 00000000 . 00000000 . 00000000 33 64 6 01000010 . 00000000 . 00000000 . 00000000 65–128 7 01000010 . 00000000 . 00000000 . 00000000 129–256. 146.64.176.0 10010001.01000000.10110000.00000000 Note You will not need to know ANDing for the Network+ exam; it’s only needed to help with the conversion of IP addresses, testing, and so on.