Subnetworks

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 171.16.0.0. (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 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

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

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.


Class B Subnetting Reference
BitsSubnet maskSubnetsHosts
2255.255.192.0216,382
3255.255.224.068,190
4255.255.240.0144,094
5255.255.248.0302,046
6255.255.252.0621,022
7255.255.254.0126510
8255.255.255.0254254
9255.255.255.128510126
10255.255.255.1921,02262
11255.255.255.2242,04630
12255.255.255.2404,09414
13255.255.255.2488,1906
14255.255.255.25216,3822


Class C Subnetting Reference
BitsSubnet maskSubnetsHosts
2255.255.255.192262
3255.255.255.224630
4255.255.255.2401414
5255.255.255.248306
6255.255.255.252622


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

The result of an AND operation using the subnet mask