Sunteți pe pagina 1din 20

## IP Subnetting without Tables, Tools, or Tribulations

Abstract

Introduction
Every networking student should have a solid understanding of TCP/IP subnetting (Loshin, 1997). Subnettings importance in modern networking is reflected by its many and varied uses. It can enhance network performance by splitting up collision and broadcast domains in a routed network (Odom, 2000). Large networks can be organized into separate subnets representing departmental, geographical, functional, or other divisions (Feit, 1997). Since hosts on different subnets can only access each other through routers, which can be configured to apply security restrictions, subnetting can also serve as a tool for implementing security policies (Bulette, 1998). Dividing a large network into subnets and delegating administrative responsibility for each subnet can

make administration of a large network easier. Routers can require that a WAN link connecting two networks must itself form a separate subnet (Bulette, 1998). Troubleshooting, diagnosing, and fixing problems in a TCP/IP internetwork typically require thorough familiarity with subnetting. Network design requires both the ability to understand and carry out subnetting. A major stumbling block to successful subnetting is often a lack of understanding of the underlying binary math. In fact, the principles of subnetting are difficult to grasp without mastery of binary arithmetic, logic, and binary/decimal conversions. On the other hand, it is not necessary to be able to think in binary in order to plan, design, and implement simple subnetting. The methodology discussed below allows anyone with the following capabilities to successfully carry out all the subnetting essentials: Know the decimal values of the powers of 2 from 0 to 8 as presented in Table 1 below (e.g., 24 = 16) Know how to add and subtract the decimal values of the powers of 2 in the following table (e.g., 27 25 = 128 32 = 96). If this decimal arithmetic can be done mentally, then subnetting itself can be accomplished mentally.
Table 1

x 0 1 2 3 4 5 6 7 8

2x 20 21 22 23 24 25 26 27 28

## 2x in Decimal 1 2 4 8 16 32 64 128 256

It is helpful to memorize Table 1 before proceeding. The discussion below presents a simple, step-by-step methodology for determining the number of subnets, the maximum number of hosts per subnet, the subnet mask, the network ids, and the valid IP addresses for each subnet. In short, the method covers all the major steps in the subnetting process. First, however, we present a rapid review of subnetting concepts.

## Simple Subnetting Concepts

Observe how the subnet mask consists of 2 octets of uninterrupted 1s (indicating the network ID part of the corresponding IP address), and 2 octets of uninterrupted 0s (indicating the host ID part of the corresponding IP address). Using the subnet mask, we can readily separate the IP address into its two parts: Network ID: Host ID: 10010010 10101000 00000000 00000111

Although it is easiest to understand the role of the subnet mask while working in binary, binary notation is in general too cumbersome for humans. Hence IP addresses and subnet masks are usually written in dotted-decimal notation (Cunningham, 1998), in which each octet is converted to its equivalent decimal number, and the four decimal numbers are separated with dots (i.e., periods). The IP address and subnet mask from the example above would appear in dotted-decimal as: IP Address: Subnet Mask: Network ID: Host ID: 146.168.0.7 255.255.0.0 146.168 0.7

Note that the network ID is usually seen written as 4 octets (which can be created by appending any necessary 0 octets to the end of the network ID as delimited by the subnet mask), and that leading 0 octets are usually dropped from the host ID, as in: Network ID: Host ID: 146.168.0.0 7

It is also important to remember that the octet 00000000 in binary becomes 0 in dotteddecimal notation, and the octet 11111111 in binary becomes 255 in dotted-decimal notation.

Table 2

## Host ID (3 bits Shorter) 00000 00000111

Notice that when we borrow bits from the host ID for the subnet ID, the original subnet mask is no longer accurate. As shown in Table 3 below, the original subnet mask has binary 0s matching up with the bits in the new Subnet ID. Since binary 0s in the subnet

mask indicate the Host ID field, the newly created Subnet ID field still appears to belong to the original Host ID field.
Table 3

## Network ID IP Address: Original Subnet Mask: 10010010 10101000 11111111 11111111

3 Bits Borrowed for Subnet ID 000 000 (0 bits here make subnet ID appear to be part of host ID)

## Host ID (3 Bits Shorter) 00000 00000111 00000 00000000

