Understanding Address spaces and subnetting in IPv4 [Tutorial] | Packt Hub

13

min read

In any network, Internet Protocol (IP) addressing is needed to ensure that data is sent to the correct recipient or device. Both IPv4 and IPv6 address schemes are managed by the Internet Assigned Numbers Authority (IANA). Most of the internet that we know today is based on the IPv4 addressing scheme and is still the predominant method of communication on both the internet and private networks.

This tutorial is an excerpt from a book written by Glen D. Singh, Rishi Latchmepersad titled CompTIA Network+ Certification Guide.

This book is a practical certification guide that covers all CompTIA certification exam topics in an easy-to-understand manner along with self-assessment scenarios for better preparation.

Public IPv4 addresses

There are two main IPv4 address spaces—the public address space and the private address space. The primary difference between both address spaces is that the public IPv4 addresses are routable on the internet, which means that any device that requires communication to other devices on the internet will need to be assigned a public IPv4 address on its interface, which is connected to the internet.

The public address space is divided into five classes:

Class A
0.0.0.0 – 126.255.255.255

Class B
128.0.0.0 – 191.255.255.255

Class C
192.0.0.0 – 223.255.255.255

Class D
224.0.0.0 – 239.255.255.255

Class E
240.0.0.0 – 255.255.255.255

Class D addresses are used for multicast traffic. These addresses are not assignable. Class E addresses are reserved for experimental usage and are not assignable.

On the internet, classes A, B, and C are commonly used on devices that are directly connected to the internet, such as layer 3 switches, routers, firewalls, servers, and any other network-related device. As mentioned earlier, there are approximately four billion public IPv4 addresses. However, in a lot of organizations and homes, only one public IPv4 address is assigned to the router or modem’s publicly facing interface. The following diagram shows how a public IP address is seen by internet users:

So, what about the devices that require internet access from within the organization or home? There may be a few devices to hundreds or even thousands of devices that require an internet connection and an IP address to communicate to the internet from within a company. If ISPs give their customers a single public IPv4 address on their modem or router, how can this single public IPv4 address serve more than one device from within the organization or home?

The internet gateway or router is usually configured with Network Addresses Translation (NAT), which is the method of mapping either a group of IP addresses or a single IP address on the internet-facing interface to the local area network (LAN). For any devices that are behind the internet gateway that want to communicate with another device on the internet, NAT will translate the sender’s source IP address to the public IPv4 address. Therefore, all of the devices on the internet will see the public IPv4 address and not the sender’s actual IP address.

Private IPv4 addresses

As defined by RFC 1918, there are three classes of private IPv4 address that are allocated for private use only. This means within a private network such as LAN. The benefit of using the private address space (RFC 1918) is that the classes are not unique to any particular organization or group. They can be used within an organization or a private network. However, on the internet, the public IPv4 address is unique to a device. This means that if a device is directly connected to the internet with a private IPv4 address, there will be no network connectivity to devices on the internet. Most ISPs usually have a filter to prevent any private addresses (RFC 1918) from entering their network.

The private address space is divided into three classes:

Class A—10.0.0.0/8 network block
10.0.0.0 – 010.255.255.255

Class B—172.16.0.0/12 network block
172.16.0.0 – 172.31.255.255

Class C—192.168.0.0/16 network block
192.168.0.0 – 192.168.255.255

Subnetting in IPv4

What is subnetting and why do we need to subnet a network?
First, subnetting is the process of breaking down a single IP address block into smaller subnetworks (subnets). Second, the reason we need to subnet is to efficiently distribute IP addresses with the result of less wastage. This brings us to other questions, such as why do we need to break down a single IP address block, and why is least wastage so important? Could we simply assign a Class A, B, or C address block to a network of any size? To answer these questions, we will go more in depth with this topic by using practical examples and scenarios.

Let’s assume that you are a network administrator at a local company and one day the IT manager assigns a new task to you. The task is to redesign the IP scheme of the company. He has also told you to use an address class that is suitable for the company’s size and to ensure that there is minimal wastage of IP addresses.

The first thing you decided to do was draw a high-level network diagram indicating each branch, which shows the number of hosts per branch office and the Wide Area Network (WAN) links between each branch router:

Network diagram

As we can see from the preceding diagram, each building has a branch router, and each router is connected to another using a WAN link. Each branch location has a different number of host devices that requires an IP address for network communication.

