2.1 IPv4 Addressing
2.1.4 Subnet masking
As you may already know from previous study or experience, subnet masking, or subnetting, is used to break one large group into several smaller subnetworks. These subnets can then be distributed throughout an enterprise, resulting in less waste and better logical organization. Formalized with RFC 950 in 1985, subnetting introduced a third level of hierarchy to the IPv4 addressing structure. The number of bits available to the network, subnet, and host portions of a given address varies depending on the size of the subnet mask.

A subnet mask is a 32-bit number that acts as a counterpart to the IP address. Each bit in the mask corresponds to its counterpart bit in the IP address. If a bit in the IP address corresponds to a 1 bit in the subnet mask, the IP address bit represents a network number. If a bit in the IP address corresponds to a 0 bit in the subnet mask, the IP address bit represents a host number.

In effect, the subnet mask (when known) overrides the address class to determine whether a bit is either network or host. This allows you to configure routers and other hosts to recognize addresses differently than the format dictated by class. For example, you can use the mask to tell hosts that, even though their addresses are Class B, the first three octets (instead of the first two) are the network number. In this case, the additional octet acts like part of the network number, but only inside the organization where the mask is configured.

The subnet mask applied to an address ultimately determines the network and host portions of an IP address. The network and host portions change when the subnet mask changes. If you apply the mask 255.255.0.0, only the first 16 bits (two octets) of the IP address 172.24.100.45 represent the network number, as shown in Figure . Therefore, the network number for this host address is 172.24.0.0. The shaded portion of the address in Figure indicates the network number.

Because the rules of class dictate that the first two octets of a Class B address are the network number, this 16-bit mask does not create subnets within the 172.24.0.0 network.

To create subnets with this Class B address, you must use a mask that identifies bits in the third or fourth octet as part of the network number.

You can apply a 24-bit mask, 255.255.255.0, which specifies the first 24 bits of the IP address as the network number. The network number for this example host is 172.24.100.0. The shaded portion of the address in Figure indicates this.

Routers and hosts configured with this mask will see all 8 bits in the third octet as part of the network number. These 8 bits are considered the subnet field because they represent network bits beyond the two octets prescribed by classful addressing.

Inside this network, devices configured with a 24-bit mask will use the 8 bits of the third octet to determine what subnet a host belongs. Because 172.24.100.45 and 172.24.101.46 have different values in the third octet, they do not belong to the same logical network. Hosts must match subnet fields to communicate with each other directly. Otherwise, the services of a router must be used so that a host on one subnet can talk to a host on another.

An 8-bit subnet field creates 28, or 256, potential subnets. Because 8 bits remain in the host field, 254 hosts may populate each network (two host addresses are reserved as the network number and broadcast address, respectively). By dividing a Class B network into smaller logical groups, you can make the internetwork more manageable, more efficient, and more scalable.

Note that subnet masks are not sent as part of an IP packet header, so routers outside this network will not know what subnet mask is configured inside the network. An outside router will therefore treat 172.24.100.45 as just one of sixty-five thousand hosts that belong to the 172.24.0.0 network. In effect, subnetting provides a logical structure that is hidden from the outside world.