To eliminate confusion over what bits still belong to the original Host ID field and what bits belong to the new Subnet ID field, we must extend the binary 1s in the original Subnet Mask with enough 1 bits to match the size of the newly created Subnet ID field (and correspondingly reduce the number of 0s which originally identified the Host ID in the Subnet Mask by the same amount). The new subnet mask is called a custom subnet mask. After this adjustment, the total number of bits in the custom subnet mask will still be 32, but the number of binary 1s will have increased by the size of the subnet ID, and the number of binary 0s will have decreased accordingly. This operation is illustrated in Table 4 below:
Table 4

Bits Borrowed for Subnet ID 000 000 111 (1 bits here indicate field belongs to network ID)

## Shortened Host ID 00000 00000111 00000 00000000 00000 00000000

A critical issue when borrowing bits from the host ID to create the subnet ID is to accurately determine the following information: 1. How many subnets are needed

2. How many bits must be borrowed from the host ID field for the new subnet ID field to accommodate the required number of subnets 3. What is the largest number of hosts that will ever be on a given subnet 4. How many bits must be retained in the host ID field to accommodate the maximum number of hosts needed These considerations mandate that careful planning should be carried out before the subnetting process is begun. It is obviously prudent to plan for future as well as for current needs. Once pre-planning is complete, the actual subnetting process involves the following steps: 1. Determine how many subnets are needed 2. Determine the maximum number of hosts that will be on any given subnet 3. Determine how many bits to borrow from the host ID field for the subnet ID field 4. Determine how many bits must remain in the host ID field (and therefore cannot be borrowed for the subnet ID) 5. Determine how many bits are in the original network ID and host ID fields 6. Check to ensure that the number of bits to be borrowed from the host ID does not exceed the number of bits to be retained for the host ID (i.e., check that the subnetting problem is solvable) 7. Set an optimal length for the subnet ID field, including room for future growth 8. Create a modified (custom) subnet mask for the network 9. Determine the valid subnet IDs for the network 10. Determine the valid ranges of IP addresses for each subnet on the network

## A Simple Subnetting Procedure

The following step-by-step procedure can be used to subnet a TCP/IP network. It is assumed that the reader is already familiar with IP addressing, subnet masks, the separation of an IP address into a network ID and a host ID, and basic subnet concepts as discussed above. 1. Determine the required number of subnets and call it S (big S) When estimating the required number of subnets, it is critical to consider not only your current subnet needs, but also to plan for future growth. If there is historical information available, use it as a guide to predict how many subnets will be needed next year, two years from now, three, etc. Remember to include both current and anticipated subnetworks in your total. If your WAN links are handled as separate subnets, then count each WAN link too.

Remember to leave plenty of room for growth. Nothing is more embarrassing (and costly) than to have to redo a network design because of poor planning. Work closely with users and management to uncover upcoming changes that might affect future growth in ways not shown by historical data (such as an anticipated merger or acquisition, introduction of a new product line, etc.). In the steps that follow, assume that S = 5. 2. Determine the maximum number of hosts per subnet and call it H (big H) In TCP/IP terminology, a host is any device that attaches to the network via a network interface. The count should reflect the largest number of network interfaces that will ever be on a given subnet. Remember to include not only network interfaces for computers, but also any network interfaces in printers, routers, or any other networked devices. Some computers (called multihomed hosts) may have more than one NIC, in which case each NIC is counted separately. Other devices (such as bridges or routers) will also have more than one network interface. It is not necessary to tabulate the number of network interfaces for every subnet. The purpose of step 2 is to count the maximum number of interfaces that will ever be needed for the largest subnet. As with step 1, remember to plan for growth. Use historical data if available, but also look for upcoming changes that could lead to significant growth not reflected in the historical data. Again, nothing is more embarrassing than to have to redo a network design because of poor planning. In the steps that follow, assume that H = 50. 3. Find the smallest integer s (little s) such that 2s 2 S This step calculates the number of bits s (little s) needed in the IP address for the subnet IDs. Little s is the smallest integer (whole number) such that 2s 2 is at least S (big S, the required number of subnets). As the following table illustrates, with s bits for the subnet ID, we can address 2s different subnets. However, a subnet ID is not allowed to be either all 0s (which according to TCP/IP standards always means the current subnet and therefore cannot be used as a subnet ID for an actual subnet), or all 1s (which according to TCP/IP standards is always a broadcast address and therefore cannot be used as a subnet ID for an actual subnet) (Heywood, 1997). Hence with s bits for the subnet ID, the effective number of addressable subnets is 2s 2, as shown in Table 5 below:
Table 5

## 2s 2 = number of addressable subnets 21 2 = 2 2 = 0

Valid subnet addresses (all 0s or all 1s are invalid and are shown crossed out) 0 1

## 2s 2 = number of addressable subnets 22 2 = 4 2 = 2

Valid subnet addresses (all 0s or all 1s are invalid and are shown crossed out) 00 01 10 11 000 001 010 011 100 101 110 111

23 2 = 8 2 = 6

Calculating s is easier if we rewrite the inequality 2s 2 S as 2s S + 2. If you are comfortable with the entries in Table 1, you can quickly find the smallest s such that 2s S + 2 as follows: 1. Find the smallest integer value in the right-hand column of Table 1 that is equal to or greater than S + 2 (big S plus 2) 2. Using Table 1, find the corresponding value of s (little s) from the left-hand column 3. This is the number of bits needed for the subnet IDs in your IP addresses For example, if S = 5, the smallest integer value from the right-hand column of Table 1 that is 5 + 2 = 7 is 8. The corresponding value of s (from the left-hand column of Table 1) is 3. If on the other hand S = 7, the smallest integer value from the righthand column of Table 1 that is greater than or equal to 7 + 2 = 9 is 16. Hence the value of s is 4. 4. Find the smallest integer h (little h) such that 2h 2 H This step calculates the number of bits h (little h) needed in the IP address for the host IDs, and is similar to step 3. In fact, the TCP/IP standards state that a host ID cannot be all 0s, since a 0 host ID always refers to the current host (and so can never be used as the address for a particular host), or all 1s, since all 1s indicates a broadcast address (and so can never be used for the address of a particular host) (Heywood, 1997). Hence the formula for finding the number of bits needed for the host IDs is exactly parallel to that used to calculate the number of bits needed for the subnet IDs. Similar to step 3, we look for the smallest integer h such that 2h 2 H.

Table 6

Starting Octet for Network ID (in decimal) 1 126 128 191 192 - 223

## Host ID Bits in Standard Subnet Mask (T) 24 16 8

For example, assume the official network ID is 146.168.0.0. According to Table 6, this is a Class B address (since 146 is between 128 191, inclusive) and the number of host ID bits in the standard subnet mask is T = 16.

9. Determine the custom subnet mask for your network Start with the default (standard) subnet mask for your address class as shown in Table 7 below: We will extend the network ID portion of the default subnet mask by replacing its leftmost zero octet (shown bolded in the table) with a new value.
Table 7

## Leftmost Zero Octet 255.0.0.0 255.255.0.0 255.255.255.0

Table 8

Original Network ID (Not a valid subnetwork address) Network ID for Subnet 1 Network ID for Subnet 2 Network ID for Subnet 3 Network ID for Subnet 4 Network ID for Subnet 5 Network ID for Subnet 6 Network ID for Subnet 7 Network ID for Subnet 8 Network ID for Subnet 9

146.168.0.0 146.168.16.0 146.168.32.0 146.168.48.0 146.168.64.0 146.168.80.0 146.168.96.0 146.168.112.0 146.168.128.0 146.168.144.0

Network ID for Subnet 10 Network ID for Subnet 11 Network ID for Subnet 12 Network ID for Subnet 13 Network ID for Subnet 14 Custom Subnet Mask value (Not a valid subnetwork address)

## 146.168.160.0 146.168.176.0 146.168.192.0 146.168.208.0 146.168.224.0 146.168.240.0

Table 9

IP Addresses for Subnet 1 (Network Address 146.168.16.0) 146.168.16.1 to 146.168.16.255 146.168.17.0 to 146.168.17.255 146.168.18.0 to 146.168.18.255 146.168.19.0 to 146.168.19.255 146.168.20.0 to 146.168.20.255 146.168.21.0 to 146.168.21.255 146.168.30.0 to 146.168.30.255 146.168.31.0 to 146.168.31.254

Do not be confused by the fact that some valid IP addresses end in 0 or 255. This happens normally when subnetting, and the rules about not having network, subnetwork, or host IDs equal to all 0s or all 1s are not necessarily violated just because an octet is equal to all 0s or all 1s. The rules place restrictions on the values of network, subnetwork, and host IDs, not on the values of octets. To understand this, consider the IP address 146.168.17.0 from Table 9 and analyze it according to the custom subnet mask for our example network, 255.255.240.0.
Table 10