Step 1 – determining an appropriate class of address and why

The subnet mask can tell us a lot about a network, such as the following:

  • The network and host portion of an IP address
  • The number of hosts within a network

If we use a network block from either of the address classes, we will get the following available hosts:

As you may remember, the network portion of an address is represented by 1s in the subnet mask, while the 0s represent the host portion. We can use the following formula to calculate the total number of IP addresses within a subnet by the known the amount of host bits in the subnet mask.

Using the formula 2H, where H represents the host bit, we get the following results:

  • Class A = 224 = 16,777,216 total IPs
  • Class B = 216 = 65,536 total IPs
  • Class C = 28 = 256 total IPs

In IPv4, there are two IPs that cannot be assigned to any devices. These are the Network ID and the Broadcast IP address. Therefore, you need to subtract two addresses from the total IP formula.

Using the formula 2H-2 to calculate usable IPs, we get the following:

  • Class A = 224 – 2 = 16,777,214 total IPs
  • Class B = 216 – 2 = 65,534 total IPs
  • Class C = 28 – 2 = 254 total IPs

Looking back at Network diagram, we can identify the following seven networks:

  • Branch A LAN: 25 hosts
  • Branch B LAN: 15 hosts
  • Branch C LAN: 28 hosts
  • Branch D LAN: 26 hosts
  • WAN R1-R2: 2 IPs are needed
  • WAN R2-R3: 2 IPs are needed
  • WAN R3-R4: 2 IPs are needed

Determining the appropriate address class depends on the largest network and the number of networks needed. Currently, the largest network is Branch C, which has 28 host devices that needs an IP address. We can use the smallest available class, which is any Class C address because it will be able to support the largest network we have. However, to do this, we need to choose a Class C address block. Let’s use the 192.168.1.0/24 block.

Remember, the subnet mask is used to identify the network portion of the address. This also means that we are unable to modify the network portion of the IP address when we are subnetting, but we can modify the host portion:

The first 24-bits represent the network portion and the remaining 8-bits represent the host portion. Using the formula 2H – 2 to calculate the number of usable host IPs, we get the following:

2H – 2
28 – 2 = 256 – 2 = 254 usable IP addresses

Assigning this single network block to either of the seven networks, there will be a lot of IP addresses being wasted. Therefore, we need to apply our subnetting techniques to this Class C address block.

Step 2 – creating subnets (subnetworks)

To create more subnets or subnetworks, we need to borrow bits on the host portion of the network. The formula 2N is used to calculate the number of subnets, where N is the number of bits borrowed on the host portion. Once these bits are borrowed, they will become part of the network portion and a new subnet mask will be presented.

So far, we have a Network ID of 192.168.1.0/24. We need to get seven subnets, and each subnet should be able to fit our largest network (which is Branch C—28 hosts).

Let’s create our subnets. Remember that we need to borrow bits on the host portion, starting where the 1s end in the subnet mask. Let’s borrow two host bits and apply them to our formula to determine whether we are able to get the seven subnets:

When bits are borrowed on the host portion, the bits are changed to 1s in the subnet mask. This produces a new subnet mask for all of the subnets that have been created.

Let’s use our formula for calculating the number of networks:

Number of Networks = 2N
22 = 2 x 2 = 4 networks

As we can see, two host bits are not enough as we need at least seven networks. Let’s borrow one more host bit:

Once again, let’s use our formula for calculating the number of networks:

Number of Networks = 2N
23 = 2 x 2 x 2 = 8 networks

Using 3 host bits, we are able to get a total of 8 subnets. In this situation, we have one additional network, and this additional network can be placed aside for future use if there’s an additional branch in the future.

Since we borrowed 3 bits, we have 5 host bits remaining. Let’s use our formula for calculating usable IP addresses:

Usable IP addresses = 2H – 2
25 – 2 = 32 – 2 = 30 usable IPs

This means that each of the 8 subnets will have a total of 32 IP addresses, with 30 usable IP addresses inclusive. Now we have a perfect match. Let’s work out our 8 new subnets.

The guidelines we must follow at this point are as follows:

  • We cannot modify the network portion of the address (red)
  • We cannot modify the host portion of the address (black)
  • We can only modify the bits that we borrowed (green)

