Monday, July 23, 2007

IP Addressing And SubNetting

IP Addressing And SubNetting
By Dr.T of BCVG Dr.T,
www.ebcvg.com
raven@ebcvg.com

Another article explaining basics of IP addressing and building subnets.


Basic Definitions
=====================

Here are some basic definitions I think that one should know in order to understand this article:

IP Address - A unique number ID assigned to one host or an interface on a network.

Subnet - A portion of a network sharing a particular address.

Subnet Mask - A 32 bit combination used to describe which portion of an address refers to the subnet and which part refers to the host.

Interface - A network connection.

InterNIC - Internet Network Information Center

NIC - Network Interface Card.

Ethernet - An Ethernet is the IEEE 802.3 Standard that allows two or more computers transfer data back and forth. The access method used, is based on Ethernet systems, which range from 1Mbps - 1000Mbps (1GBps).


Internet Protocol (IP)
=========================

The Internet Protocol, IP, is a network protocol that contains addressing information and control information that enables packets to be routed. The IP protocol is the primary protocol along with the TCP (Transmission Control Protocol) in the Internet Protocol Suite (IPS). IP actually work like a router and it is the heart of the IPS while the TCP protocol responsible that divide and reassembly packets and to assure that everything come to its destination and if not to resend it again.


IP Addressing
======================

An IP Address is actually a 32-bit (4 bytes) number, which provides you information on how to access the system and how to communicate with it through specific protocols - set of commands which computers use when they communicate (transfer data, files etc.).

The IP address is divided into 4 octets which each one takes 8bits = 1byte.
In order to represent the IP address of a system, we usually use the following structure: xxx.xxx.xxx.xxx where each 'xxx' is on octet. This way of representation called the dotted decimal notation. Each octet can contain a value range from 0 - 255 in decimal or from 00000000 - 11111111 in binary form. The reason the value can range from 0 to 255 is because each octet is one byte and the range of the values can range from 0 to 255 only.

Here is how binary octets convert to decimal (basic knowledge in binary is required):


1 1 1 1 1 1 1 1 - Binary octet

128 64 32 16 8 4 2 1 - Decimal octet


To find the value in this octet we need to sum all the number we got: 128+64+32+16+
8+4+2+1 = 255. Here is another sample of octet conversion:


0 1 0 0 0 0 0 1 - Binary octet

0 64 0 0 0 0 0 1 - Decimal octet


The result is 64+1 = 65.

To make the work with IP Addresses easier, they have been divided into five classes, each one of which has its own properties and intended use. Nowadays only the first three IP Address Classes are used (A, B and C) while the remaining two (D and E) serve for experimental and for research purposes only. Here are the IP Address Classes:


Class Name Network & Host IP Address Range Example
===============================================================

Class A: N.H.H.H 1.0.0.0 - 126.255.255.254 24.215.1.50

Class B: N.N.H.H 128.1.0.0 - 191.254.0.0 187.45.44.12

Class C: N.N.N.H 192.0.1.0 - 223.255.254.0 200.20.21.20

Class D: Not Available 224.0.0.0 - 239.255.255.255 225.45.33.33

Class E: Not Available 240.0.0.0 - 254.255.255.255 243.55.190.22

The “N” and “H” in the above table designate the Network ID and Host ID respectively.
Each host on the TCP/IP network is assigned a 32 bit number - IP Address – which consists of two parts (sections): the Network ID (network class) and the Host ID (host number). The Network ID identifies the network and must be assigned by the InterNIC, if the network is part of the Internet. The Host ID identifies a host on a network and is assigned by the local network administrator.

The first class is Class A. This class usually used by very large organizations (military, big universities etc.) that have many computers in their network. Their Network ID is only 8 bits (1 byte) long, which leaves 24 bits (3 bytes) for the Host ID. This means that such a network can hold up to (2^24 - 2) hosts.
Class B usually serves smaller universities, big companies, ISPs etc. The Network ID is 16 bits (2 bytes) long, which leaves 16 bits (2 bytes) for the Host ID. Such a network can hold up to 65,534 (2^16 - 2) hosts.
Class C is intended for small organizations and home users. The Network ID is 24 bits (3 bytes) long, which leaves 16 bits (2 bytes) for the Host ID. Such a network can hold only 254 (2^8 - 2) computers.

The class of any given IP address can be determined easily by the value of its first octet. For example, if we have the IP address 145.44.5.34, the value in the first octet is 145 and since this value falls in the range between 128 and 191, this IP Address belongs to Class B. If we have the IP Address 12.34.212.4 then the value in the first octet is 12, which belongs to Class A because it falls between 1 and 126.

Now that we understand the structure of IP addresses it is the time for explanation about special values that might present in some of its octets.
The first such value is 0 - it is reserved for systems that "do not know" their address. It is possible for a system to not know its network class or even host; a system with IP 0.0.0.90 “knows” that its host number is 90, but it “does not know” on what network.

The second reserved value is 255. It is used for broadcasting – sending a message to everyone on the network. For example, if you “sit” on 154.9.5 network and want to send a message to everybody on that network you should send it to 154.9.5.255. Notice that on some older system, the value 0 is used as the broadcast value.

The last reserved value is 127. This value does not belong to any class and it is used for special purposes only. A very common example is 127.0.0.1, which is the IP address assigned to every system, which is not connected to the Internet. If you have a web server installed on your system and you type 127.0.0.1 at the address bar you will arrive to the home page.

Sub-netting
========

Most of the people who work with networks see Sub-netting or IP Sub-netting as one of the most difficult to understand. Nevertheless, I will try to explain it in plain words and simple examples.

Basically sub-netting is dividing IP networks into smaller networks called sub-networks or subnets. Sub-netting is very important and useful feature, which provides the network administrator with several benefits: extra flexibility, more efficient use of network addresses and the capability to maintain broadcast traffic.
Subnets are under local administration and they reflect the organization’s internal structure. As such, the outside world sees the organization as a one single network and has no knowledge about the details of its internal structure.

The first step in learning sub-netting is to understand what is IP Subnet Mask or Subnet Mask (notice that this is not the same as Subnet!). Subnet address is created by "borrowing" bits from the Host ID section and designating them as a subnet section (notice that your can "borrow” only from the Host ID section and not from the Network ID section!!).
The subnet mask specifies the number of the “borrowed” bits. We represent the subnet mask the same way we represent the IP address octets, but the values can only be 0, 128, 192, 224, 240, 248, 252, 254, and 255 as the borrowed bits are the higher ones and have to be sequential. The subnet mask is built according to the number of the "borrowed" bits from the Host ID – see the following table:

128 64 32 16 8 4 2 1
1 0 0 0 0 0 0 0 = 128
1 1 0 0 0 0 0 0 = 192
1 1 1 0 0 0 0 0 = 224
1 1 1 1 0 0 0 0 = 240
1 1 1 1 1 0 0 0 = 248
1 1 1 1 1 1 0 0 = 252
1 1 1 1 1 1 1 0 = 254
1 1 1 1 1 1 1 1 = 255

In the above table you can see the number of the "borrowed" bits and the relative value that should appear in the subnet mask. Lets take an example and analyze it. If we take the IP address 148.44.34.90, according to first octet we find that it belongs to Class B so we have two Network ID octets:

[ 148 ] . [ 44 ] . [ 34 ] . [ 90 ] - IP address
[ N ] . [ N ] . [ H ] . [ H ] - Network ID and Host ID

If we want to create a sub-network from this network and we want to "borrow" 8 bits from the third octet we'll get the following subnet mask:


[ N ] . [ N ] . [ H ] . [ H ] - Network ID and Host ID

[ N ] . [ N ] . [ SN ] . [ N ] - Network ID, Host ID and Sub-network

[ 255 ] . [ 255 ] . [ 255 ] . [ 0 ] - subnet mask

As you can see, when you build a subnet mask the Network ID octets become automatically 255 and according to the "borrowed" bits we can find our what value should the other octet(s) contain(s). If we don't want to create any sub-network from a given IP address we'll have the following defaults subnet masks:

Class A - 255.0.0.0
Class B - 255.255.0.0
Class C - 255.255.255.0

After I have explained what is Sub-netting and how to find out subnet masks it's time to explain how to calculate the number of subnets and hosts for each network. Each network can contain limited amount of subnets and hosts per subnet. In order to know these numbers we must know the subnet mask of the given network because the number of subnets and the number of hosts per subnet is a function of the "borrowed" bits.

The best way to explain this is giving an example.
Assume we have the IP Address 148.44.34.90, which (see above) belongs to Class B and we have 16-bit Network ID and 16-bit Host ID. As I wrote above we can use only the Host ID section for creating sub-networks. In our case the maximum number of bits, which we can “borrow”, is 16. Now, lets say we want to create a sub-network of 7 "borrowed" bits so, our subnet mask is 255.255.254.0 and the number of subnets which we can create with this subnet mask is 2^7 - 2 (we must subtract two because one place is reserved for broadcast and another one - for network address) = 126 possible sub-networks. Now, the number of hosts per each subnet is 2^9 - 2 = 510 hosts.

Now after I have gave a little example I'll sum the above paragraph to general "equations":

Number of subnets = 2^[Number of borrowed bits] - 2
Number of hosts per subnet = 2^[HostID bits - Number of borrowed bits] - 2

In order to determine the sub-network address of a specific IP address, we need to do a set process. For that we use the logical operator AND. Here is the table of the AND logical operator:

0 AND 0 = 0
0 AND 1 = 0
1 AND 0 = 0
1 AND 1 = 1

Again, the best way to explain this is showing an example. Assume we have the IP address 190.33.10.12 with the subnet mask 255.255.255.0. The first step to find what is the subnet mask is transferring the Host ID bits of the IP address and the "borrowed" bits of the subnet mask:

IP Address 190.33.10.12 10.12 (Class B, first two octets are fixed)
Subnet mask 255.255.255.0 255.0 (only the "borrowed" bits)

10.12 00001010 00000000
255.0 11111111 00000000

After we have transferred them into binary form all we have to do now is to make a simple AND operation. As a result of this AND operation we will get the subnet address:

00001010 00000000
AND
11111111 00000000
--------------------
00001010 00000000 = 10.0

As you can see from the above AND operation, we have got the network address of the IP address 190.33.10.12. Now, we know that IP address 190.33.10.12 belongs to network address 190.33.10.0, and the valid addresses ranging from 190.33.10.1 - 190.33.10.254. 190.33.10.255 is used for broadcast.

Final Words
================

I hope that I made this tutorial is simple and clear enogh. Should you have any questions, comments, suggestions do not hesitate to contact me via email.
This tutorial utilizes few articles of Cisco (R).

No comments: