Flashback - Learn IP Addressing!

 


Today I am writing for my nephews and babies who are starting their journey to networking world. There will be multiple articles on basics. This one is on IP Addressing.

Yes, all my brother who just want to go to the flashback can also read this article. 

IPv4 Addresses

IPv4 addresses are 32 bits long (mean 32 0s or 1s), divided into two parts network address and the host address. The network portion identifies a physical links and is same for all the hosts connected to that physical network. The host portion identifies a particular device only.

An IPv4 Address can be represented in different formats –

Bits format –

00001010110101100101011110000011

Decimal format –

181819267

Both the representation above are hard to remember and calculate. Therefore a doted decimal representation developed and used by network engineers throughout the networking journey (don’t be surprised router sees and works only with binary format only 😊)

With doted decimal format, above 32-bit address is divided into 4 parts, each part is called the octets which is 8-bits long or 1-byte long. With doted decimal format, lets perform the first step –

00001010.11010110.01010111.10000011

And now convert the same to decimal format –

00001010.11010110.01010111.10000011

10.214.87.131

Points to remember – a possible value in each octets can be between 0 – 255 (with all bits set to 1 will result 255 and all bits set to 0 will result 0)

An important factor of IPv4 addressing is that it allows you to perform more calculations compared to other network layer protocols such as NetWare and AppleTalk there we have fixed network and host portion – this certainly makes life simple. In IPv4 the calculation is required to conserve the IP address for a network – I mean when we have small number of users in a network, there is no need to have 1000s of devices in that network. With the help of subnetting we’ll see how effectively we can design our IP addressing schema for network without wasting IPs.

IPv4 Addressing was designed for all types of network – small, medium and large. Wait a minute what is definition of small, medium or large I mean how many hosts can be there in each class of network. Ok that is governed by “First Octet Rule” which we are going to see next.

First Octet Rule

There a in general three types sizes of network as measured by the number of hosts – big, small and medium;

Big networks have a large number of hosts and less number of large networks

Small network are just opposite to big networks with less number of hosts and more number of small networks

Medium network has medium number of networks and medium number of hosts in each network

Now this high-level of networks require three types of classes of network addresses. Big network addresses should be capable to host many hosts and few network addresses are required. This situation is opposite for small network, as there are many small networks, a large number of small-network addresses are needed, because small network has small number of hosts, each of the network address require few hosts to address.

Address Class

These three types of address format can be represented as follows


Figure 1- Class A, B and C Address Format

The big, medium and small networks are mapped to these address classes.

Class A IPv4 Addresses are for big networks. In class A address, first octet is the network portion and the next three octets are the host portion. If we do a simple math only 256 numbers are available for network part. However a huge number of hosts can exist in each network – 224 or 16,777216 hosts.

Class B IPv4 Addresses are for medium networks. In class B address, first two octets are for the network portion and the next two octets are for the host portion. In class B address there are 216 or 65,536 networks and hosts in each network.

Class C IPv4 Address are for small networks. In Class B address, first three octets are for the network position and the next 1 octet is for the host portion.

As all the IPv4 address are 32 bits long and can have any value between 0 and 255 how can one recognize whether an address is class A, B, or C IP address? There comes the 1st octet rule in picture. According to this rule –

1.      For class A address, the first bit of 1st Octet (left most) is always 0. With this rule the class A IP address can starts with any value between 0 and 127; IP address starting with 0 is reserved for default address and 127 is reserved for internal loopback address. This leaves a Class A valid IP address first octet is between 1 and 126.

2.      For class B address, the first 2 bits are set as “10”. With binary to decimal conversion formula it is clear the first octet for class B address falls between the 128 and 191.

3.      For class C address the first two bits are set to 1 and third bit is set to zero. The result is, the first octet range is between 192 – 223.

Address Mask

Looking at the IP address we cannot findout what portion identifies the network address and the host address. To solve this puzzle, address mask is used. The address mask is a 32 bit text where one bit for each bit of the IPv4 address. It is also represented in dotted decimal format same as the IPv4 address. It is to remember address mask looks like the IP address but it is not the one. There are standard subnet mask for each class of IPv4 Address –

Figure 2: Standard Address Masks

For each bit of IPv4 address, the device under the hood performs the Boolean AND function with the corresponding bit of the address mask. The AND function – compare two bits and derive a result. The result will be one if and only if, both bits are one. If either or both bits are zero, the result will be zero.

Ahh let’s try to understand the same with example,

Figure 3: AND Operator

Figure 4: Deriving NW Address using AND Operator

As per the figure 4, a logical AND is performed on the IPv4 address and it’s address mask for every bit; the result is the 172.21.0.0 which is the network address for the host 172.21.35.17 with address mask 255.255.0.0.

Why Subnetting?

There can be multiple locations in a network and each location needs to be logically identified so that traffic from one side can reach to other side. This on a very high level is called the routing function. Each network should be unique – also each host on the network must have an address that identifies it uniquely in the network and it’s network from other networks.

Can’t we use standard subnet mask?

Probably can be used (in a lab environment) but in real-life scenario, a single class A, B, or C address can be used only on a single data link.

Figure 5: NW with default Subnet Masks

The problem with above network is scalability, with default subnet mask and addressing the size of the network will be limited and unnecessary there will be wastage of the host IP addresses. Consider the Data Link 2 in Figure 5 is a point-to-point link (effectively I need 2 IPs here) but as the default subnet and addressing is used, there are 65,000 devices can reside wasting 64,998 address.