Starting with the Network ID, we get the following eight subnets:

We can’t forget about the subnet mask:

As we can see, there are twenty-seven 1s in the subnet mask, which gives us 255.255.255.224 or /27 as the new subnet mask for all eight subnets we’ve just created.

Take a look at each of the subnets. They all have a fixed increment of 32. A quick method to calculate the incremental size is to use the formula 2x. This assists in working out the decimal notation of each subnet much easier than calculating the binary. The last network in any subnet always ends with the customized ending of the new subnet mask. From our example, the new subnet mask 255.255.255.224 ends with 224, and the last subnet also ends with the same value, 192.168.1.224.

Step 3 – assigning each network an appropriate subnet and calculating the ranges

To determine the first usable IP address within a subnet, the first bit from the right must be 1. To determine the last usable IP address within a subnet all of the host bits except the first bit from the right should all be 1s. The broadcast IP of any subnet is when all of the host bits are 1s.

Let’s take a look at the first subnet. We will assign subnet 1 to the Branch A LAN:

The second subnet will be allocated to the Branch B LAN:

The third subnet will be allocated to the Branch C LAN:

The fourth subnet will be allocated to Branch D LAN:

At this point, we have successfully allocated subnets 1 to 4 to each of the branch’s LANs. During our initial calculation for determining the size of each subnet, we saw that each of the eight subnets are equal, and that we have 32 total IPs with 30 usable IP addresses. Currently, we have subnets 5 to 8 for allocation, but if we allocate subnet 5, 6 and 7 to the WAN links between the branches R1-R2, R2-R3 and R3-R4, we would be wasting 28 IP addresses since each WAN link (point-to-point) only requires 2 IP addresses.

What if we can take one of our existing subnets and create even more but smaller networks to fit each WAN (point-to-point) link? We can do this with a process known as Variable Length Subnet Masking (VLSM). By using this process, we are subnetting a subnet.

For now, we will place aside subnets 5, 6, and 7 as a future reservation for any future branches:

Step 4 – VLSM and subnetting a subnet

For the WAN links, we need at least three subnets. Each must have a minimum of two usable IP addresses. To get started, let’s use the following formula to determine the number of host bits that are needed so that we have at least two usable IP addresses: 2H – 2, where H is the number of host bits.

We are going to use one bit, 21 – 2 = 2 – 2 = 0 usable IP addresses. Let’s add an extra host bit in our formula, that is, 22 – 2 = 4 – 2 = 2 usable IP addresses. At this point, we have a perfect match, and we know that only two host bits are needed to give us our WAN (point-to-point) links.

We are going to use the following guidelines:

  • We cannot modify the network portion of the address (red)
  • Since we know that the two host bits are needed to represent two usable IP addresses, we can lock it into place (purple)
  • The bit between the network portion (red) and the locked-in host bits (purple) will be the new network bits (black)

  • To calculate the number of networks, we can use 2N = 23 = 8 networks. Even though we got a lot more networks than we actually needed, the remainder of the networks can be set aside for future use.
  • To calculate the total IPs and increment, we can use 2H = 22 = 4 total IP addresses (inclusive of the Network ID and Broadcast IP addresses).
  • To calculate the number of usable IP addresses, we can use 2H – 2 = 22 – 2 = 2 usable IP addresses per network.

Let’s work out our eight new subnets for any existing and future WAN (point-to-point) links:

Now that we have eight new subnets, let’s allocate them accordingly.

The first subnet will be allocated to WAN 1, R1-R2:

The second subnet will be allocated to WAN 2, R2-R3:

The third subnet will be allocated to WAN 3, R3-R4:

Now that we have allocated the first three subnets to each of the WAN links, the following remaining subnets can be set aside for any future branches which may need another WAN link. These will be assigned for future reservation:

Summary

In this tutorial, we understood public and private IPV4 addresses. We also learned the importance of having a subnet and saw the 4 simple steps needed to complete the subnetting process.

To learn from industry experts and implement their practices to resolve complex IT issues and effectively pass and achieve this certification, check out our book CompTIA Network+ Certification Guide.

Read Next

AWS announces more flexibility its Certification Exams, drops its exam prerequisites

Top 10 IT certifications for cloud and networking professionals in 2018

What matters on an engineering resume? Hacker Rank report says skills, not certifications