What is IPv4?
IPv4 is the main protocol used by the internet. It is the fourth version of the protocol, which started to be used in the 1980s. There is a newer version of the protocol, IPv6, but at the time of making this video, IPv4 was still the most widely used protocol on the internet.
Earlier versions of the protocol were considered developmental and experimental and were never adopted. Thus, the first version used on a production network was version 4. IPv4 uses a 32-bit address. Due to the way IPv4 addresses are implemented, there are under 3.7 billion usable public addresses.
This may seem like a lot, but when you consider the number of devices each person owns—such as home, work, and mobile devices—it becomes clear that the demand for IP addresses has increased. Thanks to technologies that allow a single IP address to be shared among multiple devices, we have managed to significantly extend the usability of available IP addresses despite the ongoing shortage. Now, let’s take a closer look at what an IP address really is.
What is an IP Address?
An IP address is essentially a location on the internet. Every device that connects to the internet needs an IP address. Think of it like a home mailing address—just as a mailing address helps a postal worker deliver your mail to the right house, an IP address lets other devices on the internet send data directly to your device. It also helps routers figure out where to send network traffic so it reaches you.
A physical house can have many people living at the same address who all receive mail for that address. IP addresses can work the same way. Multiple devices can be at the same location and share the same public IP address. More on that in a later video. However, for this video, let’s look at what makes up an IP address.
IP Address
Each IP address is 32-bit. In its raw form, it is 32 ones and zeros. This is simple for computers to read but very hard for humans to read. To make this easier to read, we divide the IP address into four 8-bit parts. Each part is called an octet.
Even divided up into binary form, it is hard for us humans to read. To make them easier to read, the IP address is written as numbers separated by periods. This makes it easier for us to work with.
The IP address, however, can be further divided. Let’s have a look.
Subnet Mask and Network ID/Host ID
A single IP address is encoded with two pieces of information. This information is divided up using the subnet mask into the network ID and the host ID. The subnet mask essentially determines how many bits are used for each of those.
The subnet mask essentially splits an IP address into two parts. If you move the subnet mask to the left, your network will support more hosts. If you move it to the right, you get more networks. Let’s have a closer look at how it works.
Subnet Mask
The subnet mask is an unbroken sequence of 1’s followed by 0’s. Once again, representing this using binary is difficult for us to work with. To make it easier to work with, you can use slash notation. Slash notation is essentially the slash followed by the number of bits. So given the first example, there are 24 consecutive bits, thus it would be slash 24.
Slash notation is the new standard and is easy to understand, which is why I started with it first. The other standard is dotted decimal. This is the older standard and is a little harder to work with. In our example, the subnet mask would be 255.255.255.0.
When working with subnet masks, you will notice that the dotted decimal format is easier to work with when the subnet mask ends on an 8-bit boundary, as it simplifies the calculations. For example, 24, which was the first one I looked at. 16 or 8.
You will notice that when these subnet masks are used, all the digits are 255 or zero. However, it is not always possible to use these subnet masks. For example, you may need to use slash 25. This would give you a subnet mask of 255.255.255.128. If I change the subnet mask to slash 26, this would make the subnet mask 255.255.255.192.
You will notice that slash notation is a bit easier to work with than dotted decimal. You will often find that network maps and routing will use slash notation. When configuring a network card, it will often use dotted decimal notation. For this reason, you should understand both.
Let’s now have a look at how to use the subnet mask to perform subnetting.
Subnetting 192.168.0.0/24
A lot of new technicians, when they first learn subnetting, have trouble understanding the concept. Some people find it easier to consider a pie, and subnetting is like dividing the pie up into smaller pieces. For the A+ exam, you most likely won’t get any questions about subnetting addresses. You may get a question where a computer is configured with an incorrect subnet, and you need to correct it. If you go on to study for Network+, you will need to understand subnetting.
In this example, I have been given the network address of 192.168.0.0/24. When you start subnetting, part of your decision of how many bits you use will be based on how many networks and hosts you will get. When working out the hosts, there are two things that you need to consider.
For the number of bits in the subnet, I have used the notation CIDR. CIDR stands for Classless Inter-Domain Routing. In the early days of IP addresses, they were divided up into classes. In the next video, I will look at IP address classes. You don’t see classful addresses mentioned that much nowadays, as CIDR, as the name suggests, removes it. You will see it mentioned sometimes.
If the host ID is all zeros, it cannot be used. This is known as the network ID; it identifies the network the hosts are using. If the host ID is all ones, it is a broadcast. A broadcast message goes to all hosts on the network. Don’t worry if you don’t understand this so far; I will go through another example of it.
To work out the number of usable hosts, raise 2 to the power of the number of bits used for hosts and subtract 2. So the network that I have been given has 24 bits allocated to the network side, which leaves 8 bits for the hosts. Two to the power of eight is 256. Taking two from this leaves 254 hosts.
If we want to create more networks, that is, divide our pie into more slices, we can allocate 25 bits to the network IDs. When we do this, we increase the number of networks to 2 and reduce the number of hosts to 126.
If we keep increasing the number of bits used for the network ID, this will reduce the number of usable hosts. Thus, subnetting is always a trade-off between how many networks you want and how many usable hosts are on that network. Let’s work through an example so we can understand the process better.
Subnetting Example
In this example, I have been given the subnet 192.168.0.0/24. Later in the video I will look at more examples, so don’t worry if you don’t fully understand. For this example network I will subdivide this into smaller networks. This subnet needs to be divided up into an office area containing 90 devices, a warehouse of 20 devices, and a factory of 10 devices.
When subnetting, I find it helpful to have a power-of-2 table to reference. This table shows the result when 2 is raised to different powers. It is useful to reference this table when subnetting.
To start with, I will work out the subnet for the office network. The network has 90 devices; so the subnet needs to support at least 90 devices. Consulting my powers-of-2 table, I will find the lowest number over 90. 2 to the power of 7 gives 128. Keep in mind I have to remove the network ID and the broadcast ID. This gives me 126 usable hosts, or in other words, the network has 126 unique IP addresses. We only need 90 devices, so this gives us 36 unused IP addresses.
The next step is to work out the range. The first IP address will be 192.168.0.0. There are 128 addresses in the range. Keep in mind that we are also counting the first address ending in zero. This makes the last address 192.168.0.127.
Now that we have the range, we can easily work out the network ID and broadcast address. The network ID will be the first IP address in the range. The broadcast address will be the last IP address in the range.
The last part is to work out the CIDR. This will be the network ID. To work out the number of bits used in the subnet mask, we need to work the gap between the value 24 and the number of bits that we used. The total number of bits is 32, so we need to subtract 24 for the number of bits and also subtract 7. We got 7 from the power-of-2 table. This leaves us 1. The value will be 24 + 1, which gives us 25.
I will now move on to the warehouse network. The network ID for the warehouse will be the first IP address of its subnet. This is determined by taking the next available IP address after the last IP address of the office network. The last IP address of the office network is 192.168.0.127. To calculate the network ID for the warehouse, we simply add one to the last IP address of the office network, resulting in a network ID of 192.168.0.128.
The next step is to work out the last IP address on the network. To do that, we need to work out how many bits we will need. So, once again, I will go to my powers-of-2 table. I have 20 devices on my network, so I will need to go down to 5, which gives 32. Taking two off 32 gives us 30. This gives us 10 more IP addresses than we need. This means the number of usable hosts is 30.
I will next calculate the range. The range will be the first IP address, which is the network ID, which is the next usable IP address after the office subnet ends. The end IP address will be the network ID plus the number from the powers-of-two table. So, the end IP address will be 192.168.0.128 plus 32 from the power-of-two table. Keep in mind that we are counting from zero, so the first IP address is included in the count. This makes the last IP address to be 192.168.0.159. If you have trouble understanding counting from zero, simply subtract one from the number you want to add, and that will give you the same result.
Since we have the last IP address, we now have the broadcast address. Next, we need to work out the CIDR, that is, how many bits will be used for the subnet mask. IP addresses are effectively split in half by the subnet mask. The first part of the address will be the network ID. To work out the number of bits for the subnet mask, this will be 32 minus the bits that are being used. 24 was allocated beforehand. This gives us 8 more bits. Since I need 20 addresses, looking at the power-of-2 table, we need to use 5 bits. Taking five from eight gives us 3. Adding 3 to 24 gives us 27. It may take a few goes before you get the hang of it.
Now let’s work out the factory subnet. This time, I will start from the top. The CIDR will start with the next IP address that is available after the warehouse range. This will be 192.168.0.160. To work out the number of bits, once again, I will go to my powers-of-2 table. I will go up to 4, which gives us 16. Taking two from this gives us 14. This gives us four free addresses. There is not much room for expansion. If we wanted to, we could make it larger since we still have some free space. This is the kind of decision an administrator needs to make. Do they use the left-over space, and where do they use it? To work out the number of bits, we once again start with 32 and subtract the bits used beforehand, which is 24, giving us 8. Next, subtract from the power-of-2 table the value 4, which gives us a result of 4. Thus, the number of bits for the subnet is 28.
To work out the range, we start with the next IP address after the warehouse address. This will be 192.168.0.160. The end of the range will be the value from our power-of-2 table, which is 16. Counting from zero, this gives us 192.168.0.175. The network ID will be the first IP address in the range, so this will be 192.168.0.160.
The broadcast address will be the last IP address in the range, thus in this case, it will be 192.168.0.175. Lastly, the usable hosts will be the number from our powers-of-2 table, subtracting 2, giving us 14. The process of subnetting can be confusing at first. If you are having trouble, I would suggest trying it a different way until you find a way that works for you. So, what I will do next is look at a different way of working out the subnetting if you are having trouble understanding.
Subnetting Example
When learning subnetting try a few different methods as it will help you understand how it works. When subnetting, you will often be given a network that you will need to divide up into smaller networks to meet your needs.
I will work through the previous example using a different method. To start with, I will work out the range of IP addresses. The first address will be when the host ID is all zeros. Thus, in this case, it will be 192.168.0.0. The last IP address will be when the host ID is all ones. In this case, it will be 192.168.0.255. Since we know the first and last IP addresses, we now have the range.
The first address will be the network ID. The last address will be the broadcast address. Since the range of IP addresses is 256 addresses, we need to subtract two to get the usable IP addresses. These unusable addresses are the network ID and broadcast address. This takes the 256 IP addresses down to 254 usable IP addresses when we remove the network ID and broadcast address.
So let’s now divide this network up into our office, warehouse, and factory networks. The office network has 90 devices on it. Thus, we need to have a network that supports 90 or more.
I have added an extra column for the number of hosts the network supports. This is simply the value minus 2 for the usable IP addresses. The network ID and broadcast ID are not usable IP addresses that can be used for devices on the network, thus we subtract 2.
To work out how many bits we need for the host ID, I will go down the table until the hosts are greater than 90. Thus, the number of bits I will need for the host ID is 7. Consulting the powers-of-2 table, we know that 7 is 128 values. Thus, we will take 128 addresses out of the network that we were given. Keep in mind, this is 128 addresses, thus we have to include zero as one of these addresses. This makes the last address in our new subnet 192.168.0.127. Thus, we now know what the range is.
The first address in the range will be the network ID. The last address will be the broadcast address. The first usable IP address will be the next IP address after the network ID. The last usable IP address will be the address before the broadcast address.
We have so far divided our network into two. We, however, need to further divide it because we have two more networks that need IP addresses.
The start of the next network will be the next address after the last network. Thus, the next network address will be 192.168.0.128. For the warehouse, we need 20 addresses, so consulting the powers-of-2 table, we need 5 bits as this gives us 32 addresses, 30 of which are usable.
Since we know the first address of the subnet and we know how many addresses are in the subnet, we can now work out the range. The range will include 32 addresses, which includes the first address in the network. Thus, the last address will be 192.168.0.159.
The first address in the network will be the network ID, and the last IP address will be the broadcast address. The first usable address will be the next address after the network ID. The last usable address will be the last address before the broadcast address.
The last network that we have to allocate is the factory network. The first address of the factory network will be the next address after the last warehouse address, which will be the broadcast address of the warehouse network. To work out the end address or the broadcast address, we will consult our powers-of-2 table. We need 10 addresses, so we will use 2 to the power of 4. From the powers-of-2 table, we know that the network will have 16 addresses. So, counting 16 addresses, including the first address in the network, this gives us the address 192.168.0.175. Thus, we now have the range.
Using the range, taking the first address, we know that it is the network ID and the last address is the broadcast address.
You can see that there is still some space left in the original network we were allocated. We could use that space to increase the number of devices on one of the other networks. For example, we could increase the number of IP addresses on the warehouse or factory networks. We could also leave the last part of the network unallocated and leave it for future expansion.
I am going to move on to the next topic of the video, which is how packets are forwarded around an IP network. If you don’t understand subnetting, I will address some of the points when looking at forwarding packets, and that may help you understand it better.
Forwarding
Forwarding is the process of forwarding packets from one network to another. To do this, the device uses a routing table to determine the route. Later in the video, I will have a look at an example of how routing tables work. For the moment, I will have a look at how a device makes the decision of whether the packet is routed or not.
Routing uses the AND operator. The AND operator works at the binary level of the IP addresses and subnet mask. Essentially, the AND operator is used with a route and the subnet mask. When both binary values are one, the result will be a one. In any other case, the result will be zero. To understand how it works, let’s consider that we have a route to the local network.
The first thing that I will do is convert the route into binary. The next step is to AND the subnet mask with the route. The subnet mask shown is used to determine which part of the route will be considered for routing. In the case of this subnet mask, the first 24 bits are ones and the last 8 are zeros. This translates to the first three bytes being considered for routing, while the last byte will not.
To see how this works, I will AND the route with the subnet mask. This effectively removes the bits we don’t want to consider and leaves the bits that we do want to consider. In a lot of cases, like in this example, you won’t get any bits that change. The reason for this is that the network ID is generally used with the subnet for that network. It is, however, possible to reduce the number of one bits in the subnet mask, if you need to, by using a subnet mask with fewer ones in it.
This is just the route, so now let’s add a destination IP address. Like before, I will use the same network mask with the AND operator on the destination address. This destination IP address is on the same network as the route. You will notice that bits on the right have all changed to zero, which are the bits for the host part of the address. That is, all the bits on the right in the last byte. We now have separated the network part from the destination IP address.
By default, when a packet is sent and the destination IP address is on the same network, the packet will be sent directly to that network. For the device to determine that the packet should go to the local network, it needs to check if the route matches. To do this, the device simply compares the two network IDs. Since they are the same, we know the destination IP address is on the same network as the route.
Later in the video, I will look at this process in more detail, but essentially, the device will go through its routing table until it gets a match. Let’s now look at what happens when the result is not a match.
For this example, I have a second destination IP address which is on a different network. You will notice that the last byte is the same as the other destination IP address. Since we can separate the network and the host ID from each other, different networks can have the same host IDs. I will apply the same network mask to this address that I did to the last address. This will give the following result.
You will notice the right byte once again will be zeroed out like before. However, in the third byte, notice that since the destination address is slightly different from the source IP address, one of the bits is different. Thus, when we compare the two, the network IDs won’t match.
When the network IDs don’t match, like in this case, it means the routing rule won’t be applied. To understand how routing rules determine where traffic goes, let’s consider a more complicated example.
Routing Example
In this example, I have the office network and warehouse network connected together by a router. I have left out the factory network to make the example easier to understand. To show what is happening, I have added a route tester. When working through the example, I will show what is being tested so you can have a clearer understanding of what is occurring.
The office network has been assigned the following network address. The warehouse network has been assigned the following network address.
On the office network, there is a user using a computer. This user has been assigned the following IP address. To understand routing a little better, let’s consider the user is sending a packet to a server on the same network as the user. The server has been assigned the following IP address.
Now let’s consider what happens when the packet is sent. First, the computer consults its routing table. Every device on the network has its own routing table. The computer does not have the same routing features as a dedicated hardware router but still has a basic routing table to determine where packets go.
The computer consults the routing table to find a route that matches. Let’s consider the first route in the table. This route will send any traffic from the computer to the local network. Let’s put it in the route tester to see what is happening.
The route and destination IP address will have the AND operator applied to them using the subnet mask. When this process is complete, only the network ID will be left. You will notice that these will match. Thus, sending a packet to the local network matched this rule in the routing table. This rule is added automatically by the computer to ensure packets for the local network get routed to the local network.
You may be wondering if it is possible to delete this route or change it. The answer is you could. Unless you had a really good reason to, you would not modify any of the default routes created in the routing table. In some cases, for testing, very rare troubleshooting, or workarounds, you may. Changing a default routing table should be very rare. The reason I point this out is to demonstrate that every IP device on the network is essentially a mini router with a small routing table that determines where packets are sent.
Now let’s consider another example. Let’s say the user wants to connect to a CCTV camera that is in the warehouse network. This CCTV camera is accessible using the network and has been assigned the following IP address.
The user attempts to connect to the CCTV camera and thus sends a packet with the CCTV camera address. Now let’s have a look at how it gets routed to the destination.
Like before, the routing table is consulted. I will put the first route into the route tester. You will notice this time the network IDs are different because this packet is going to another network. Thus, the packet won’t match this rule in the routing table.
The computer will then go to the next rule in the routing table. A computer will have more routes than the ones I have shown, but I have reduced it down to the bare minimum to make it easier to understand what is happening.
When configuring networking on a computer, you will be asked to provide a default gateway. The default gateway is where traffic will be routed when no other matches are found in the routing table. In this case, this route is saying to send all traffic to an interface on the router for this network. Let’s put this in the route tester to see what is happening.
You can see the subnet mask is all zeros. When this occurs, this essentially changes all the values in the source and destination IP addresses to zero. Thus, the result will match since everything is zeros. This means anything that does not match a previous rule will match this rule.
The next step is the router needs to forward the packet to the next network. To do this, it will consult its routing table. The router should have a route in its routing table which will say where to send the traffic. In this case an interface on the network containing the destination IP address, or another network that will get the packet closer to the destination. Let’s look at the route tester to see what is happening.
You will notice for this route there are 27 ones in the subnet mask, whereas the last network had 25 ones in the subnet mask. The process is the same: the subnet mask is applied to the route and the destination IP address. Once applied, the results are compared, and if the results are the same, then the route is used. In this case, the packet will be sent via the interface to the network directly to the CCTV camera. You can see how traffic is routed on an IP network. The routing table is read, and the destination IP address is compared with it using the AND operator. Once a match is found, the packet is routed to the next location.
You can see that routing tables on the device and routers determine how packets will be routed to their destination. The subnet mask is used to determine how we should process each rule. Let’s have a look at how this all works in the real world.
In The Real World
As an IT technician, you need to know how to configure network settings. In this example, the IP address, subnet mask, and default gateway are configured. To make the IP address easy to read, it is written as four digits known as octets.
A subnet is used to work out what is local traffic and what traffic needs to be routed to other networks. To do this, the IP address and subnet mask are processed in binary. The subnet mask allows the IP address to be divided into a network ID and a host ID.
To route packets to the local subnet, a route is added to the local routing table. This is all done automatically. Normally, you won’t need to make changes to the routing table on the device; this will be done automatically for you.
You can see that the route that has been added forwards packets to the local subnet. The term “On-link” is essentially saying to send the packet to the network card to the local network. When a packet is sent from the computer, the destination IP address is checked against the routing table. Once a match is found in the routing table, the packet is forwarded according to the routing table.
If no match is found in the routing table, generally the last route in the table will be the default route. The default route is always matched since the subnet mask used to check it is all zeros. Thus, it will always process as being true. When you configure the default gateway on the computer, the default route with that gateway IP address is added to the route table. Thus, when no other rules match, the computer will forward the packet to the default gateway.
IP addresses can be difficult to understand at first. Hopefully, this video has helped you better understand how they work.
End Screen
That concludes this video on IPv4. I hope you have found this video informative. Until the next video, I would like to thank you for watching.
References
“The Official CompTIA A+ Core Study Guide (Exam 220-1101)” pages 172 to 174
“Mike Myers All in One A+ Certification Exam Guide 220-1101 & 220-1102” pages 771 to 773
Credits
Trainer: Austin Mason http://ITFreeTraining.com
Voice Talent: HP Lewis http://hplewis.com
Quality Assurance: Brett Batson http://www.pbb-proofreading.uk