IP networks can be divided into smaller subnetworks. Subnetting gives the network administrator the ability to use network addresses more efficiently, and a given network address can be broken up into many subnetworks. For example, 172.16.1.0, 172.16.2.0, 172.16.3.0, and 172.16.4.0 are all subnets within network 18.104.22.168. (All 0s in the host portion of an address specifies the entire network). A subnet address is created by using some of the bits from the host field to create the subnet field. The number of bits used varies, and is determined by the subnet mask. The diagram below shows how bits are borrowed from the host field to create the subnet address field.
The subnet field is created using bits taken from the host field
The subnet mask has binary 1s in all bits specifying the network and subnetwork fields, and binary 0s in all bits specifying the host field. The diagram below shows an example subnet mask.
An example subnet mask
Subnet mask bits for class B and class C networks should come from the high-order (left-most) bits of the host field, as shown in the diagram below. Class A addresses are generally subnetted on an 8-bit boundary.
Subnet masks for class B and C networks come from the high-order bits of the host field
The default subnet mask for a Class B address with no subnetting is 255.255.0.0, while the subnet mask for a Class B address 172.16.0.0 that specifies eight bits of subnetting is 255.255.255.0. Eight bits of subnetting means that 254 subnets are possible, with 254 hosts per subnet. The subnet mask for a Class C address 192.168.2.0 that specifies five bits of subnetting is 255.255.255.248. With five bits available for subnetting, 30 subnets are possible, with 6 hosts per subnet. The tables below can be used to determine subnet masks for Class B and C networks.
Using subnet masks to determine the network number
In order to determine the network (or subnetwork) address, the router first extracts the destination IP address from an incoming packet, and then retrieves the internal subnet mask. It carries out a logical AND of these two numbers in order to obtain the network number. This removes the host portion of the destination IP address and leaves the destination network number. The router looks up the destination network number and matches it to an outgoing network interface. It then forwards the packet to the destination IP address. The following diagram shows how a logical AND of the destination IP address and the subnet mask produces the subnetwork number.
The result of an AND operation using the subnet mask