 # How to calculate a subnet mask

Subnet mask – the convenient mechanism for division of the address of network and the address of a specific node. Such mechanism was installed already in the first standard of the IP protocol in September, 1981. For simplification of routing and increase in its efficiency it is necessary to be able to calculate a mask.

Instruction

1. The subnet mask, as well as the network address, represents four one-byte numbers (for the version of IPv4 protocol, in IPv6 protocol they represent 8 groups of sixteen-bit digits). For example: IP address 192.168.1.3, subnet mask 255.255.255.0. In TCP/IP networks a mask is called the bitmap which defines what part of the network address is the address of network and what – a node address. For this purpose the subnet mask needs to be presented in the binary form. Those bits which values are set in unit indicate the address of network, and bits which values are equal to zero – indicate a node address. For example, subnet mask 255.255.255.0. It is possible to present it in the binary form: 11111111.11111111.11111111.00000000. Then for address 192.168.1.1 Part 192.168.142 will be the address of network, and.142 - a node address.

2. Apparently from the previous step, there is a restriction for number of nodes and networks. It turns out from restriction for number representable the set number of bits of options. One bits can code only 2 statuses: 0 and 1. 2 bits – four statuses: 00, 01, 10, 11. Generally, n of bits code 2^n statuses. At the same time you remember that all units and all zero in a node address and network are backed up by the standard for the designation "current node" and "all nodes". Thus, it turns out that the total number of nodes in network is defined by formula N=(2^z)-2 where N – the total number of nodes, z – number of zero in binary representation of a subnet mask.

3. Remember that the mask can be made not of any numbers. The first bits of a mask always single, the last - zero. Therefore sometimes it is possible to meet an address format in the form of 192.168.1.25/11. It means that the first 11 bits of the address – the address of network, the last 21 – a node address in network. This record corresponds to address 192.168.1.25 and a subnet mask 255.224.0.0. When calculating a subnet mask it is necessary to proceed from the number of computers in network. Consider also its possible expansion: if the number of computers exceeds possible for this network, it will be necessary to change manually all addresses and masks on each computer.

4. Addressing is class and classless. Division into classes was used in early implementation of the protocol, and later, with growth of the Internet, it was complemented with classless addressing. Class addressing selects 5 classes: A, B, C, D, E. The class defines how many bits of the address will be taken away under the address of network and how many – under a node address. In this case it is not necessary to consider anything. In class A under the address of network 7 bits, in a class B – 14 bits, in a class C – 21 bits are taken away. The class D is used for multi-address mailing, the class A of E is reserved for experimental use. At the same time the first several bits of the address are used for definition of its class. In class A it is 0 in the first bit, in class B – 10, in class C – 110, in a class D – 1110, in a class E – 11110.

5. Class addressing reduced flexibility of the IP protocol in respect of selection of the addresses, and reduced quantity of possible. Therefore classless addressing was accepted. For finding of a mask at first define how many nodes you will have in network, including gateways and the other network equipment. Add to this number two and round up to the next power of two. For example, you plan 31 computers. Add to it two, receive 33. The next power of two - 64, that is, 100 0000. After that add everything the senior bits with units. Receive mask 1111 1111. 1111 1111. 1111 1111. 1100 0000 that in a decimal system there will be 255.255.255.192. In network with such mask it is possible to receive 62 different IP addresses which are not backed up in the standard.

Author: «MirrorInfo» Dream Team