Pages

Thursday, May 4, 2017

About IP Addressing & Calculating first and Last IP address of a subnet

IP Default Subnet Masks For Address Classes A, B and C

IP Address Classes

Class -A - 0 -126
Class  B - 128- 191
Class C  - 192 - 223
Class D - 224  -249 
Clase E  - 250 - 255

Class D for Multicast
Class E reserved for Testing

Class A - N.H.H.H
Class B - N.N.H.H
Class C - N.N.N.H

Default Subnet Mask

Subnet mask for a default, unsubnetted class A, B or C network has ones for each bit that is used for network ID or subnet ID, and zeroes for the host ID bits. Of course, we just said we aren't subnetting, so there are no subnet ID bits! Thus, the subnet mask for this default case has 1s for the network ID portion and 0s for the host ID portion. This is called the default subnet mask for each of the IP address classes.

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

What is Subnetting

Subnetting is the process of dividing a Class A, B or C network into subnets, as we've seen in the preceding topics. In order to better understand how this “division of the whole” is accomplished, it's worth starting with a look at how the “whole” class A, B and C networks are represented in a subnetted environment. This is also of value because there are situations where you may need to define an unsubnetted network using subnetting notation.

This might seem like a strange concept—if you aren't going to bother creating subnets, why do you need to consider how the old-fashioned classes are used under subnetting? The answer is that after subnetting became popular, most operating systems and networking hardware and software were designed under the assumption that subnetting would be used. Even if you decide not to subnet, you may need to express your unsubnetted network using a subnet mask.


Custom subnetting 

Will be done by adding extra bits from host bit.

If we want two subnet then we need to add 1 bit from host bit. If we want 20 subnet then we need to borrow 5 bits as  4 bits will give only 16 subnets

Each bit taken from the host ID for the subnet ID doubles the number of subnets that are possible in the network.

Each bit taken from the host ID for the subnet ID (approximately) halves the number 

so /16 means 255.255.0.0 this will be the subnet of either class B or Class A. So to determine Class A or Class B, Class C only subnet is not enough we need IP address of Host as well.

eg 1) If 10.0.0.0/8 is the IP address then subnet will be 255.0.0.0 then the number of hosts will be calculated by the left over host bits. In this case out of 24 bits 8 are used by network so remaining 24 will be used for host, so 2^24 = 16777216, is the total number of hosts in this network.

eg 2) If the IP address is 10.0.0.0/17 then subnet mask will be  255.255.128.0. As the 9 bits are borrowed from host bit. And the number of hosts will be calculated by  ( Subnet mask - 1111 1111.1111 1111.1000 0000. 0000 0000) 32 -17 =15  2^15 = 32768 and total number of usuable ip's are 32768 -2 = 32766.

Normally first usable IP is the default gateway and last IP is used for brodcating. 


It's important to understand what default subnet masks are and how they work. A default subnet mask doesn't really represent subnetting, however, since it is the case where we are assigning zero bits to the subnet ID. To do “real” subnetting we must dedicate at least one of the bits of the pre-subnetted host ID to the subnet ID, as shown in the example in the topic that introduced subnet masks.

In this post will see how to calculate the first and last IP address of a subnet from a given IP address and also how to create subnet.

Part 1 : Calculate the first and last IP of an IP address range

Question : What is the first and last IP addresses of this network? 192.168.176.0/23. 

To identify the first and last IP of the given address we need to find out below details

1) Interesting Octet
2) Magic Number
3) Subnet Number
4) Broadcast ID

Interesting Octet - First you need to find the interesting octet of the mask. Take a look at each octet in the mask and see if it's a 255, 0, or some other number. If the octet is neither a 255 or 0, that's your interesting octet. 

In Our case - 255.255.254.0 (Highlighted 254 is the interesting octet)
So, Interesting octet from the IP - 254

