An IP address is a 32-bit binary code (often written in the decimal-dot form) that contains network and host parts. The host bits define a particular computer. The network prefix determines a network; its length depends on the network class. Subnetting helps to organize a network by breaking it into several subnets. To define such subnets, you must take bits from the host portion of the IP address. That also extends the network prefix. The subnet mask explicitly defines network and host bits as 1 and 0, respectively.
Video of the Day
In this example, we'll calculate a subnet mask for a computer with IP address 126.96.36.199 that belongs to network with six subnets.
Determine the network class (A, B or C) based on IP address:
- If IP addresses begin with 1 to 126, it is Class A.
- If IP addresses begin with 128 to 191, it is Class B.
- If IP addresses begin with 192 to 223, it is Class C.
In our example, the network is class C since the IP address 188.8.131.52 start with 192.
Determine number of bits needed to define subnets:
- Number of subnets = (2^Number of bits) - 2. Hence,
- Number of bits = Log2(Number of subnets + 2).
In our example, there are six subnets:
- Number of bits = Log2(6 + 2) = Log2(8) = 3. Three bits in the IP address are used as a subnet portion.
Compose the subnet mask in binary form by extending the default subnet mask with subnet bits. Default subnet mask for classes A to C are:
- 11111111.00000000.00000000.00000000 (Class A, network part is 8 bits)
- 11111111.11111111.00000000.00000000 (Class B, network part is 16 bits)
- 11111111.11111111.11111111.00000000 (Class C, network part is 24 bits)
In our example, an extension of the default class C subnet mask with 3 bits (Step 2) results in the subnet mask 11111111.11111111.11111111.11100000.
Convert the binary subnet mask to the decimal-dot form. The binary form contains four octets (8 bits in each). Use following rules:
- For "1111111" octet, write "255".
- For "00000000" octet, write "0".
- If octet contains both "1" and "0" use the formula:
Integer number = (128 x n) + (64 x n) + (32 x n) + (16 x n) + (8 x n) + (4 x n) + (2 x n) + (1 x n) Where "n" is either 1 or 0 in the corresponding position in the octet sequence.
In our example, for 11111111.11111111.11111111.11100000 11111111 ---> 255 11111111 ---> 255 11111111 ---> 255 11100000---> (128 x 1) + (64 x 1) + (32 x 1) + (16 x 0) + (8 x 0) + (4 x 0) + (2 x 0) + (1 x 0) = 224
Subnet mask is 255.255.255.224.