# 6: Subnet Mask and Subnetting

When we understand the following rule, it will help us in the understanding of the subnetting.

Suppose that we have 1 place that we need to replace it with a binary number. What numbers can be used? The answer is ‘0’ or ‘1’, which are 2 values or (21 values), from decimal ‘0’ to decimal ‘1’. Suppose that we have 2 places that we need to replace it with binary number. What numbers can be used? The answer is ‘00’, ‘01’, ‘10’ or 11, which are 4 values or (22 values), from decimal ‘0’ to decimal ‘3’. Now, if you have 3 places… you will have 8 values (23 values), from decimal ‘0’ to decimal ‘7’. Therefore, what if we have 4 or 5 or…8 places? From the previous, we can deduce that, The subnet mask enables you to know the network portion and host portion of any IP address.

If no subnet mask information is associated with the IP, then the default is to determine the network portion and the host portion of this IP address depending on its IP class.

The subnet mask determines the network portion and the host portion of an IP address by converting the network portion to all ones and converting the host portion to all zeros.

Therefore, for the ‘class A’ subnet mask, the first bye will be all ones and the last three bytes will be all zeros.   ### 6.1.1 Getting the network IP using the subnet mask

To get the network IP from any IP address, we should convert the host portion to zeros.

The theoretical method to get the network IP, is to make a logical AND operation between the IP and its subnet mask. Figure 6.1: getting the network IP

The following illustrates the AND function, Figure 6.2: the logical AND function

#### Example 1

Get the network IP and the broadcast IP from the following IP and subnet mask ‘193.129.2.131/25’. In addition, get the number of available host IPs, and determine the first and the last available host IP. #### To get the number of available host IPs, we use the following rule, Therefore, the number of available host IPs = #### Example 2

Get the network IP and the broadcast IP from the following IP and subnet mask ‘130.5.192.68/26’. In addition, get the number of available host IPs, and determine the first and the last available host IP. The number of available host IPs= ## 6.3 Subnetting

Suppose that we have one network IP and we have three networks. How we can use this only one network IP to be able to assign one network IP to every network of our networks?

The solution is to make ‘subnetting’.

### 6.3.1 What is subnetting?

Subnetting is to get many ‘network IPs’ from only one network IP, by changing in the network portion and the host portion in the original network IP.

### 6.3.2 Subnetting example 1

You have one ‘class C’ IP address (194.5.24.0), and you have two networks, every one of them has 100 computers. You should subnet this IP to fulfill your needs.

#### Solution:

Convert the given IP to binary formatting and determine the network portion and the host portion.

Determine how many bits you need to add to the network portion in order to have the correct number of network IPs. Now, you can get the new subnet mask Make sure you can cover the number of host IPs in every network. Now, you can get the subnetted network IPs. ### 6.3.3 Subnetting example 2

You have one ‘class B’ IP address (134.18.0.0), and you have three networks, every one of them has 100 computers. You should subnet this IP to fulfill your needs.

#### Solution:

Convert the given IP to binary formatting and determine the network portion and the host portion. Determine how many bits you need to add to the network portion in order to have the correct number of network IPs. Now, you can get the new subnet mask. Make sure you can cover the number of host IPs in every network. Now, you can get the subnetted network IPs. 