## Shortened Host ID Part of IP Address

10010010 10101000

0001 00000000

11111111 11111111

1111

0000 00000000

Notice that although the rightmost octet of the Host ID consists of all zero bits, the full Host ID is a total of 12 bits and is not all 0s (the sole one bit is shown bolded). For a second example, consider the IP address 146.168.21.255 from Table 9. Although the last octet is 255 (eight 1s in binary), the following analysis shows that the full host ID is not all 1 bits (the two zero bits in the host ID are shown bolded):
Table 11

## Shortened Host ID Part of IP Address

10010010 10101000

0101 11111111

11111111 11111111

1111

0000 00000000

A Class C Example
Suppose an ISP assigns a Class C network address of 193.200.35.0 to an organization (call it Widgets, Inc., or just Winc). We will work through the 11 steps presented above in order to subnet this Class C network. 1. After meetings with relevant Winc personnel and study of historical growth trends, it is determined that Winc currently needs 2 subnets, with practically no likelihood of adding other subnets in the future. Therefore, we set S (big S) at 2. 2. After meetings with relevant Winc personnel and study of historical growth trends, it is determined that Winc currently needs at most 25 hosts on any subnet. In the future, subnet size is not expected to pass 30 hosts. Hence, we set H (big H) at 30. 3. To find the smallest integer s such that 2s 2 S, we first rewrite the inequality as 2s S + 2. Since S = 2, this becomes 2s 2 + 2 or 2s 4. Reference to Table 1 shows that the smallest such integer s is 2. 4. To find the smallest integer h such that 2h 2 H, we first rewrite the inequality as 2h H + 2. Since H = 30, this becomes 2h 30 + 2 or 2h 32. Reference to Table 1 shows that the smallest such integer h is 5. 5. Wincs assigned network address is 193.200.35.0, which begins with 193. Hence Winc has a Class C network address for which T (big T) is 8 (see Table 6). 6. Now we can calculate s + h = 2 + 5 = 7, which does not exceed the value of big T (T = 8). Hence we have a solvable subnetting problem and can proceed to step 7. 7. Since s + h = 2 + 5 = 7 which is not equal to 8 (the value of T), we must carry out step 8 8. Since s + h = 2 + 5 = 7 is less than T = 8, we have r = T s h = 8 2 5 = 1 bit left over to increase the value of either s or h. Since in general Winc is more likely to run short of subnets rather than hosts on a subnet, we allocate the extra bit to s, incrementing s so that now s = 3. Note that now s + h = 3 + 5 = 8 = T. 9. To determine the custom subnet mask for Wincs network, we start with the standard (default) subnet mask for Class C (Wincs network class), which according to Table 7 is 255.255.255.0. We will replace the leftmost zero octet in the original subnet mask (i.e., the 0 in 255.255.255.0), with a new octet that will extend the subnetwork ID into the host ID. Calculate the new value for the original leftmost zero octet as 256 28 s, which is 256 28 3 or 256 25 or 256 32 or 224. Hence the custom subnet mask for Wincs network is 255.255.255.224. 10. Now we determine the valid network IDs for the new subnets by identifying the leftmost 0 octet in the original network ID assigned by the ISP. Since this network ID is 193.200.35.0, the leftmost 0 octet (the only 0 octet) is also the rightmost 0

octet (shown bolded). We now add 28 s = 28 3 = 25 = 32 to this 0 octet to get the new value for the octet in the first subnet ID: 32 + 0 = 32. Thus the network ID for the first subnet is 193.200.35.32 We continue adding 28 s to this octet until we either reach the value of the custom subnet mask (255.255.255.224) or until we have network addresses for 2s 2 subnets (these two conditions are equivalent and so will occur at the same time). In our case, 2s 2 = 23 2 = 8 2 = 6 subnets, so we continue adding 28 s five more times (for a total of six times) as shown below:
Table 12

Original Network ID (not a valid subnet address since subnet ID is all 0s) Address for subnet 1 Address for subnet 2 Address for subnet 3 Address for subnet 4 Address for subnet 5 Address for subnet 6 Custom Subnet Mask (not a valid subnet address since subnet ID is all 1s)