Thursday 8 November 2012

How to made easy Subnetting


Subnetting Made Easy
Hi all,

I've received an email from one of your members asking me to post up my technique for subnetting as links to external blogs are not allowed due to forum rules. I know that he benefited from it and he wishes to help out others so here goes:

First of all I need you to get rid of all of the negative thoughts surrounding subnetting. Put down all of the books that you have read about the subject and navigate away from other sites claiming to provide an easy way to subnet. This technique requires no charts, just simply the know-how to work with the powers of 2.

We need to start with the fundamentals of IP addressing. An IP address is made up of 32 bits, split into 4 octets (oct = 8, yes?). Some bits are reserved for identifying the network and the other bits are left to identify the host.

There are 3 main classes of IP address that we are concerned with.

Class A Range 0 - 127 in the first octet (0 and 127 are reserved)
Class B Range 128 - 191 in the first octet
Class C Range 192 - 223 in the first octet

Below shows you how, for each class, the address is split in terms of network (N) and host (H) portions.

NNNNNNNN . HHHHHHHH . HHHHHHHH . HHHHHHHH Class A
NNNNNNNN . NNNNNNNN . HHHHHHHH . HHHHHHHH Class B
NNNNNNNN . NNNNNNNN . NNNNNNNN . HHHHHHHH Class C

At each dot I like to think that there is a boundary, therefore there are boundaries after bits 8, 16, 24, and 32. This is an important concept to remember.

We will now look at typical questions that you may see on subnetting. More often than not they ask what a host range is for a specific address or which subnet a certain address is located on. I shall run through examples of each, for each class of IP address.
IP addressing and Subnetting:
To fully understand Subnetting, it is vital to know how many network and host bits are present in Class A, Class B, and Class C networks.
             
  First Octet (Range) No. of Network Bits No. of Host Bits Default Mask
Class A 1 – 126 8 24 255.0.0.0
Class B 128 – 191 16 16 255.255.0.0
Class C 192 – 223 24 8 255.255.255.0

Network Address 17.1.1.1 broken down into network and host bits.

Dotted decimal               17           1                             1                             1
Octet in binary 0001001 00000001             00000001             00000001
Network / Host Bits       Network Host                       Host                       Host

SUBNETTING:
Subnetting is simply a process of “borrowing” host bits in order to create the subnet portion of an address. Note in the following examples that the network portion of the address never changes. The subnet field always borrows from the host bits.

Why Use Subnetting?
Subnetting is a highly effective method of conserving  IP address. Consider a point to point ISDN connection with two host addresses, one on each side of the connection. Using an entire Class C address range for this network segment would be a waste of addresses. A default Class C network mask of 255.255.255.0 yields 254 usable host addresses, but only two are needed for this small network.

Subnetting allows the use of a “tighter” subnet mask that the default; that is, one that yields a smaller amount of network addresses. The benefit is that the address that would have been wasted are now still usable by other segments of the network.


Determining the number of valid subnets
To determine the number of valid subnets for a given number and mask, use this formula:
Number of subnets = (2 squared by the number of subnet bits) – 2
The number of subnet bits is determined by examining the default network mask for that class, and comparing it to the actual network mask. Taking network 172.20.20.0 255.255.255.0 as an example, the default mask for the class B network is 255.255.0.0. write out the default mask and the actual mask in binary:

                1st octet 2nd octet 3rd octet 4th octet
Default mask 255.255.0.0 1111111 1111111 0000000 0000000
Subnet mask 255.255.255.0 1111111 1111111 1111111 0000000
Type and number of bits all network bits all network bits all subnet bits all host bits

TRICK:
No. of subnet bits = network bits in (subnet mask) – network bits in (default subnet mask)
No. of hosts bits = 32 – no. of network bits in subnet mask (CIDR value)

Suppose:
x= no. of subnet bits    
y = no. of host bits
No. of valid subnet = 2x -2
No. of host per subnet = 2y – 2
Total no. of host = no. of valid subnet X no. of host per subnet
For example:
i) 172.16.15.0/24               (stated in prefix notation and /24 is called CIDR value)
x = 24 – 16 = 8                    
y= 32 – 24 = 8
No. of subnets = 28 – 2 = 254
No. of host per subnet= 28 – 2 = 254
ii) 10.16.15.0/24
x= 24 – 8 = 16
y= 32 – 24 = 8
No. of subnets = 28 – 2 = 254
No. of host per subnet = 28 – 2 = 254
iii) 192.168.1.64/27
x= 27 – 24 = 3
y= 32 – 27 = 5
No. of subnets = 23 – 2 = 6
No. of host per subnet = 25 – 2 = 30

Determining the subnet number (subnet address) of a given IP address and subnet mask
is accomplished by performing a Boolean AND operation.
First, the IP Address and its subnet mask will be converted to binary. The Boolean AND is simply a bit-by-bit comparison of the IP Address and the Subnet Mask.
1 + 1 = 1
0 + 1 = 0
0 + 0 = 0                                              
(if any value is 0 then result 0)

Consider Network Address 178.56.21.9/24. Convert the IP address and the subnet mask into binary, remembering that /24 is equivalent to 255.255.255.0

                1st octet 2nd octet 3rd octet 4th octet
IP Address 178.56.21.9 10110010 00111000 00010101 00001001
Subnet mask 255.255.255.0 1111111 1111111 1111111 00000000
AND Result 10110010 00111000 00010101 00000000
AND Result (decimal) 172 56 21 0

So, Subnet Address of 178.56.21.9/24 is 178.56.21.0/24

Example: What is the subnet address of 200.154.150.89/27
                1st octet 2nd octet 3rd octet 4th octet
IP Address 200.154.150.89 11001000 10011010 10010110 01011001
Subnet mask 255.255.255.224 1111111 1111111 1111111 11100000
AND Result 11001000 10011010 10010110 01000000
AND Result (decimal) 200 154 150 64

So, Subnet Address of 200.154.150.89/27 is 200.154.150.64/27

Host Range in a given subnet 200.154.150.64/27
Y = 32 – 27 = 5

Total no of valid host in a given subnet = 2y-2 = 30

First IP Address (in the subnet)
(When all hosts bit are 0) Valid Host Range (in the subnet) Last IP Address (in the subnet)
(When all host bits are 1)
200.154.150.64 200.154.150.65 to 200.154.150.94 200.154.150.95
200.154.150.96 (next n/w 64+32)


Meeting Stated Design Requirements:
Example:
Your network uses Class B 165.10.0.0. You need at least 150 subnets that have no more than 200 hosts apiece. What subnet mask should you use?

Solution:
No. of subnet ≥ 150
2X – 2 ≥ 150                          (so x = 8)

No. of hosts per subnet ≤ to 200
2Y – 2 ≤ 200                          (so x = 7)

As 165.10.0.0 is a Class B address with default mask 255.255.0.0. 16 bits are being used for network and leaving another 16 bits to be divided between subnet and host bits.
As no. of Hosts per subnet should not be more than 200, and No. of subnet can be more than 150. We are not going to use more than 7 bits for the hosts, it means we have 9 bits for the subnet.
So x = 9

so the subnet mask you should use is 255.255.255.128 or /25

1 comments: