Subnets in TCP/IP
The address class system described in Hour 4, "The Internet Layer," enables all hosts to identify the network ID in an IP address and send a datagram to the correct network. However, identifying a network segment by its Class A, B, or C network ID presents some limitations. The principal limitation of the address class system is that it doesn't provide any logical subdivision of the address space beneath the network level.
Figure 5.1 shows a Class A network. As described in Hour 4, datagrams arrive efficiently at the gateway and pass into the 188.8.131.52 address space. However, the picture gets more complicated when you consider how to deliver the datagram once it passes into the 184.108.40.206 address space. A Class A network has room for over 16 million host IDs. This network could include millions of hosts, way more than would be possible on a single subnet.
To provide for more efficient delivery on a large network, the address space can be subdivided into smaller network segments (see Figure 5.2). Segmenting into separate physical networks increases the overall capacity of the network and therefore enables the network to use a greater portion of the address space. In this common scenario, the routers that separate the segments within the address space need some indication of where to deliver the data. They can't use the network ID because every datagram sent to the network has the same network ID (220.127.116.11). Though it might be possible to organize the address space by host ID, such a solution would be very cumbersome, inflexible, and totally impractical on a network with 16 million hosts. The only practical solution is to create some subdivision of the address space beneath the network ID so that the hosts and routers can tell from the IP address which network segment should receive the delivery.
TCP/IP provides a second tier of logical organization beneath the network ID through what is called a subnet. A subnet is a logical division of the network address space. The routers can deliver a datagram to a subnet address within the network (generally corresponding to a network segment), and once the datagram reaches the subnet, it can be resolved to a physical address using ARP (see Hour 4).
You are probably wondering where this subnet address comes from, since all 32 bits of the IP address are used for the network ID and the host ID. The answer is that the designers of TCP/IP provided a means to borrow some of the bits from the host ID to designate a subnet address. A parameter called the subnet mask tells how much of the address should be used for the subnet ID and how much is left for the actual host ID.
Like an IP address, a subnet mask is a 32-bit binary number. The bits of the subnet mask are arranged in a pattern that reveals the subnet ID of the IP address to which the mask is associated. Figure 5.3 shows an IP address/subnet mask pair. Each bit position in the subnet mask represents a bit position in the IP address.
The subnet mask uses a 1 for every bit in the IP address that is part of the network ID or subnet ID. The subnet mask uses a 0 to designate any bit in the IP address that is part of the host ID. You can think of the subnet mask as a map used for reading the IP address. Figure 5.4 shows the allocation of address bits in a subnetted network versus a non-subnetted network.
The routing tables used by routers and hosts on a subnetted network include information on the subnet mask associated with each IP address. (You'll learn more about routing in Hour 10, "Routing.") As Figure 5.5 shows, an incoming datagram is routed to the network using the network ID field, which is determined by the address class (see Hour 4). Once the datagram reaches the network, it is routed to the proper segment using the subnet ID. After it reaches the segment, the host ID is used to deliver the datagram to the correct computer.