# How to calculate the subnet mask from an Ip?

[10:34 AM] Charan Williams

The subnet mask of a network is used to divide the IP address space into a network and host portions. To determine the subnet mask for a specific network range, we need to know how many bits are used to represent the network portion of the IP address.

In the case of the network range 192.168.1.0/28, the /28 indicates that the first 28 bits of the IP address represent the network, and the remaining 4 bits represent hosts within that network.

To convert this prefix length to a subnet mask, we can use the formula:

subnet mask = 2^(32 – prefix length) – 1

Plugging in the prefix length of 28, we get:

subnet mask = 2^(32-28) – 1 = 2^4 – 1 = 15

So the subnet mask for the network range 192.168.1.0/28 is 255.255.255.240.

The other subnet masks listed do not correspond to the prefix length of 28.

• 255.255.255.192 corresponds to a /26 prefix length.
• 255.255.255.240 corresponds to a /28 prefix length.
• 255.255.0.0 corresponds to a /16 prefix length.
• 255.255.255.0 corresponds to a /24 prefix length.

[10:34 AM] Charan Williams

The subnet mask is a 32-bit value used to identify which portion of an IP address represents the network and which portion represents the host. The value of the subnet mask is a sequence of 1’s followed by a sequence of 0’s. The number of 1’s in the subnet mask indicates how many bits are used to represent the network portion of the IP address.

In the formula subnet mask = 2^(32 – prefix length) – 1, we first calculate the number of bits used to represent the host portion of the IP address. In this case, the prefix length is 28, so the host portion of the IP address uses 4 bits.

Next, we calculate 2^(32 – prefix length), the number of possible network addresses in the given range. In this case, we have:

2^(32 – 28) = 2^4 = 16

Finally, we subtract 1 from this value to get the number of valid network addresses in the range. In this case, we have:

2^(32 – 28) – 1 = 16 – 1 = 15

This gives us the value of the subnet mask, which is a sequence of 1’s followed by a sequence of 0s with a length of 32 bits. Since we have 28 bits for the network portion of the IP address, we set the first 28 bits of the subnet mask to 1, and the remaining 4 bits (for the host portion) to 0. This gives us the subnet mask:

11111111 11111111 11111111 11110000

In dotted decimal notation, this is equivalent to:

255.255.255.240

Therefore, the subnet mask for the network range 192.168.1.0/28 is 255.255.255.240.

To clarify further:

The number 15 calculated for the subnet mask represents the number of valid host addresses in the subnet. In the subnet mask, the bits set to 1 represent the network portion of the IP address, and the bits set to 0 represent the host portion.

For the subnet mask 255.255.255.240, the binary representation is:

11111111 11111111 11111111 11110000

This means that the first 28 bits of an IP address in the subnet represent the network portion, and the last 4 bits represent the host portion. Since there are 4 bits for the host portion, there are 2^4 (or 16) possible combinations of host bits. However, we need to subtract 2 from this value because the first address in the subnet (192.168.1.0) is reserved as the network address, and the last address in the subnet (192.168.1.15) is reserved as the broadcast address. This leaves us with 14 possible host addresses in the subnet.

So, the range of valid host addresses for the subnet 192.168.1.0/28 is:

192.168.1.1 to 192.168.1.14

All other addresses in the subnet are either reserved or cannot be used as valid host addresses.