A PRACTICAL APPROACH TO ASSIGNING SUBNET
MASKS
John P. Abraham
Department of Computer Science
Email jabraham@utpa.edu
1. INTRODUCTION
Explosive growth of the Internet has brought about two major problems: exhaustion of IP addresses and routing table growth [Fuller et al. 1993]. Exhaustion IP addresses came about as a result of random assignment of IP addresses by NIC and under utilization of already assigned IP addresses [Cisco 1998]. Uncontrolled growth of routing table is a result of random assignment of network numbers rather than hierarchical assignment based on geography. According to Cisco Systems, Inc. [1998], only about 5000 routes needed to be tracked in 1990. This number has grown to 35000 routes by 1995. Several patches have been introduced to work around these problems. Patches that are in use today are subnetmasking [Mogul 1984, Baker 1995], variable length subnet masking [Braden and Postel 1987, Pummill and Manning 1995], Address Allocation for Private Internets [Rekhter et al. 1996], and Classless Inter-Domain Routing [Fuller et al. 1993, Rekhter et al, 1996]. A more permanent solution, IP version 6 using a 128 bit address, is in the testing phase now [Hinden and Deering 1995].
Computers and other devices connected to the Internet are identified by
unique IP addresses, and these addresses are included in the source address and
destination address fields of all IP packets. An IP address provides sufficient
information to route a packet from the source to the destination network and
deliver it to the appropriate node. The IP address uses a 32 bit binary number
allowing for a total of 4,294,967,295 possible nodes to be divided among the
anticipated number of local networks. For example, if there were only four
networks, each could have over a billion nodes. No one can accurately predict
the number of networks that will be in existence even a few years from now.
When the original ARPANET was designed in 1969, only four sites were
internetworked: First node at
An IP address is 32 bits long and for ease of human understanding, it is written as four octets connected by dots, each octet ranging from 0 to 11111111 binary or 0 to 255 decimal. The IP address has two distinct parts: the network address (prefix) and the host address (suffix). The prefix portion of the address identifies the physical network to which a host is attached, while the suffix portion identifies an individual computer on that network [Comer 1999]. Number of bits used for the network portion and host portion depends upon the class of the IP address. All zeros and all ones have special meanings and cannot be used for normal communication [Tanenbaum, 1996]. Therefore, the number of networks and hosts each class can have is total possible binary alternatives minus two (2n-bits -2).
Given a network address and the number of subnets needed or maximum number of nodes per subnet, we can calculate subnet masks for each of the subnet. For illustrative purposes, we will use the IP address of 201.222.5.0 later in this paper. And we will assume that the subnets needed would be five with twenty-five computers in each subnet. To do the calculation we must have a reasonable understanding of the various classes of IP addresses and the purpose of the subnet masking.
2. CLASSES OF IP ADDRESSES
There are five classes of IP addresses , named A through E. Class D is used for multicast addressing and class E is reserved for future use [Tanenbaum 1996]. Class A addresses begin with 1 and end with 127 in the first octet portion of the IP address. Defined another way, the most significant bit of the first octet of the IP address is always zero for all class A addresses. Class B addresses begin with 128 and end with 191; the two most significant bits of the first octet is always 10. Class C addresses begin with 192 and end with 223; the three most significant bits of the first octet is always 110. Classes D and E begin with 1110 and 1111 respectively. Class A uses 8 bits for network address and 24 bits for host address; class B uses 16 bits for network address and 16 bits of host address; and class C uses 24 bits of network address and 8 bits for host address. Figure 1 summarizes the various classes and network and host portions of the total address space.
BITS 8 16 24 31
0 |
Network address |
Host address |
Class A
10 |
Network address |
Host address |
Class B
110 |
Network address |
Host address |
Class C
1110 |
Multicast address |
Class D
1111 |
Reserved for future use |
Class
E
Figure 1
Classes of IP addresses and number of bits used for network and host address portions.
Out of the 8 bits allocated for the network address portion of the Class A IP address, the first bit should remain 0, and the remaining 7 bits can be used for assigning networks yielding a maximum of 127 Class A networks. Each network of Class A can have a maximum of 16,777,216 minus 2 hosts. All zeros and all ones have special meanings and may not be used for host addressing. All zeros in the host portion has the special meaning, "this computer or this network", and all ones are used for broadcasting a message to every host on a network [Mogul and Postel 1985]. Figure 2 reveals the number of networks and hosts each of the three Classes of IP address can have. Not all networks are used; for example, networks 0 and 127 of Class A are reserved giving a total of 126 usable Class A networks.
Class |
Available bits in network portion |
Number of networks |
Available bits in host portion |
Number of hosts |
A |
7 |
128 |
24 |
16,777,214 |
B |
14 |
16,384 |
16 |
65534 |
C |
21 |
2,097,152 |
8 |
254 |
Figure 2
Number of Networks and Hosts for each class of IP address
The network addresses are distributed by the Internet Assigned Numbers Authority (IANA) and the American Registry for Internet Numbers (ARIN) [Marine et al 1994]. One Class A network with almost 17 million hosts would be extremely unmanageable. Even the 254 hosts available in a Class C would be difficult to manage. Furthermore, there are restrictions on the number of nodes a particular cable can have. A network can be divided into smaller more manageable networks using subnet masks. Some other reasons for subnetting are: differing topologies, limits of technologies, network congestion and point-to-point links [Mogul and Postel 1985].
3. SUBNET MASKS
Subnet masks determine if a destination address can be found within the local physical network or outside the local physical network. Routers are specialized computers that find paths to destination addresses. Routers connect to multiple physical networks and are called multi-homed hosts. When a router receives a packet from outside for one of the physical networks connected to it, it matches the IP address with the physical address of the host and sends the packet to that host. Each host has a physical address on its Ethernet card. When the router receives a packet from one of the hosts connected to its physical network, the router must determine if the destination can be found on one of its physical networks or it must send it out. Subnet mask provides necessary information to make this decision. Mogul and Postel [1985] provide a general code for making routing decision:
IF bitwise_and(dg.ip_dest, my_ip_mask) = bitwise_and(my_ip_addr, my_ip_mask)
THEN
send_dg_locally(dg, dg.ip_dest)
ELSE
send_dg_locally(dg, gateway_to(bitwise_and(dg.ip_dest, my_ip_mask)))
Once a network address is assigned to an organization by IANA, that organization must decide how many of the host portion of the bits would be used for subnet masking. The remaining bits can be used for host addressing. For example, if the Class B IP address 129.113.0.0 is assigned to an organization, it has 16 bits of the host portion to work with. These 32 bits can be divided into two 8 bit portions, the first half for subnet addressing and the second for host addressing. Based on this decision, that organization can have 254 different networks each having 254 hosts. For this example, the subnet mask would be all binary ones for the first three octets and 0 for the last octet or decimal 255.255.255.0.
Continuing with this example, let us suppose that host 129.113.200.111 sends a packet to destination 129.113.200.120. Does the destination host reside on the local physical network or outside? This determination is
made by ANDing the destination address with the subnet mask. Keep in mind that the source subnet address is 129.113.200.0
10000001.01110001.11001000.01111000 destination address
AND 11111111.11111111.11111111.00000000 subnet mask
10000001.01110001.11001000.00000000 destination on the same subnet
129.113.200.0 – same as the source subnet address.
This destination address is on the same physical subnet as the source address. Now let us change the destination address to 129.113.191.121 and perform the same calculation:
10000001.01110001.10111111.01101111 destination address
AND 11111111.11111111.11111111.00000000 subnet mask
10000001.01110001.10111111.00000000 destination not on the same subnet
129.113.191.0 – not same as the source subnet address.
In order to send packets between two physical networks, a router, a bridge, or a switch must be used, the most common one being the router. A router keeps a routing table to look up which direction the packet must be sent or to determine if the packet belongs to self. The routing table is constantly updated based on if the target is reachable or unreachable, shortest path to the destination, traffic congestion, etc. The subnets are only visible within a network and not to the outside world. In the above example, ANDing the subnet mask with destination address eliminates the host portion of the address. The remaining portion, the network address portion, can be looked up in the routing table. A router may have several cable segments connected to it (multi-homed), each having its own network address and subnet mask. Based on the result of the above described ANDing, the router makes the decision whether the destination is on the same physical cable as the source, or on another segment connected to it, or outside its immediate reach. If the destination is outside, based on the routing table, it must send the packet to the appropriate segment to which it is connected. When a router is going to forward a packet, it must determine whether it can send it directly to its destination, or whether it needs to pass it through another router [Braden and Postel 1987]. If the latter, it needs to determine which router to use. If the next hop is not known, a request may be sent to the NHRP server for next hop resolution protocol [Cansever 1998]. Several other routing algorithms are described by Comer [1999] and Tanenbaum [1996].
4. A CASE STUDY
In this section we will examine a step by step process of subdividing a Class C network into smaller subnets and calculating subnet masks for each of the subnets. Let us assume that Johnson & Co. is a small business firm with five departments each having twenty-five employees. Assuming each employee has a computer and each department has a printer, Johnson & Co. will need 125 nodes for computers and five for printers. It is also assumed that one department requires token ring, another requires fiber, and the rest of the departments requires 10 or 100 Mbs Ethernet. The network number assigned to Johnson & Co. is 201.222.5.0. The network administrator decides to create smaller networks, one for each department. This decision is based on different topology requirements for different departments, simplifying cabling, and easy administration of the network.
The first octet of the network address is decimal 201 or binary 11001001. Looking at the first three bits it is clear that this is a Class C address (refer to Figure 1). Out of the 32 bits, 24 bits are used for the network portion and 8 bits are used for the host portion. The network portion, the first 24 bits, cannot be altered. Therefore, Johnson & Co. has discretion only on the last eight bits. A portion of these eight bits can be used for subnet masks and the remainder for host addresses. Figure 3 illustrates how many subnets or hosts can be obtained from given a number of bits. The number of subnets or hosts is derived by subtracting two from the maximum possible binary alternatives for the given number of bits. As mentioned earlier, all ones and all zeros have special meanings. As an example, 3 bits allocated to the subnet portion can yield 8 subnets, two of which cannot be used leaving 6 networks.
Number of bits |
Number of subnets or hosts |
2 |
2 |
3 |
6 |
4 |
14 |
5 |
30 |
6 |
62 |
Figure 3
Number of bits and useable IP addresses
Subnet addresses in binary |
Subnet addresses in decimal |
201.225.5.00100000 |
201.225.5.32 |
201.225.5.01000000 |
201.225.5.64 |
201.225.5.01100000 |
201.225.5.96 |
201.225.5.10000000 |
201.225.5.128 |
201.225.5.10100000 |
201.225.5.160 |
201.225.5.11000000 |
201.225.5.192 |
Figure 4
Addresses of subnets using 3 bits
Only last octet is shown in binary
The subnet mask will be 201.225.5.11100000 (201.225.5.224)
Host addresses in binary For subnet 201.225.5.64 |
Host addresses in decimal |
201.225.5.01000001 |
201.225.5.65 |
201.225.5.01000010 |
201.225.5.66 |
201.225.5.01000011 |
201.225.5.67 |
201.225.5.01000100 |
201.225.5.68 |
201.225.5.01000101 |
201.225.5.69 |
201.225.5.01000110 |
201.225.5.70 |
201.225.5.01000111 |
201.225.5.71 |
… |
… |
201.225.5.01011110 |
201.225.5.94 |
Figure 5
Host addresses for subnet 201.225.5.64
Only last octet is shown in binary
A careful examination of Figure 3 reveals that a good allocation would be 3 bits for subnet masks and 5 bits for host addresses. Three bits for subnet masks will yield a total of 6 usable subnets, and five bits for host addresses will yield a total of 30 IP addresses. This bit allocation is the best fit given the requirements. It allows for future growth of one more department and four additional hosts per each subnet (after allowing for the network printer). Masks for each subnet are given in Figure-4. Subnet masks may be obtained by manipulating the number of bits allocated for that purpose. All zeros may not be used, so the first subnet mask can be obtained by setting the least significant bit of the three bits set aside for the subnet portion to 1. The mask for the first subnet therefore is 201.225.5.32.
The host IP address for each of the computer can be calculated by manipulating the five bits allocated for that purpose. Again, all zeros and all ones may not be used. The first host address in the first subnet is obtained by setting the lease significant bit of the host portion to 1, giving an address of 201.225.5.65. Each additional host address in the same subnet can be obtained by adding a binary one to the previous number until all bits are set to ones. The range of usable IP addresses for the first subnet are 201.225.5.65 to 201.225.5.94. All host addresses for the subnet 201.225.5.64 are given in Figure 5.
Resolving to which subnet an IP belongs is handled by the routers. For instance if a packet was destined to 201.225.5.69, this IP will be ANDed with 255.255.255.224. Just using the last octet in binary in this example, 01000101 will be ANDed with 11100000, yielding 01000000 or decimal 64 as the subnet. Examining Tables 4 and 5, we find it to be correct.
Subnet masks do waste some IP addresses. In the above example, if the network was not subnetted 254 host addresses could have been used. After subnetting the total useable host addresses have been reduced to 180, a twenty-nine percent loss. To regain some of this loss, many newer routers can be instructed to use all zeros in the subnet masks.
5. SUMMARY
Explosive growth of the Internet has brought about two major problems, exhaustion of IP addresses and routing table growth. These problems arose from poor planning of IP address distribution. Several patches have been introduced to ameliorate these problems. One such solution involves assignment of subnet masks in addition to IP address to each host. Assignment of subnet masks allows a large network to be broken down to more manageable smaller sub-networks. Another advantage to this solution is that different network topologies can be assigned different subnet numbers instead of obtaining a new network number. This paper explored a systematic way of dividing a Class C network into smaller more manageable sub-networks. A detailed explanation was given for calculating subnet mask for each of the subnets.
REFEREENCES
Baker, F., 1995, "Requirements for IP Version 4 Routers", RFC-1812.
Braden, R., and Postel, J., 1987, "Requirements for Internet Gateways", RFC-1009.
Cansever, D., 1998, "NHRP Protocol Applicability Statement", RFC-2333.
Cisco Systems, Inc., 1998, Advanced Cisco Router Configuration Guide,
Corporate Headquarters,
Comer, D. E., 1999, Computer Networks and Internets,
2nd Ed., Prentice Hall,
Fuller, V., Li, T., Yu, J., and Varadhan, K., 1993, "Classless Inter-Domain Routing (CIDR): an Address Assignment and Aggregation Strategy", RFC-1519.
Gromove, G. R., 1995, "History of Internet and WWW: The Roads and Cross Roads of Internet History", http://www.internetvalley.com/intval.html.
Hinden, R., and Deering, S., 1995, "IP Version 6 Addressing Architecture", RFC-1884.
Marine, A., Reynolds, J., and Malkin G., 1994, "FYI on Questions and Answers: Answers to Commonly asked New Internet User Questions", RFC-1594.
Mogul, J., 1984, "Internet Subnets", RFC-917.
Mogul, J., and Postel, J., 1985, "Internet Standard Subnetting Procedure", RFC-950.
Pummill, T., and Manning, B., 1995, "Variable Length Subnet Table for Ipv4", RFC-1878.
Rekhter, Y., Moskowitz, B., Karrenberg, D., de Groot, G. J., and Lear, E., 1996, "Address Allocation for Private Internets", RFC-1518.
Tanenbaum, A. S., 1996, Computer Networks, 3rd
Ed., Prentice Hall,