networking@andystechpage.com
Subnetting and
Binary Anding

Large groups of IPs are
broken into smaller subnets..
Network Theory


This article requires an understanding of binary mathematics. I recommend you refer to Binary Basics under the PC Operations, File Basics Menu prior to reading this section.

Subnetting has a number of uses. It can be used to control bandwidth use on a network or for security purposes (it's harder for hackers if they have to cross routers). Subnetting also allows nore efficient use of a block of IP addresses.

Under TCP/IP, IP Addresses are put into groups such as Class A, Class B, and Class C IP addresses and so on.
Class A IP addresses have a subnet mask of 255.0.0.0
Class B IP addresses have a subnet mask of 255.255.0.0
Class C IP addresses have a subnet mask of 255.255.255.0

An IP address is a 32-bit number separated into 4 "octets", which are simply 8 bits. Each octet can have a decimal value from 0 to 255. A subnet mask looks very similar to an IP address and represents the ratio of available networks to the number of available hosts per network.

IP addressing also requires an ability to convert between binary and decimal. Calculating the decimal equivalent is a matter of adding the decimal column numbers together. If a '1' appears in the binary number then the decimal equivalent at the top of the column is included in the addition. If a binary '0' appears, then that decimal equivalent at the top of its column is not counted (see binary basics for more detail).

decimal
128
64
32
16
8
4
2
1
                 
3
0
0
0
0
0
0
1
1
18
0
0
0
1
0
0
1
0
158
1
0
0
1
1
1
1
0
255
1
1
1
1
1
1
1
1


IP Addressing uses binary ANDing where two binary numbers are compared and the resulting number depends on the formula of..

1+1 = 1
0+1 = 0
0+0 = 0

This is used in conjunction with the IP address and the subnet mask to determine the "network address". For instance with an IP address of 192.168.100.1 and subnet mask of 255.255.255.0 the network address can be determined. This is what separates networks from hosts. For instance:

11000000.10101000.01100100.00000001 (IP address 192.168.0.1)
+
11111111.11111111.11111111.00000000 (subnet mask 255.255.255.0)
---------------------------------------------------------
11000000.10101000.01100100.00000000
= 192.168.100.0
= network address


Thus the network address uses (from left to right) three octets or 24 bits. This is known as a Class C addressing scheme. It leaves the last octet for use in addressing hosts. In other words, in this example you would have 256 numbers (0-255) that could be placed at the end of the network address to differentiate between hosts; hence their name, host addresses. Note that the first and last addresses in a block of addresses are reserved (at binary level, no address can have all zeros or all ones). In the example, a host address of 0 or 255 cannot be used, leaving 254 valid host addresses.

No matter what values are used in the IP address, the network address will always be the same. So in a class C network, 8 bits are reserved to determine the number of hosts while 24 bits determine the number of networks.

In this example, if you raise 2 to the power of (24-2) the result is 4194304 (all ones or all zeros are invalid, hence 24-2). This is the number of networks available which each have 254 valid host addresses. Note this not completely accurate as certain address ranges are reserved and also because certain network addresses will not be valid, for similar reasons that the first and last IP addresses are not valid.

If a range of 254 IP addresses is more than required, a system called CIDR (Classless Inter-Domain Routing) subnetting is used. For instance if only 50 IP as required, based on a Class C subnet mask the entire block of 256 addresses would have to be used, wasting many addresses. In the previous example the last octet in the subnet mask is all zeros. This is what determines the number of hosts.

If the last octet of the subnet mask was 11000000 = 192, the entire subnet mask would be: 255.255.255.192. If you consider all the 32 available bits, you have used 26 (binary notation, counting ones from the left). This can be represented as: 192.168.100.x/26, where 'x' represents the beginning number of the block of addresses.

Now there are 6 bits left to determine the number of hosts. If one adds the decimal totals for those 6 bits, there is a range of 0-63 or 64 addresses. In the example one block of 256 addresses was divided into four blocks of 64 addresses (0-63,64-127,128-191,192-255) of which 62 addresses per block are valid (1-62,65-126,192-190,193-254).

Note that the first and last addresses are not valid, resulting in 62 usable addresses. The same applies to the networks where the two bits that make up the 192 octet cannot be all zeros or all ones; thus the ranges 0-63 and 192-255 are invalid.

- A.
andystechpage.com
Put 06.12.2004 | | Refresh Page |