Short tutorial that explains you on how to calculate Subnet Mask of IP address.

Subnet mask is a 32 bits long address used to distinguish between network address and host address in IP address. Subnet mask are used to identify which part of an IP address is network address and which part is host address. Subnetting helps to organize a network by breaking it into several subnets. The subnet mask explicitly defines network and host bits as 1 and 0, respectively.

- In decimal notation subnet mask value 1 to 255 represent network address and value 0 [Zero] represent host address.
- In binary notation subnet mask
**ON**bit [ 1] represent network address while**OFF**bit[0] represent host address.

There are 3 classes of IP addresses.

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

Binary Classifications of the three classes 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)

For example let us consider an IP address 192.35.128.93 which belongs to the network with 6 subnets. How to calculate subnet mask?

**Step 1:** Determine the network class of the given IP Address 192.35.128.93.

**Step 2:** As the IP starts with 192, the address falls on Class C.

**Step 3:** Calculate Number of bits, to define the subnets.

**Step 4:** Formula to calculate **Number of bits = Log2(Number of subnets + 2).**

**Step 5:** Given here is 6 subnets, Applying the values in the formula, we get, Number of Bits = Log2(Number of subnets + 2) = Log2(6+2) = 3 bits.

**Step 6: **Use the bits calculated in the above step, to compose the subnet mask in binary form using the default binary classification.

**Step 7:** IP Address 192.35.128.93 falls on Class C, whose Binary Classification is 11111111.11111111.11111111.00000000. Substitute the subnet bits in the binary classification and we get 11111111.11111111.11111111.**111**00000.

**Step 8:** Convert the binary values to its equivalent decimal values using the 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.

**Step 9: **Converting the IP 11111111.11111111.11111111.**111**00000 into binary using the above rules, we get,

- 11111111 = 255
- 11111111 = 255
- 11111111 = 255
**111**00000 - (128 x 1) + (64 x**1**) + (32 x**1**) + (16 x**1**) + (8 x n) + (4 x 0) + (2 x 0) + (1 x 0) =**224**

**Step 10:** Hence, the IP Subnet Mask = 255.255.255.**224**