Chapter 4 – (Day) TCP/IP Study Guide Subnets and Subnetting Introduction: An IP (Internet Protocol) address is a unique identifier for a node or host connection on an IP network. An IP address is a 32 bit binary number usually represented as 4 decimal values, each representing 8 bits, in the range 0 to 255 (known as octets) separated by decimal points. This is known as "dotted decimal" notation. Example: 140.179.220.200 It is sometimes useful to view the values in their binary form. 140 .179 .220 .200 10001100.10110011.11011100.11001000 Every IP address consists of two parts, one identifying the network and one identifying the node. The Class of the address and the subnet mask determine which part belongs to the network address and which part belongs to the node address. Address Classes: There are 5 different address classes. You can determine which class any IP address is in by examining the first 4 bits of the IP address. Class A addresses begin with 0xxx, or 1 to 126 decimal. Class B addresses begin with 10xx, or 128 to 191 decimal. Class C addresses begin with 110x, or 192 to 223 decimal. Class D addresses begin with 1110, or 224 to 239 decimal. Class E addresses begin with 1111, or 240 to 254 decimal. The first number in the IP address identifies the network class the address belongs to. A class A address has a range of 1 to 126. In binary, the first bit of the first octet is zero. This means that the first bit identifies the address class, and the remaining seven bits of the first octet identify the network. The remaining 24 bits can be used to identify the host. Because the first bit is zero, there are fewer than 128 class A networks, but each network can contain literally millions of hosts. However, Class A addresses are typically used to create a larger network of small networks through the use of subnets. If the first two bits of the IP address consist of 1 0, then it is a class B address, which establishes the address range of 128 to 191. In a class B network, the first two bits identify the class of network, the next fourteen bits identify the network itself, and the last sixteen bits identify the host. There are thousands of class B networks available, and each network can contain thousands of hosts. Class B networks are predominantly used by universities and some Internet Service Providers. For a class C network, the first three bits of the IP address consist of 1 1 0. Here the first three bits are class identifiers, the next 21 bits are the network address, and the last eight bits identify the host. This combination calls for millions of class C network addresses, where each network is composed of fewer than 254 hosts. Subnetting: Subnetting an IP Network can be done for a variety of reasons, including organization, use of different physical media (such as Ethernet, FDDI, WAN, etc.), preservation of address space, and security. The most common reason is to control network traffic. In an Ethernet network, all nodes on a segment see all the packets transmitted by all the other nodes on that segment. Performance can be adversely affected under heavy traffic loads, due to collisions and the resulting retransmissions. A router is used to connect IP networks to minimize the amount of traffic each segment must receive. In an effort to create smaller broadcast domains and to better utilize the bits in the host ID, an IP network can be subdivided into smaller networks, each bounded by an IP router and assigned a new subnetted network ID, which is a subset of the original class-based network ID. This creates subnets, subdivisions of an IP network each with their own unique subnetted network ID. Subnetted network IDs are created by using bits from the host ID portion of the original class-based network ID. Consider the example in the figure below. The class B network of 139.12.0.0 can have up to 65,534 nodes. This is far too many nodes, and in fact, the current network is becoming saturated with broadcast traffic. The subnetting of network 139.12.0.0 should be done in such a way so that it does not impact, nor require, the reconfiguration of the rest of the IP internetwork. Network 139.12.0.0 is subnetted by utilizing the first 8 host bits (the third octet) for the new subnetted network ID. When 139.12.0.0 is subnetted, as shown in the next figure, separate networks with their own subnetted network IDs (139.12.1.0, 139.12.2.0, 139.12.3.0) are created. The router is aware of the separate subnetted network IDs and will route IP packets to the appropriate subnet. Note that the rest of the IP internetwork still regards all the nodes on the three subnets as being on network 139.12.0.0. The other routers in the IP internetwork are unaware of the subnetting being done on network 139.12.0.0, and therefore require no reconfiguration. A key element of subnetting is still missing. How does the router who is subdividing network 139.12.0.0 know how the network is being subdivided and which subnets are available on which router interfaces? To give the IP nodes this new level of awareness, it must be told exactly how to discern the new subnetted network ID regardless of Internet Address Classes. To tell an IP node exactly how to extract a network ID, either class-based or subnetted, a subnet mask is used. Guidelines for Subnettting: Decide how many segments your network will have. o Determine maximum number of hosts on your network. More subnets means LESS hosts per subnet More subnets also means LESS possible hosts on the ENTIRE network. Eliminate 0 (00000000) and 255 (11111111) for each possible subnet. o Leave room for future expansion and improvement. Subnet Masking (Default): Applying a subnet mask to an IP address allows you to identify the network and node parts of the address. Performing a bitwise logical AND operation between the IP address and the subnet mask results in the Network Address or Number. For example, using our test IP address and the default Class B subnet mask, we get: 10001100.10110011.11110000.11001000 140.179.240.200 Address 11111111.11111111.00000000.00000000 255.255.000.000 B Subnet Mask -------------------------------------------------------10001100.10110011.00000000.00000000 140.179.000.000 Address Class B IP Default Class Network Default subnet masks: Address Class Bits for Subnet Mask Subnet Mask Class A 11111111 00000000 00000000 00000000 255.0.0.0 Class B 11111111 11111111 00000000 00000000 255.255.0.0 Class C 11111111 11111111 11111111 00000000 255.255.255.0 Address Class Bits for Subnet Mask Network Prefix Class A 11111111 00000000 00000000 00000000 /8 Class B 11111111 11111111 00000000 00000000 /16 Class C 11111111 11111111 11111111 00000000 /24 Additional bits can be added to the default subnet mask for a given Class to further subnet, or break down, a network. When a bitwise logical AND operation is performed between the subnet mask and IP address, the result defines the Subnet Address. There are some restrictions on the subnet address. Node addresses of all "0"s and all "1"s are reserved for specifying the local network (when a host does not know it's network address) and all hosts on the network (broadcast address), respectively. This also applies to subnets. A subnet address cannot be all "0"s or all "1"s. This also implies that a 1 bit subnet mask is not allowed. This restriction is required because older standards enforced this restriction. Recent standards that allow use of these subnets have superceded these standards, but many "legacy" devices do not support the newer standards. If you are operating in a controlled environment, such as a lab, you can safely use these restricted subnets. More Restrictive Subnet Masks: To calculate the number of subnets or nodes, use the formula (2^n - 2) where n = number of bits in either field. Multiplying the number of subnets by the number of nodes available per subnet gives you the total number of nodes available for your class and subnet mask. Also, note that although subnet masks with noncontiguous mask bits are allowed they are not recommended. Example: 10001100.10110011.11011100.11001000 140.179.220.200 11111111.11111111.11100000.00000000 255.255.224.000 -------------------------------------------------------10001100.10110011.11000000.00000000 140.179.192.000 Address 10001100.10110011.11011111.11111111 140.179.223.255 Address IP Address Subnet Mask Subnet Broadcast In this example a 3 bit subnet mask was used. There are 6 subnets available with this size mask (remember that subnets with all 0's and all 1's are not allowed). Each subnet has 8190 nodes. Each subnet can have nodes assigned to any address between the Subnet address and the Broadcast address. This gives a total of 49,140 nodes for the entire class B address subnetted this way. Notice that this is less than the 65,534 nodes an unsubnetted class B address would have. Subnetting always reduces the number of possible nodes for a given network. Step 1: Determining the Number of Host Bits The number of host bits being used for subnetting determines the possible number of subnets and hosts per subnet. Before you choose how many host bits, you should have a good idea of the number of subnets and hosts you will have in the future. Using more bits for the subnet mask than required will save you the time of reassigning IP addresses in the future. The more host bits that are used, the more subnets (subnetted network IDs) you can have—but with fewer hosts. If you use too many host bits, it will allow for growth in the number of subnets, but will limit the growth in the number of hosts. If you use too few hosts, it will allow for growth in the number of hosts, but will limit the growth in the number of subnets. For example, Figure 9 illustrates the subnetting of up to the first 8 host bits of a class B network ID. If we choose one host bit for subnetting, we obtain 2 subnetted network IDs with 16,382 hosts per subnetted network ID. If we choose 8 host bits for subnetting, we obtain 256 subnetted network IDs with 254 hosts per subnetted network ID. Figure 9 Subnetting a class B network ID In practice, network administrators define a maximum number of nodes they want on a single network. Recall that all nodes on a single network share all the same broadcast traffic; they reside in the same broadcast domain. Therefore, growth in the amount of subnets is favored over growth in the amount of hosts per subnet. Follow these guidelines to determine the number of host bits to use for subnetting. 1. Determine how many subnets you need now and will need in the future. Each physical network is a subnet. WAN connections may also count as subnets depending on whether your routers support unnumbered connections. 2. Use additional bits for the subnet mask if: o You will never require as many hosts per subnet as allowed by the remaining bits. o The number of subnets will increase in the future, requiring additional host bits. To determine the desired subnetting scheme, you will start with an existing network ID to be subnetted. The network ID to be subnetted can be a class-based network ID, a subnetted network ID, or a supernet. The existing network ID will contain a series of network ID bits which are fixed, and a series of host ID bits which are variable. Based on your requirements for the number of subnets and the number of hosts per subnet, you will choose a specific number of host bits to be used for the subnetting. Table 16 shows the subnetting of a class A network ID. Based on a required number of subnets, and a maximum number of hosts per subnet, a subnetting scheme can be chosen. Table 16 Subnetting a Class A Network ID Required number of subnets Number of host bits Subnet Mask Number of hosts per subnet 1-2 1 255.128.0.0 or /9 8,388,606 3-4 2 255.192.0.0 or /10 4,194,302 5-8 3 255.224.0.0 or /11 2,097,150 9-16 4 255.240.0.0 or /12 1,048,574 17-32 5 255.248.0.0 or /13 524,286 33-64 6 255.252.0.0 or /14 262,142 65-128 7 255.254.0.0 or /15 131,070 129-256 8 255.255.0.0 or /16 65,534 257-512 9 255.255.128.0 or /17 32,766 513-1,024 10 255.255.192.0 or /18 16,382 1,025-2,048 11 255.255.224.0 or /19 8,190 2,049-4,096 12 255.255.240.0 or /20 4,094 4,097-8,192 13 255.255.248.0 or /21 2,046 8,193-16,384 14 255.255.252.0 or /22 1,022 16,385-32,768 15 255.255.254.0 or /23 510 32,769-65,536 16 255.255.255.0 or /24 254 65,537-131,072 17 255.255.255.128 or /25 126 131,073-262,144 18 255.255.255.192 or /26 62 262,145-524,288 19 255.255.255.224 or /27 30 524,289-1,048,576 20 255.255.255.240 or /28 14 1,048,577-2,097,152 21 255.255.255.248 or /29 6 2,097,153-4,194,304 22 255.255.255.252 or /30 2 Table 17 shows the subnetting of a class B network ID. Table 17 Subnetting a class B network ID Required number of subnets Number of host bits Subnet Mask Number of hosts per subnet 1-2 1 255.255.128.0 or /17 32,766 3-4 2 255.255.192.0 or /18 16,382 5-8 3 255.255.224.0 or /19 8,190 9-16 4 255.255.240.0 or /20 4,094 17-32 5 255.255.248.0 or /21 2,046 33-64 6 255.255.252.0 or /22 1,022 65-128 7 255.255.254.0 or /23 510 129-256 8 255.255.255.0 or /24 254 257-512 9 255.255.255.128 or /25 126 513-1,024 10 255.255.255.192 or /26 62 1,025-2,048 11 255.255.255.224 or /27 30 2,049-4,096 12 255.255.255.240 or /28 14 4,097-8,192 13 255.255.255.248 or /29 6 8,193-16,384 14 255.255.255.252 or /30 2 Table 18 shows the subnetting of a class C network ID. Table 18 Subnetting a class C network ID Required number of subnets Number of host bits Subnet Mask Number of hosts per subnet 1-2 1 255.255.255.128 or /25 126 3-4 2 255.255.255.192 or /26 62 5-8 3 255.255.255.224 or /27 30 9-16 4 255.255.255.240 or /28 14 17-32 5 255.255.255.248 or /29 6 33-64 6 255.255.255.252 or /30 2 Step 2: Enumerating Subnetted Network IDs Based on the number of host bits you use for your subnetting, you must list the new subnetted network IDs. There are two main approaches: Binary—List all possible combinations of the host bits chosen for subnetting and convert each combination to dotted decimal notation. Decimal—Add a calculated increment value to each successive subnetted network ID and convert to dotted decimal notation. Either method produces the same result—the enumerated list of subnetted network IDs. Note There are a variety of documented shortcut techniques for subnetting. However, they only work under a specific set of constraints (for example, only up to 8 bits of a class-based network ID). The methods described below are designed to work for any subnetting situation (class-based, more than 8 bits, supernetting, variable length subnetting). Binary Subnetting Procedure 1. Based on n, the number of host bits chosen for subnetting, create a 3-column table with 2n entries. The first column is the subnet number (starting with 1), the second column is the binary representation of the subnetted network ID, and the third column is the dotted decimal representation of the subnetted network ID. For each binary representation, the bits of the network ID being subnetted are fixed to their appropriate values and the remaining host bits are set to all 0’s. The host bits chosen for subnetting will vary. 2. In the first table entry, set the subnet bits to all 0’s and convert to dotted decimal notation. The original network ID is subnetted with its new subnet mask. 3. In the next table entry, increase the value within the subnet bits. 4. Convert the binary result to dotted decimal notation. 5. Repeat steps 3 and 4 until the table is complete. As an example, a 3-bit subnet of the private network ID 192.168.0.0 is needed. The subnet mask for the new subnetted network IDs is 255.255.224.0 or /19. Based on n = 3, construct a table with 8 (= 23) entries. The entry for subnet 1 is the all 0’s subnet. Additional entries in the table are successive increments of the subnet bits as shown in Table 19. The host bits used for subnetting are underlined. Table 19 Binary subnetting technique for network ID 192.168.0.0 Subnet Binary Representation Subnetted Network ID 1 11000000.10101000.00000000. 192.168.0.0/19 00000000 2 11000000.10101000.00100000. 192.168.32.0/19 00000000 3 11000000.10101000.01000000. 192.168.64.0/19 00000000 4 11000000.10101000.01100000. 192.168.96.0/19 00000000 5 11000000.10101000.10000000. 192.168.128.0/19 00000000 6 11000000.10101000.10100000. 192.168.160.0/19 00000000 7 11000000.10101000.11000000. 192.168.192.0/19 00000000 8 11000000.10101000.11100000. 192.168.224.0/19 00000000 Decimal Subnetting Procedure 1. Based on n, the number of host bits chosen for subnetting, create a 3-column table with 2n entries. The first column is the subnet number (starting with 1), the second column is the decimal (Base 10 numbering system) representation of the 32-bit subnetted network ID, and the third column is the dotted decimal representation of the subnetted network ID. 2. Convert the network ID (w.x.y.z) being subnetted from dotted decimal notation to N, a decimal representation of the 32-bit network ID. N = w*16777216 + x*65536 + y*256 + z 3. Compute the increment value I based on h, the number of host bits remaining. I = 2h 4. In the first table entry, the decimal representation of the subnetted network ID is N and the subnetted network ID will be w.x.y.z with its new subnet mask. 5. In the next table entry, add I to the previous table entry’s decimal representation. 6. Convert the decimal representation of the subnetted network ID to dotted decimal notation (W.X.Y.Z) through the following formula (where s is the decimal representation of the subnetted network ID): W = INT(s/16777216) X = INT((s mod(16777216))/65536) Y = INT((s mod(65536))/256) Z = s mod(256) INT( ) denotes integer division, mod( ) denotes the modulus, the remainder upon division. 7. Repeat steps 5 and 6 until the table is complete. As an example, a 3-bit subnet of the private network ID 192.168.0.0 is needed. Based on n = 3, we construct a table with 8 entries. The entry for subnet 1 is the all 0’s subnet. N, the decimal representation of 192.168.0.0, is 3232235520, the result of 192*16777216 + 168*65536. Since there are 13 host bits remaining, the increment I is 213 = 8192. Additional entries in the table are successive increments of 8192 as shown in Table 20. Table 20 Decimal subnetting technique for network ID 192.168.0.0 Subnet Decimal Subnetted Representation Network ID 1 3232235520 192.168.0.0/19 2 3232243712 192.168.32.0/19 3 3232251904 192.168.64.0/19 4 3232260096 192.168.96.0/19 5 3232268288 192.168.128.0/19 6 3232276480 192.168.160.0/19 7 3232284672 192.168.192.0/19 8 3232292864 192.168.224.0/19 The All-Zeros and All-Ones Subnets RFC 950 originally forbade the use of the subnetted network IDs where the bits being used for subnetting are set to all 0’s (the all-zeros subnet) and all 1’s (the all-ones subnet). The all-zeros subnet caused problems for early routing protocols and the all-ones subnet conflicts with a special broadcast address called the all-subnets directed broadcast address. However, RFC 1812 now permits the use of the all-zeros and all-ones subnets in a Classless Interdomain Routing (CIDR)-compliant environment. CIDR-compliant environments use modern routing protocols which do not have a problem with the all-zeros subnet and the use of the all-subnets directed broadcast has been deprecated. Before you use the all-zeros and all-ones subnets, verify that they are supported by your hosts and routers. Windows NT supports the use of the all-zeros and all-ones subnets. Step 3: Enumerating IP Addresses for Each Subnetted Network ID Based on the enumeration of the subnetted network IDs, you must now list the valid IP addresses for new subnetted network IDs. To list each IP address individually would be too tedious. Instead, we will enumerate the IP addresses for each subnetted network ID by defining the range of IP addresses (the first and the last) for each subnetted network ID. There are two main approaches: Binary—Write down the first and last IP address for each subnetted network ID and convert to dotted decimal notation. Decimal—Add values incrementally, corresponding to the first and last IP addresses for each subnetted network ID and convert to dotted decimal notation. Either method produces the same result—the range of IP addresses for each subnetted network ID. Binary Procedure 1. Based on n, the number of host bits chosen for subnetting, create a 3-column table with 2n entries. Alternately, add two columns to the previous table used for enumerating the subnetted network IDs. The first column is the subnet number (starting with 1), the second column is the binary representation of the first and last IP address for the subnetted network ID, and the third column is the dotted decimal representation of the first and last IP address of the subnetted network ID. 2. For each binary representation, the first IP address is the address where all the host bits are set to 0 except for the last host bit. The last IP address is the address where all the host bits are set to 1 except for the last host bit. 3. Convert the binary representation to dotted decimal notation. 4. Repeat steps 2 and 3 until the table is complete. As an example, the range of IP addresses for the 3 bit subnetting of 192.168.0.0 is shown in Table 21. The bits used for subnetting are underlined. Table 21 Binary enumeration of IP addresses Subnet Binary Representation Range of IP Addresses 1 11000000.10101000.00000000. 00000001-11000000.10101000.00011111. 11111110 192.168.0.1 - 192.168.31.254 2 11000000.10101000.00100000. 192.168.32.1 - 192.168.63.254 00000001-11000000.10101000.00111111. 11111110 3 11000000.10101000.01000000. 00000001 - 11000000.10101000.01011111. 11111110 192.168.64.1 - 192.168.95.254 4 11000000.10101000.01100000. 00000001 -11000000.10101000.01111111. 11111110 192.168.96.1 - 192.168.127.254 5 11000000.10101000.10000000. 00000001 - 11000000.10101000.10011111. 11111110 192.168.128.1 - 192.168.159.254 6 11000000.10101000.10100000. 00000001 - 11000000.10101000.10111111. 11111110 192.168.160.1 - 192.168.191.254 7 11000000.10101000.11000000. 00000001 -11000000.10101000.11011111. 11111110 192.168.192.1 - 192.168.223.254 8 11000000.10101000.11100000. 00000001 - 11000000.10101000.11111111. 11111110 192.168.224.1 - 192.168.255.254 Decimal Procedure 1. Based on n, the number of host bits chosen for subnetting, create a 3-column table with 2n entries. Alternately, add two columns to the previous table used for enumerating the subnetted network IDs. The first column is the subnet number (starting with 1), the second column is the decimal representation of the first and last IP address for the subnetted network ID, and the third column is the dotted decimal representation of the first and last IP address of the subnetted network ID. 2. Compute the increment value J based on h, the number of host bits remaining. J = 2h - 2 3. For each decimal representation, the first IP address is N + 1 where N is the decimal representation of the subnetted network ID. The last IP address is N + J. 4. Convert the decimal representation of the first and last IP addresses to dotted decimal notation (W.X.Y.Z) through the following formula (where s is the decimal representation of the first or last IP address): W = INT(s/16777216) X = INT((s mod(16777216))/65536) Y = INT((s mod(65536))/256) Z = s mod(256) INT( ) denotes integer division, mod( ) denotes the modulus, the remainder upon division. 5. Repeat steps 3 and 4 until the table is complete. As an example, the range of IP addresses for the 3 bit subnetting of 192.168.0.0 is shown in Table 22. The increment J is 213 - 2 = 8190. Table 22 Decimal enumeration of IP addresses Subnet Decimal Representation Range of IP Addresses 1 3232235521 – 3232243710 192.168.0.1 192.168.31.254 2 3232243713 – 3232251902 192.168.32.1 192.168.63.254 3 3232251905 – 3232260094 192.168.64.1 192.168.95.254 4 3232260097 – 3232268286 192.168.96.1 192.168.127.254 5 3232268289 – 3232276478 192.168.128.1 192.168.159.254 6 3232276481 – 3232284670 192.168.160.1 192.168.191.254 7 3232284673 – 3232292862 192.168.192.1 192.168.223.254 8 3232292865 – 3232301054 192.168.224.1 192.168.255.254 RFC’s that relate to this document are: RFC 1918- Address Allocation for Private Internets RFC 1219- On the Assignment of Subnet Numbers RFC 950- Internet standard subnetting procedure RFC 940- Toward an Internet standard scheme for subnetting RFC 932- Sub network addressing scheme RFC 917- Internet subnets Sources: 1. IP Address Subnetting Tutorial - http://www.ralphb.net/IPSubnet/ (used with permission from the author) 2. Introduction to TCP/IP in Windows NT® 4.0 – Microsoft Tech Net Online – http://www.eu.microsoft.com/technet/deploy/tcpintro/tcpintro1.htm 3. Illustrated TCP/IP – A graphic Guide to the Protocol Suite – Matthew Naugle