### How to find Subnet Mask?

We can find Subnet Mask from any below information available.

How to find Subnet Mask from prefix?

Prefix or CIDR Netmask represents network part.

So, Network Bits = Prefix #
Subnet Mask is 32 bits binary number. Which consists of Network Bits and Host Bits.

SM = 32 and NB = prefix#
SM = NB + HB
SM = prefix# + HB
To find Subnet Mask form 32 bit binary number which has consicutive prefix# times '1' and remaining bits as 0
Divide this binary number in 4 octets and convert octets to decimal format.

Example:

Write 23 times consecutive '1' as Prefix# = 23
SM = 11111111111111111111111

Now append consecutive '0' HB times with SM. here HB = 9.
SM = 11111111111111111111111000000000

Divide in 4 octets
SM = 11111111.11111111.11111110.00000000

Convert octets to decimal
SM = 255.255.254.0
Hence for network /23 Subnet Mask is 255.255.254.0

How to find Subnet Mask from Network Bits or Host Bits?

As mentioned before Subnet Mask is 32 bits binary number. Which consists of Network Bits and Host Bits.

SM = NB + HB
To find Subnet Mask form 32 bit binary number which has consicutive prefix# times '1' and remaining bits as 0
Divide this binary number in 4 octets and convert octets to decimal format.

Example:
Subnet Mask for Network Bits 25 or Host Bits 7

Write 25 times consecutive '1' as NB = 25
SM = 1111111111111111111111111

Now append consecutive '0' HB times with SM. here HB = 7.
SM = 11111111111111111111111110000000

Divide in 4 octets
SM = 11111111.11111111.11111111.10000000

Convert octets to decimal
SM = 255.255.255.128
Hence for network /25 Subnet Mask is 255.255.255.128

SM = ~ WM

Example:

WM = 00000000.00000000.00000000.01111111
SM = 11111111.11111111.11111111.10000000

Convert octets to decimal
SM = 255.255.255.128