Subnet Mask - SubnetsSubnet mask shows which bits of an IP address (read the article IP Addresses, by the same author) represent the network and which represent the host. By default we have: IP addresses - Subnet mask Example: When a host A wants to be connected to a host B, the host A uses its subnet mask to check if the host B is on the same LAN - local area network - or on a remote network. For this purpose it is used the boolean ANDing process. Example: Host A IP in binary: Host B IP in binary: Subnet mask in binary: -- ANDing process for Host A -- ANDing process for Host B The calculation works in this way: Since result A = result B the two hosts are on the same network, so the communication is possible without using a gateway ( normally a router ) to establish a connection to another network. There are two ways to write an IP address using subnet mask: Since in a class C subnet mask there are three 255 groups we have 24 bits. Subnets Sometime it is useful to divide a network in smaller networks. Let's suppose we want divide a network, with a class B - IP address, in 8 subnets. The class B subnet mask is 255.255.0.0 We must use some of the 16 bits of the host portion ( borrowing process ) to create the 8 subnets. Since the subnets are 8, we need 8 different combinations plus 1 ( the broadcast ): 9 in total. In binary 9 = 1001, that is 4 bits. Subnet mask: Generally speaking: The calculation for subnets addresses is The calculation for the hosts number is ----------------------bits left (12) The IP addresses numbers are between the IP of the first subnet and the IP of the last subnet with the exclusion of the broadcast and network IP. Broadcast IP have all the bits of the host portion = 1 Network IP have all the bits of the host portion = 0 Final Example: Let's divide a network with IP address 192.168.5.0 ( class C ) in two subnets. The necessary combinations are 3. In binary it is 11, so we have 2 bits. The class C subnetmask is 255.255.255.0 After the borrowing process, it's last group becomes 11000000 which is 192 (base 10). The new subnet mask is 255.255.255.192 Hosts number is 2^6 -2 = 62 ( y = 6 ) Subnets addresses: 256 - 192 = 64 ( s = 192 ) Then 192.168.5.64 and 192.168.5.128 It starts with 64 and goes on adding 64 IP addresses: from 192.168.5.65 to 192.168.5.126 for the first subnet. from 192.168.5.129 to 192.168.5.190 for the second subnet Note: the broadcast address for the first subnet is 11000000.10101000.00000101.01111111, the fourth group is 127 (base 10 ) and the broadcast address of the second subnet is 11000000.10101000.00000101.10111111, the fourth group is 191 ( base 10 ) |