Now that we have the interesting octet, compare the mask to the IP address. Anything on the left of the interesting octet, signals that you should copy the IP address octet to your subnet number. (X means it's currently unknown)

In our case - 192.168.X.X

Magic Number - Next we need to calculate the magic number. To find the magic number, simply subtract the number 256 from the interesting octet in the mask

In our case : 256 - 254 = 2

Subnet Number -  Step 3 is to identify the subnet number from the magic number. To identify the subnet number find the multiples of magic number that is lesser than or equal to the interesting octet in the IP address. 

Magic number is 2. Multiples of 2 is 2, 4, 6, 8 and ... 172, 174, 176...

You can see, 176 is the closest number to 176 and which is actually not going above 176. Yes, 176 is our subnet number. Simply place 176 in the interesting octet in the IP address.

So IP address will be like - 192.168.176.0

BrodcastFinding the broadcast address is very easy.  Take the interesting octet from IP address field which we found now (176) and add the magic number (2) then subtract 1. This gives you your interesting octet for the broadcast address.

Broadcast = ( Interesting Octet of subnet + Magic Number ) -1 

From our eg, 176 + 2 -1 = 177. So, Brodcast IP will be - 192.168.177.255

Host RangeTo find the host range, simply add 1 to the final octet of the subnet number and subtract 1 from the final octet of the broadcast address.

Host Range - 192.168.176.1 - 192.168.177.254

Total number of available Hosts – 2^ 9 = 512 (As remaining bits are used by subnet mask)

Subnet mask - 255.255.254.0
Wildcard mask - 0.0.1.255
Number od hosts - 2^9 - 512 hosts
So the starting will be 192.168.176.1 and ending will be 192.168.177.254

Practice Questions. 

1) Find the addresses in subnet 10.1.4.0/23.  

Subnet mask for the given address -  255.255.254.0
Magic number - 256 - 254 = 2 
Multiples of magic number - 2 - 0,2,4,6,8 -  In our case 4 is lesser r equal to the Interesting octet.
So subnet - 10.1.4.0 
Brodcast =  Magic number + Interseting octet = 4+2 -1 = 5. So broadcast IP is  10.1.5.255 

As you know first IP address is network address that is 10.1.4.0 and last address ( broadcast IP address 10.1.5.255) cant be assigned. So the usable IP address starting with 10.1.4.1 and ending with 10.1.5.254

2) A fellow engineer tells you to configure the DHCP server to lease the first 20 usable IP addresses in subnet 192.168.9.96/27.  Which of the following IP addresses could be leased as a result of your new configuration?

This is class C IP address only last part is host

Number of hosts - 2^5 =32
Subnet mask - 255.255.255.224
Magic number - 256-224 =32
Multiples of 32 = 32,64,96
96 is nearby to our IP so
First IP is 192.168.9.96  and
Brodcast = Magic number + Subnet Interesting number = 32+96 =128 = 128 -1 =127 
Brodcast IP address = 192.168.9.127

Usuable Host Range = 192.168.9.97 - 192.168.9.126

Subnet 192.168.9.96/27 has subnet mask as 255.255.255.224 so the IP address started from 192.168.9.96 and ending with 192.168..9.127 as you know first IP address is network address that is 192.168.9.96 and last address is broadcast IP address 192.168.9.127 and we cant assigned network and broadcast IP address so the usable IP address starting with 192.168.9.97 and ending with 192.168.9.126

Part 2 : How to create subnet's from the given IP addrss

Question : Create a VPC with CIDR 10.0.0.0/24 and we have to create 6 subnets. Let see how can we do that

The given IP 10.0.0.0 is Class A IP address so the default subnet mask is 255.0.0.0. Mask as per the CIDR block is 255.255.255.0

Total number of available Hosts – 2^ 8 = 512 (As remaining bits are used by subnet mask)

As per requirement we need 6 subnets for which we need 3 bits from hosts.

So the Subnet mask will be 10.0.0.0/27  (255.255.255.224)

Then to calculate Host range

Interesting octet in Mask - 224
Magic Number - 256 - 224 = 32
Multiples of 32, is 0, 32, 64
So Subnet number is 10.0.0.0
Brodcast = Interesting octet of subnet + Magic Number - 1 =31
Host Range = 10.0.0.1 - 10.0.0.30

Similaryly 2nd Subnet IP address wil be 10.0.0.32/27

So the 1st ip address of subnet will be 10.0.0.32 to 10.0.0.63


Similar Sample Questions

10.180.10.18, mask 255.192.0.0
10.200.10.18, mask 255.224.0.0
10.100.18.18, mask 255.240.0.0
10.100.18.18, mask 255.248.0.0
10.150.200.200, mask 255.252.0.0
10.150.200.200, mask 255.254.0.0
10.220.100.18, mask 255.255.0.0
10.220.100.18, mask 255.255.128.0
172.31.100.100, mask 255.255.192.0
172.31.100.100, mask 255.255.224.0
172.31.200.10, mask 255.255.240.0
172.31.200.10, mask 255.255.248.0
172.31.50.50, mask 255.255.252.0
172.31.50.50, mask 255.255.254.0
172.31.140.14, mask 255.255.255.0
172.31.140.14, mask 255.255.255.128
192.168.15.150, mask 255.255.255.192
192.168.15.150, mask 255.255.255.224
192.168.100.100, mask 255.255.255.240
192.168.100.100, mask 255.255.255.248
192.168.15.230, mask 255.255.255.252
10.1.1.1, mask 255.248.0.0
172.16.1.200, mask 255.255.240.0
172.16.0.200, mask 255.255.255.192
10.1.1.1, mask 255.0.0.0

