10.7 Creating a Subnet 10.7.1 Range of bits needed to create subnets Instructor Note The purpose of this target indicator is to correctly discern how many bits may be "stolen" or "borrowed" from the host fields to extend the network number. The first step in this process is identifying the IP address as class A (thus a default subnet mask of 255.0.0.0), class B (thus a default subnet mask of 255.255.0.0), or class C (thus a default subnet mask of 255.255.255.0). This establishes the "minimum" mask. The maximum mask must leave at least 2 bits for numbering hosts. To create subnets, you must extend the routing portion of the address. The Internet knows your network as a whole, identified by the Class A, B, or C address, which defines 8, 16, or 24 routing bits (the network number). The subnet field will become additional routing bits, so that the routers within your organization can recognize different locations, or subnets, within the whole network. Question: In the address 131.108.0.0, which are the routing bits?Answer: 131.108 - That's the 16 bit Class B network number. Question: What are the other two octets (16 bits) of the address 131.108.0.0 used for? Answer: Well, as far as the Internet knows, that's just a 16 bit host field, because that's what a Class B address is - a 16 bit network number and a 16 bit host number. Question: What part of the address 131.108.0.0 is the subnet field?Answer: When you decide to create subnets, you must divide the original host field (16 bits in the case of Class B) into two parts - the subnet field and the host field. This is sometimes referred to as "borrowing" some of the original host bits to create the subnet field. The other networks in the Internet won't care - they look at the address the same - all they really see is the Class A, B, or C network number, and send the packet on to its destination. The minimum number of bits that you can borrow is 2, regardless of whether you're working with a Class A, B, or C network1 because at least 2 bits must remain for host numbers2, the maximum varies by address class. Address Class Size of Default Host Field Maximum Number of Subnet Bits A 24 22 B 16 14 C 8 6 The subnet field always follows immediately after the network number. That is, the borrowed bits must be the first n bits of the default host field, where n is the desired size of the new subnet field. The subnet mask is the tool used by the router to determine which bits are routing bits and which bits are host bits. Web Links What's a Netmask? 1 Previous standards did not allow for the use of subnets obtained by borrowing 1 bit (with only 1 subnet bit, the subnet field can only have two values: subnet 0 is part of the network address, and subnet 1 would be part of the network broadcast address) although many devices can now support subnets obtained by borrowing 1 bit, it is still common practice to avoid doing this to insure compatibility with legacy devices; for our purposes here, you will always borrow at least 2 bits.2 Similarly, a 1 bit host field would allow only for host 0, which is part of the network address, and host 1, which is part of the broadcast address, leaving 0 valid host addresses. 10.7 Creating a Subnet 10.7.2 Determining subnet mask size Instructor Note The more bits stolen, the more possible combinations of those bits. More combinations means more subnetwork numbers. Subnet masks use the same format as IP addresses. They are 32 bits long and are divided into four octets, written in dotted decimal format. Subnet masks contain all 1s in the network bit positions (determined by the address class) as well as the desired subnet bit positions, and contain all 0s in the remaining bit positions, designating them as the host portion of an address. By default, if you borrow no bits, the subnet mask for a Class B network would be 255.255.0.0, which is the dotted decimal equivalent of 1s in the 16 bits corresponding to the Class B network number. If 8 bits were to be borrowed for the subnet field, the subnet mask would include 8 additional 1 bits, and would become 255.255.255.0. For example, if the subnet mask 255.255.255.0 were associated with the Class B address 130.5.2.144 (8 bits borrowed for subnetting), the router would know to route this packet to subnet 130.5.2.0 rather than to just network 130.5.0.0 Another example is the Class C address 197.15.22.131, with a subnet mask of 255.255.255.224. With a value of 224 in the final octet (11100000 in binary), the 24 bit Class C network portion has been extended by 3 bits, to make the total 27 bits. The 131 in the last octet now presents the third usable host address in the subnet 197.15.22.128. The routers in the Internet (that don't know the subnet mask) will only worry about routing to the Class C network 197.15.22.0, while the routers inside that network, knowing the subnet mask, will be looking at 27 bits to make a routing decision. Web Links What's a Netmask? 10.7 Creating a Subnet 10.7.3 Computing subnet mask and IP address Instructor Note There are several techniques for calculating the number of subnets when given the subnet mask and IP address. From the IP address, you can determine its class and hence the default subnet mask. Find how many bits beyond the default mask the actual subnet mask has been extended. This is the number of bits "borrowed" or stolen to create subnetworks. The formula 2n - 2, where n is the number of bits stolen, gives the number of USABLE subnetworks created. Another way to see this is to write out the powers of two, and find the exponent of two that matches the number of bits stolen. Whatever that power of two equals (less the 2 reserved numbers) gives the number of subnets. Whenever you borrow bits from the host field, it is important to note the number of additional subnets that are being created each time you borrow one more bit. You have already learned that you cannot borrow only 1 bit; the fewest you may borrow is 2 bits.Borrowing 2 bits creates four possible subnets (22) (but you must always remember that there are two reserved/unusable subnets). Each time you borrow another bit from the host field, the number of subnets created increases by a power of 2. The eight possible subnets that are created by borrowing 3 bits is equal to 23 (2 x 2 x 2). The sixteen possible subnets created by borrowing 4 bits is equal to 24 (2 x 2 x 2 x 2). From these examples, it is easy to see that each time you borrow another bit from the host field, the number of possible subnets doubles.Question: How many bits are being borrowed (how long is the subnet field) for a Class B network using a subnet mask of 255.255.240.0?Answer: The first two octets of the mask (255.255) correspond with the 16 bits in a Class B network number. Remember that the subnet field is represented by all the additional "1" bits past that. The number 240 decimal is 11110000 in binary, and you can see that you are using 4 bits for the subnet field. Question: How many possible subnets are there with a 4 bit subnet field? Answer: Start with finding the smallest 4 bit number - 0000 - then the largest 4 bit number - 1111 (15). So the possible subnets are 0-15, or sixteen subnets. However, you know you cannot use subnet 0 (it's part of the network address), and you cannot use subnet 15 (1111) either (broadcast address). So this 4 bit subnet field gives you fourteen usable subnets (1-14). Web Links What's a Netmask? 10.7 Creating a Subnet 10.7.4 Computing hosts per subnetwork Instructor Note There are several techniques for calculating the number of subnets when given the subnet mask and IP address. From the IP address, you can determine its class and hence the default subnet mask. Find how many bits beyond the default mask the actual subnet mask has been extended. This is the number of bits "borrowed" or stolen to create subnetworks. The formula 2m - 2, where m is the number of bits NOT stolen, gives the number of USABLE host numbers created. Another way to see this is to write out the powers of two, and find the exponent of two that matches the number of bits NOT stolen. Whatever that power of two equals (less the 2 reserved numbers) gives the number of hosts per subnetwork. Each time you borrow 1 bit from a host field, there is 1 less bit remaining in the field that can be used for host numbers. Specifically, each time you borrow another bit from the host field, the number of host addresses that you can assign decreases by a power of 2 (gets cut in half). To help you understand how this works, use a Class C network address as an example. If there is no subnet mask, all 8 bits in the last octet are used for the host field. Therefore, there are 256 (28) possible addresses available to assign to hosts (254 usable addresses, after you subtract the 2 you know you can't use). Now, imagine that this Class C network is divided into subnets. If you borrow 2 bits from the default 8 bit host field, the host field decreases in size to 6 bits. If you write out all of the possible combinations of 0s and 1s that could occur in the remaining 6 bits, you would discover that the total number of possible hosts that could be assigned in each subnet would be reduced to 64 (26). The number of usable host numbers would be reduced to 62. In the same Class C network, if you borrow 3 bits, the size of the host field decreases to 5 bits and the total number of hosts that you could assign to each subnet would be reduced to 32 (25). The number of usable host numbers would be reduced to 30. The number of possible host addresses that can be assigned to a subnet is related to the number of subnets that have been created. In a Class C network, for example, if a subnet mask of 255.255.255.224 has been applied, then 3 bits (224 = 11100000) would have been borrowed from the host field, and 8 (minus 2) useable subnets would have been created, each having 32 (minus 2) usable host addresses. Exercise:Divide the last octet into two parts: a subnet field and a host field. If there are 32 possible host addresses that can be assigned to each subnet, then their IP addresses would fall within the range of numbers (but remember the 2 unusable host addresses in each subnet!).In a Class C network 199.5.12.0 with subnet mask 255.255.255.224, to which subnet would host 199.5.12.97 belong? (hint: 97 = 01100001 binary)subnet 0? subnet 1? subnet 2? subnet 3? subnet 4? none of the above? Web Links What's a Netmask? 10.7 Creating a Subnet 10.7.5 Boolean AND operation Instructor Note The key to understanding the result of the Boolean ANDing of an IP address and a subnet mask is to realize that once created, subnetworks are valid network numbers as far as the "outside" world is concerned. So as with the earlier calculation, the bit-by-bit ANDing of the IP address and the subnet mask gives the subnetwork number. As you have already learned, the lowest numbered address in an IP network is the network address (the network number plus 0 in the entire host field). This also applies to a subnet; the lowest numbered address is the address of the subnet. Lab Activity This lab focuses on a Class B network with three subnets. It will help you develop a better understanding of IP subnet mask. In order to route a data packet, the router must first determine the destination network/subnet address by performing a logical AND using the destination host's IP address and the subnet mask for that network. The result will be the network/subnet address, which is what a router uses to determine how to forward the packet.Imagine that you have a Class B network with the network number 172.16.0.0. After assessing the needs of your network, you decide to borrow 8 bits in order to create subnets. As you learned earlier, when you borrow 8 bits with a Class B network, the subnet mask is 255.255.255.0. Someone outside the network sends data to the IP address 172.16.2.120. In order to determine where to deliver the data, the router ANDs this address with the subnet mask. When the two numbers are ANDed, the host portion of the result will always be 0. What is left is the network number, including the subnet. Thus, the data is sent to subnet 172.16.2.0, and only the final router notices that the packet should be delivered to host 120 in that subnet. Now, imagine that you have the same network, 172.16.0.0. This time, however, you decide to borrow only 7 bits for the subnet field. The binary subnet mask for this would be 11111111.11111111.11111110.00000000. What would this be in dotted decimal notation? Again, someone outside the network sends data to host 172.16.2.120. In order to determine where to send the data, the router again ANDs this address with the subnet mask. As before, when the two numbers are ANDed, the host portion of the result is 0. So what is different in this second example? Everything looks the same - at least in decimal. The difference is in the number of subnets available, and the number of hosts that can be in each subnet, and you can only see that by comparing the two different subnet masks. 1With 7 bits in the subnet field, there can be only 126 subnets. How many hosts can there be in each subnet? How long is the host field? With 9 bits for host numbers, there can be 510 hosts in each of those 126 subnets. Web Links How Boolean Logic Works 1 The two graphics on this page include something you'll learn more about later - an alternate way to express the subnet mask. You learned that the 1s of the mask represent the routing bits - the network plus the subnet. 255.255.255.0 indicates there are 24 total routing bits. This is sometimes indicated by following an IP address with "/24", as in 131.108.3.1 /24 - this says the same thing as the longer subnet mask. 10.7 Creating a Subnet 10.7.6 IP configuration on a network diagram Instructor Note The importance of this target indicator is to relate IP address configuration involving subnets to actual logical network topologies. As an activity, have the students assign IP address to the teaching topology. Types of IP Addressing ProblemsProblem:Given 195.137.92.0 and needing 8 usable subnets, find the subnetwork numbers, the ranges of host numbers, and subnetwork broadcast numbers.Solution:IP Address is a class C. Default subnet mask is 255.255.255.0. We need to extend the network number by enough bits to give 8 usable subnets. Stealing 2 bits yields 2 usable subnets, stealing 3 bits yields 6 usable subnets, so we must steal 4 bits to get 14 usable subnets, of which we needed 8. This makes the subnet mask 255.255.255.240. So the Network number is 195.137.92.NNNN HHHH where Ns stand for network extension bits (subnets) and Hs stand for host numbers. Next we must number the subnets; there are 16 combinations of 4 bit binary numbers but they retain their place value within the last octet. When you configure routers, you must connect each interface to a different network segment. Then each of these segments will become a separate subnet. You must select an address from each different subnet to assign to the interface of the router that connects to that subnet. Each segment of a network - the actual wires and links - must have different network/subnet numbers. The Figure shows what a network diagram might look like using a subnetted Class B network. Web Links Introduction to the Internet Protocols 10.7 Creating a Subnet 10.7.7 Host/subnet schemes Instructor Note An unfortunate by-product of creating subnetworks is that the reserved network and broadcast numbers now exist for each and every subnetwork created. Thus entire blocks of IP addresses, which begin with these subnetwork id and subnetwork broadcast numbers, are wasted. So the network administrator must strike a balance between the number of subnets required, the hosts per subnet that is acceptable, and the resulting waste of addresses. One of the decisions that you must make whenever you create subnets is to determine the optimal number of subnets and hosts (Note: The number of subnets required in turn determines the number of hosts available. For example, if you borrow 3 bits with a Class C network, only 5 bits remain for hosts). Lab Activity This lab focuses on a Class C network with three subnets and using a Custom Subnet Mask. It will help you develop a better understanding of IP subnet masks. You have already learned that you cannot use the first and last subnet. You also cannot use the first and last address within each subnet - one is the broadcast address of that subnet, and the other is part of the network address. When you create subnets, you lose quite a few potential addresses. For this reason, network administrators must pay close attention to the percentage of addresses that they lose by creating subnets.Example:If you borrow 2 bits with a Class C network, you create 4 subnets, each with 64 hosts. Only 2 of the subnets are usable and only 62 hosts are usable per subnet, leaving 124 usable hosts out of 254 that were possible before you chose to use subnets. This means you are losing 51% of your addresses. Imagine, this time, that you borrow 3 bits. You now have 8 subnets, of which only 6 are usable, with 30 usable hosts per subnet. This gives you a total of 180 usable hosts, down from 254, but now you are losing only 29% of your addresses. Whenever you create subnets, you need to take into consideration future network growth and the percentage of addresses that you would lose by creating subnets. Web Links Introduction to the Internet Protocols 10.7 Creating a Subnet 10.7.8 Private addresses Instructor Note There are certain IP address ranges reserved for private IP addressing schemes. Not everyone needs connectivity to the Internet. Another relevant discussion is IP address depletion. Various schemes are being pursued to deal with IP address depletion. First there is NAT. Second there is CIDR. Third there is IP v6. While all of these have there benefits, students should be well-grounded in classful IP addresses. There are certain addresses in each class of IP address that are not assigned. These addresses are called private addresses. Private addresses might be used by hosts that use network address translation (NAT), or a proxy server, to connect to a public network; or by hosts that do not connect to the Internet at all. Many applications require connectivity within only one network and do not need external connectivity. In large networks, TCP/IP is often used, even when network layer connectivity outside the network isnt needed. Banks are good examples. They may use TCP/IP to connect to automatic teller machines (ATMs). These machines do no connect to the public network, so private addresses are ideal for them. Private addresses can also be used on a network where there are not enough public addresses available. The private addresses can be used together with a network address translation (NAT) server or a proxy server to provide connectivity to all hosts in a network that has relatively few public addresses available. By agreement, any traffic with a destination address within one of the private address ranges will NOT be routed on the Internet. Summary This chapter discussed routing and addressing as it relates to the network layer of the OSI model. You learned that: internetworking functions of the network layer include network addressing and best path selection for traffic. there are two addressing methods: flat and hierarchical. there are three classes of IP addresses that an organization can receive from InterNIC: Class A, B, and C. InterNIC reserves Class A addresses for governments throughout the world, Class B addresses for medium-size companies, and Class C addresses for all other entities when written in a binary format, the first bit of a Class A address is always 0 the first 2 bits of a Class B address are always 10, and the first 3 bits of a Class C address are always 110 in order to provide extra flexibility for the network administrator, networks --- particularly large ones --- are often divided into smaller networks called subnetworks or subnets subnets are concealed from outside networks by using masks referred to as subnet masks In the next chapter, you will see how devices and routing protocols operate at the network layer.