The only way to make IP address practical in real network, it is necessary to perform the subnet where a big or major network is divided into sub-networks addresses.

Let’s try to understand the same by simple example, look at the below network architecture where 172.21.0.0 is divided into subnetworks –

Figure 6 - Subnetworks - using single network address across multiple links

You must have noticed that the subnet mask is not the standard class B subnet mask with 16-bit reserved for network address. Instead, we have borrowed additional 8 bits from the host portion of the address – so now we have 24-bits to represent the network address. This resulted that the major network 172.21.0.0 has been divided into subnetworks and each datalink has been addressed instead of wasting the IP addresses using the major network address across the datalinks.

Now after subnetting there are 3 part of the IPv4 Address – network, subnet, and the host part. The address mask is now called – subnet mask. First two octets are the major network (172.21.x.x) and will remain unchanged. However, the 3rd octet is subnet bits instead of host bit. I range from 0 to 255.

Just a point to remember, not all routing protocols (classful routing protocol) can understand the subnet address where all subnet-bits are 0 or all subnet-bits are 1. For example – 172.21.0.0/24 and 172.21.255.0/24. It is because they are not able to differentiate 172.21.0.0 which is major subnet address or the first subnetwork 172.21.0.0. In this case both are same. Likewise, 172.21.255.0 – it is major network broadcast address and at the same time last subnetwork . IGRP and RIPv1 are classful routing protocols that don’t allow to use all-ones and all-zero subnets in a network. On the other hand, classless routing protocol such as EIRP, OSPF etc. understand the differentiator – as the subnet mask information is communicated in the routing updates.

Sometimes we also get confused with the verbal communication of the subnet during our day to day troubleshooting or support tasks. So what is the correct way to communicate a piece of information when subnetting is used as we have done in above feature. It means “Class B address with 8-bits of Subnetting” or “Class B address with 24-bits mask”. I hope it is clear now.

A subnet mask can be represented in the dotted decimal format – 255.255.255.0; in bits count format 172.21.1.0/24; or in Hexadecimal format 0xFFFFFF00.

Designing a IP Addressing for a network

As it is already mentioned that all-zero subnet-bits and the all-ones subnet-bits are not understood by classful routing protocols, likewise, all-zero host address and all-ones host address are reserved in IPv4 networking. Router use all-zero host address as – subnet address and all-ones host address as – broadcast address i.e. 172.21.1.0/24 is the subnet address and 172.21.1.255/24 is the broadcast address in subnet 172.21.1.0/24.

When you have been assigned a task to build a network and designed the IP schema you have to go through the series of steps to successfully come out as an architect –

Step 1 – Determine how many subnets and how many hosts per subnets required

Step 2 – Use 2n – 2 formula to determine the number of subnet bits and the number of hosts bits that will satisfy the requirement established in step 1. If multiple subnet masks meet the requirement, choose one that will best scale to future need.

Step 3 – working in binary, determine all available bit combinations in the subnet space; in each instance, set all the host bits to zero. Convert the resulting subnet address to dotted decimal. These are the subnet addresses.

Step 4 – for each subnet address, again working in binary, all possible bit combinations for the host space without changing the subnet bits. Convert the result to doted decimal; these are the host addresses available for each subnet.

Let’s work in a real scenario and try to design the IP Addressing for a customer. This customer need IP design for 500 remote locations and each location has around 100 hosts.

Step 1 – using the 9 bits for subnet can meet the requirement - 29 - 2 = 510 (locations considering the scalability into mind); if we use 8 bits for subnets than the requirement cannot be met as it will give only 254 subnets only.

Let’s work on the below network setup where we do need 5 subnets for each data-link in the topology –

Figure 7: Network with 5 Datalinks and mini. 25 IP host

Network 192.168.100.0 to be divided in such as way that provide at least 5 subnet addresses. The maximum host addresses are 25 for two LAN subnets. Therefore full IP Addressing design require 5 subnets with each minimum 25 host addresses.

Applying 2n -2 formula, three subnet bits and five host bits will satisfy the requirement : 23 – 2 = 6 and 25 – 2 = 30. A class C subnet mask with 3 bits of subnetting is represented as 255.255.255.224 in the dotted decimal format.

Figure 8: Network, Subnet Bits & Host bits - Subnet Addresses

 In above figure, subnet bits are abstracted and then writing all the possible bit combinations in the space by counting up from zero in the binary – 0, 1, 2, 3 and so on. These are the subnet addresses that will be assigned to datalinks.

Figure 9: Calculating the Subnet Address counting up Subnet Bits  from 0 in binary

Last step to calculate the host addresses available to each subnet. This step is performed by choosing the subnet mask and keeping the network & Subnet bits unchanged, writing all bit combinations in the host space by counting up from zero in binary. Let’s take an example for 192.168.100.32 subnet –  

Figure 10: Calculating the host address counting up host bits from 0 in binary

Note – the first address, in which all the host bits are zero, is the subnet address – that’s the reason it cannot be assigned to host. Another address is the last address where all the host bits are 1, this is the broadcast address in the subnet that represent to all hosts in the subnet. This is also not assigned to host. In any subnet the usable IPs are – 2n – 2; 25 - 2 = 30.

With is I take a halt, the only way to mastery the IP Addressing is to practice. A homework for you to calculate valid host for –

·        Class C IP addresses with 4 Subnet bits

·        Class C IP address with 5 Subnet Bits

Find out subnet broadcasts and network addresses as well. Happy Learning!