Subnet Mask - Subnets

Subnet 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
Class A - 255.0.0.0
Class B - 255.255.0.0
Class C - 255.255.255.0

Example:
IP address 192.168.8.4 ( class C ). The first 24 bytes represent the network - 192.168.8.0 - and the last 8 bits the host - 4 -.

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 address ( class B ) 172.16.2.4 - Subnet mask ( class B ) 255.255.0.0
Host B IP address ( class B ) 172.16.2.5

Host A IP in binary:
10101100 00010000 00000010 00000100

Host B IP in binary:
10101100 00010000 00000010 00000101

Subnet mask in binary:
11111111 11111111 00000000 00000000

-- ANDing process for Host A
10101100 00010000 00000010 00000100
11111111 11111111 00000000 00000000
-----------------------------------------
10101100 00010000 00000000 00000000 Result for HOST A

-- ANDing process for Host B
10101100 00010000 00000010 00000101
11111111 11111111 00000000 00000000
-----------------------------------------
10101100 00010000 00000000 00000000 Result for HOST B

The calculation works in this way:
- 1 when the first and second bits are both 1.
- 0 when they are 0 and 1, 0 when they are 0 and 0.

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:
Example:
1) 49.22.2.3 255.0.0.0 - class A IP and subnet mask
2) 192.168.1.3/24 - class C IP and subnet mask ( showing its bits ) 255 in binary is 11111111 - 8 bits -.

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:
11111111 11111111 00000000 00000000
Inserting 4 bits in the third group ( the first of the host portion ):
11111111 11111111 11110000 00000000
the third group becomes 11110000 = 240 ( base 10 )
It means that we have a new subnet mask: 255.255.240.0

Generally speaking:
The calculation for the number of subnets is 2^x -2
where x is the bits number for the subnet mask.
( In the example above x = 4 )

The calculation for subnets addresses is
256 - s
where s is the value of the subnet mask: in the same example s = 240

The calculation for the hosts number is
2^y -2
where y is the number of the remaining bits: in the same example y = 12 because

----------------------bits left (12)
11111111 11111111 11110000 00000000
----------------- bits
----------------inserted
------------------(4)

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 )

Renato Piccini - Florence - Italy
Computers Networks technician
http://www.softgrafic.com