Monday, January 2, 2012

IPv4 Subnetting

IP subnetting is one of the core skills that good network engineers should master.  However, being able to subnet the Internet Protocol isn’t a skill exclusively reserved for network engineers.  Many different types of technologists could benefit from understanding how IP addressing and subnetting works.
Before we get into subnetting IP networks, let’s first discuss what IP addressing is, how it works and its architecture.

The Address

An Internet Protocol (IP) address is a logical address of a host that must be unique on the network.  Many technical writers liken the IP address to a street address.  Each house on the street must have a unique address.  Otherwise, the mail could possibly (and likely) be consistently delivered to the wrong house.  The same does indeed hold true for an IP address.  It must be unique, otherwise, the router(s) will not know to which host to deliver the packet of information.
An IP address is a 32 bit number represented in a dotted decimal format.  The 32 bits are divided into four separate octets.  The eight positions in each octet are given a number value based on a power of two.  It is very similar to the traditional numbering system that is based on 10.  In Table 1 below, the traditional numbering system and the place values are shown.
Table 1
107
106
105
104
103
102
101
100
10,000,000's
1,000,000's
100,000's
10,000's
1,000's
100's
10's
1's

So, the number 1275 would have one instance of 103, two instances of 102, seven instances of 101 and 5 instances of 100.
The binary system, shown below in Table 2, works in the same way.  It is simply based on two rather than 10.
Table 2
27
26
25
24
23
22
21
20
128
64
32
16
8
4
2
1

As you can see from the number positions and their values, the highest numerical value within each octet is 255.  Therefore, you have 256 possible values.  Don’t forget about zero!  0-255 gives you 256 numbers.  The number in each octet is derived from the placement of a 1 or 0 in each of the binary positions.  The typical descriptions I have read describe 1 as the “I care” bit and the 0 as the “I don’t care” bit.  So, the 1 indicates an instance of that value and a 0 indicates no instance of that value.  To get the number displayed, you simply add the values with a 1 in their position and the sum is the value.
Let’s take a look at a binary representation of a number.  Table 3 below represents the number 153:
Table 3
128
64
32
16
8
4
2
1
1
0
0
1
1
0
0
1

If take a look at the value positions with a 1 and add them, you get:
128+16+8+1 = 153
Each octet work in the exact same way when arriving at the IP address.

The Classes

IP addresses are divided into five classes.  The classes are A, B, C, D and E.  The classes are defined by the placement of 1’s and 0’s in the first few bits of the address.
Class A has a “0” in the first bit of the first octet.  So, Class A addresses range from 0-126 in the first octet.  Note: 127.0.0.0 – 127.255.255.255 is reserved for loopback addresses.
Class B has a “10” in the first two bits of the first octet.  This would put class B’s range from 128-191 in the first octet.
Class C has “110” in the first three bits of the first octet.  This makes the range of class C addresses 192-223 in the first octet.
Class D has “1110” in the first four bits of the first octet.  The range of class D addresses would be 224.0.0.0 – 239.255.255.255.  Class D addresses are used for multicast traffic.  There are many applications and protocols that effectively utilize multicast.  Many routing protocols use it for forming adjacencies and sending updates. 
Class E has “11110” in the first five bits of the first octet.  Class E addresses are not in IP networks.  The term typically used for the use of class E addressing is “experimental.” 

The Network

Subnetting IP networks is very similar, but it is just different enough that the result is often confusion.  Within an IP address are two different parts.  There is a network portion and a host portion.  The subnet mask will have a number of contiguous 1’s that represent the network portion of the address.  The mask must be contiguous 1’s.  If mask was not contiguous, it could be ambiguous (Too many …uous words?) and the “/” notation wouldn’t work.  With IP, the more subnets you have, the fewer hosts you will have per network.  The inverse is also true.  The fewer networks you have, the more hosts you have per network.  You will often see an IP address coupled with a subnet mask.
1)      192.168.100.10   255.255.255.0
2)      192.168.100.10   /24
The first line is the traditional representation of the IP address with the subnet mask represented in dotted decimal notation.  The second line has the subnet mask represented as the number of bits in the mask.  This would make the network portion of the address the first 24 bits and host portion the last eight bits.  The network portion of the address is: 192.168.100.  The host portion is .10.  So, this network would be 192.168.100.0.  The broadcast address, being all ones in the host portion, would be 192.168.100.255.
In an IP subnet, the formula for the number of hosts in the subnet is 2n-2, where “n” is the number of hosts bits.  You subtract the two because you typically do not use the network address as a host address and you can’t use the broadcast address.  So, if you have a /24 network there are eight hosts bits.  Using the formula, 28-2, you get 254 possible host addresses.
Now, to make it a little tricky.  What happens if you take away a bit from the network portion and give it to the host portion?  The IP address doesn’t change, but the subnet mask does.  It turns into 192.168.100.10  255.255.254.0.  That is a /23 subnet mask.  How many hosts do you think would be in each subnet?  Let’s use our formula and see what we get.  29-2=510. Let’s move that subnet mask bit in the other direction and see what happens.  Let’s take away a host bit and give it to the network.  That would make our IP address and mask 192.168.100.10  255.255.255.128.  This is a /25 subnet mask.  Using our formula, 27-2, we get 126 possible hosts per subnet. 

RFC 1918

There are some networks that are not allowed to be routed on the Internet.  These network address ranges are defined in RFC 1918.  These are, by far, the most utilized IP addresses on private IP networks.  These networks are as follows:
1)      10.0.0.0 /8
2)      172.16.0.0 /12
3)      192.168.0.0 /16
Since these addresses are not allowed on the Internet and most companies use them, you must perform a function called Network Address Translation (NAT) in order to translate those addresses into something the Internet will route.  NAT may be a little out of the scope of this instance of the blog, but I wanted to plant the seed.

That is pretty much the meat of IPv4 subnetting.  If there are questions, please leave a comment and I would be happy to field them as best I can.

Happy Computing!!

No comments:

Post a Comment