Deciding How Many Subnet Bits to Use

The key decision in customized subnetting is how many bits to take from the host ID portion of the IP address to put into the subnet ID. Recall that the number of subnets possible on our network is two to the power of the number of bits we use to express the subnet ID, and the number of hosts possible per subnet is two to the power of the number of bits left in the host ID (less two, which I will explain later in this topic).

Thus, the decision of how many bits to use for each of the subnet ID and host ID represents a fundamental trade-off in subnet addressing:
of hosts that are possible within each subnet on the network.

How do we decide how to divide the “classful” host ID into subnet ID and host ID bits? This is the key design decision in subnetting. We must make this choice based on our requirements for the number of subnets that exist in the network, and also on the maximum number of hosts that need to be assigned to each subnet in the network. For example, suppose we have 10 total subnets for our Class B network. We need 4 bits to represent this, because 24 is 16 while 23 is only 8. This leaves 12 bits for the host ID, for a maximum of 4,094 hosts per subnet.

However, suppose instead that we have 20 subnets. If so, 4 bits for subnet ID won't suffice: we need 5 bits (25=32). This means in turn that we now have only 11 bits for the host ID, for a maximum of 2,046 hosts per subnet. Step #2 of the practical subnetting example discusses these decisions in more detail.

Now, what happens if we have 20 subnets and also need a maximum of 3,000 hosts per subnet? Well, we have a problem. We need 5 bits to express 20 different subnets. However, we need 12 bits to express the number 3,000 for the host ID. That's 17 bits—too many. The solution? We might be able to shuffle our physical networks so that we only have 16. If not, 
we need a second Class B network.

It's also important to realize that in regular subnetting, the choice of how many bits to use for the subnet ID is fixed for the entire network. You can't have subnets of different sizes—they must all be the same. Thus, the number of hosts in the largest subnet will dictate how many bits you need for the host ID. This means that in the case above, if you had a strange configuration where 19 subnets had only 100 hosts each but the 20th had 3,000, you'd have a problem. If this were the case, you could solve the problem easily by dividing that one oversized subnet into two or more smaller ones. An enhancement to subnetting called Variable Length Subnet Masking (VLSM) was created in large part to remove this restriction.
IP Custom Subnet Masks


Key Concept: Once the choice of how to subnet has been made, the custom subnet mask is determined simply, by starting with the default subnet mask for the network and changing each subnet ID bit from a 0 to a 1.
Subtracting Two From the Number of Hosts Per Subnet and (Possibly) Subnets Per Network


There's one more issue that needs to be explained regarding the split into subnet ID and host ID. We've already seen how in regular “classful” addressing, we must subtract 2 from the number of hosts allowed in each network. This is necessary because two host IDs in each subnet have “special meanings”: the all-zeroes host ID meaning “this network”, and the all-ones host ID which is a broadcast to “all hosts on the network”. These restrictions apply also to each subnet under subnetting too, which is why we must continue to subtract 2 from the number of hosts per subnet. (This is also why dividing the 8 host ID bits of a Class C network into 7 bits for subnet ID and 1 bit for host ID is not just silly, but in fact meaningless: it leaves 21-2=0 hosts per subnet. Not particularly useful.)


http://www.tcpipguide.com/free/t_IPDefaultSubnetMasksForAddressClassesABandC.htm

Sample Answers
1. 10.180.10.18, mask 255.192.0.0
---- Subnet Number - 10.128.0.0
---- Broadcast Address - 10.191.255.255
---- Host Range - 10.128.0.1 - 10.191.255.2542. 10.200.10.18, mask 255.224.0.0
---- Subnet Number - 10.192.0.0
---- Broadcast Address - 10.223.255.255
---- Host Range - 10.192.0.1 - 10.223.255.254
Which two statements describe the IP address 10.16.3.65/23?
Using above example let us find the starting and ending ip of above CIDR block
IP - 10.16.3.65
Subnet - 255.255.254.0
Wildcard Mask - 0.0.1.255
Innocent octet - 254
To find subnet number - 256-254 = 2 (this 2 is called as magic number)
So multiples of 2 is 0,2, 4,6 ,8,10
We need to take the number which is lesser and closer to our IP address. Our IP address is 3 and closer number is 2
so the subnet will be 10.16.2.0/23
to find the brodcast IP address add the interesting octet in our case it is 2
if the ip is like 172.21.80.0 then intersting octet is 80.

so Intersting octet + magic number = 2+2 =4 =3
so 10.16.3.255 is the brodcast ip address

No comments:

Post a Comment