What is an IPv4 address?
Found within layer 3 of the OSI model, an IPv4 (Internet Protocol Version 4) address is a logical 32 bit address represented in a dotted decimal number format assigned to network devices to allow for host identification and it's location within a network. This allows for a route to be established between two network nodes to send/receive traffic. To compare against a MAC address, an IP address allows for traffic to pass over many network devices whereas a MAC address is only used between on those links between the devices. To re-iterate, an IP address is a logical addressing scheme which allows devices to talk to hosts on their own network (LAN), or to devices within other remote networks (WAN). The IP address always comes with a subnet mask, which we will explore later in the article.
To use an analogy, the IP address is not dissimilar to your own personal address, with the street name being the network portion and the house number being the host portion.
IP addresses are split into octets, with each octet containing 8 binary bits to make up the 32 bit address. These octets are separated by a full-stop and there are 4 octets in total, each having a maximum numerical value of 255. This is referred to as dotted decimal. Let's take a look at an example IP address 192.168.0.1.
A 1 or a 0 is used to denote whether the decimal value is on or off. So 1 = ON, and 0 = OFF. These 1's and 0's essentially energise or take no action on the transistors within computer processors. To make up the total dotted decimal value of the 2nd octet 168 of the IP address, we add together the individual decimal values like this:
128 + 32 + 8 = 168
To break it down even further we can check whether the decimal value fits within the total dotted decimal value per the below:
Does 128 fit within 168? Yes, binary value on. 1
Does 64+128 fit within 168? No, binary value off. 0
Does 32+128 fit within 168? Yes, binary value on. 1
Does 16+32+128 fit within 168? No, binary value off. 0
Does 8+32+128 fit within 168? Yes, binary value on. 1
Does 4+8+32+128 fit within 168? No, binary value off. 0
Does 2+4+8+32+128 fit within 168? No, binary value off. 0
Does 1+2+4+8+32+128 fit within 168? No, binary value off. 0
So, to summarise, an IP address is presented to us in dotted decimal format split into 4 octets. Each octet contains 8 binary values or "bits", which translate on the device to either power on, or power off to calculate the octet's total value. The total value if all bits were set to 1 is 255, so the maximum possible IP address is 255.255.255.255, however there is more to IPv4 addressing as two IP addresses are reserved for the network ID and broadcast address, see below.
Network ID and Broadcast Address
The network ID is always the first IP address in the address range, and is used to identify the network usually for routing purposes. The broadcast address is always the last IP address in the range and is used when traffic needs to be sent to all devices on the local subnet. This is also referred to as the broadcast domain.
The CCNA requires the following to be calculated from a network address and subnet, depending on the question:
-
Number of available networks
-
Number of IP addresses
-
Number of host usable IP addresses
-
Network ID IP address
-
First usable IP address
-
Last usable IP address
-
Broadcast IP address
What is a subnet mask?
Now we have an understanding of what an IP address is, and how it is used for network routing and host identification, a key element of the IPv4 protocol is how do we identify what portion of the network is used for the network subnet and what portion is available for host addressing. For this we use something called the Subnet Mask. The subnet mask is always present with the IP address and typically you will see it like below:
Subnet Mask - Broken Down
With the subnet mask, if the binary value is set to 1, then this denotes the network portion of the IP address. Always starting from the left until the binary value of 0 is seen. This then denotes the host portion of the IP address. 255 is the maximum binary value of an octet. So looking at the below we know the first three octets are designated for the network, and the final fourth octet is for host allocation. This example mask will allow for a total of 253 usable IP addresses for the hosts (192.168.0.1 - 192.168.0.254). It's not 255 usable IP addresses as the first IP (192.168.0.0) is used for the network ID, and the final IP (192.168.0.255) is used for the broadcast IP.
Changing the Subnet Mask
A key element of the subnet mask is it allows us to change the size of the network, where we can reduce or increase the number of available hosts. If we change the binary values of the network portion to 0, we add more hosts. Conversely, if we change the host portion bits to 1 we reduce the number of hosts. Note that the changes are always made left to right. This is known as subnetting which we will learn how to calculate later in this article.
Looking at the above example, we have changed a number of bits within the third octet to 0. This has increased the number of available usable host IP addresses to 8190 (8190 is including the network ID and broadcast IP).
Classful IP Addressing
While the classful IP addressing method is no longer in use within the public IP address scheme, it is still referred to today and therefore is something we need to understand. Classful IP addressing was replaced in 1993 due to the unexpected (at the time) popularity of the internet. Classful addressing was replaced by Classless Inter-Domain Routing to allow for better scalability of the internet with the limited number of IP addresses available. There are 5 different classes of IP addresses, per the below:
Prior to the move away from classful addressing, network classes were identified using the first 4 bits of the IP address seen in the above table. These were referred to as the leading bits. For example, for IP address 130.58.41.89 , we know this is a Class B network because the binary string for the first octet is 1 0 0 0 0 0 1 0. As we now know this is Class B network, the subnet mask will be 255.255.0.0. Another example such as 200.54.88.57 would be a Class C network, because the binary string of the first octet is 1 1 0 0 1 0 0 0, and the subnet will be 255.255.255.0. Due to the growing size number of interconnected devices, restricting subnet masks to 3 would prove to be a massive limiting factor in the success of the internet.
Today we still sometimes use the classful naming convention, but this is typically only used to quickly describe what subnet mask is used in a specific network. For example if we see an IP address with subnet mask of 255.255.255.0, this is known as a Class C network. See the table below for reference:
Classless Inter-Domain Routing (CIDR) Addressing
When it was realised that using the classful addressing scheme would limit the scale of the internet, the Internet Engineering Task Force (IEFT) introduced the Classless Inter-Domain Routing (CIDR) scheme back in 1993. Following this change we now append the IP address of a network with something called a CIDR Notation. The CIDR Notation is a number which starts at 0 and ends at 32. This is because there are 32 bits in the subnet mask (same number as in an IP address). The notation is the total count of network bits within the subnet mask. For example, with an IP address of 192.168.0.1 255.255.255.0, the CIDR notation will be 24 because the first 3 octets of bits within the subnet mask are binary value 1, so 8 x 3 is 24. The IP address is then presented as 192.168.0.1/24. See below for another example of 172.78.23.5/30:
If we look at the IP address in the image above and it's subnet mask, we can see the first 3 octets of the subnet mask are 255, therefore all the binary values or bits will be set to 1. So 8+8+8=24. Then looking at the final 4th octet, the decimal value is 252, therefore when converted to binary there are 6 bits set to 1. 24+6=30, so in total with 30 network bits, the CIDR notation with the IP address will be 172.78.23.5/30. The flexibility of CIDR allows IANA and organisations to better control public IP address assignment.
If we look at an example in reverse for IP address 192.168.54.5/28, we know there are 28 total network bits. Always work left to right when calculating subnet masks and because the value is more that 24, the first 3 octets will be 255. To calculate the final 4th octet we need to convert to binary, as 28-24=4, we set the first 4 bits to on, then add up the decimal values to obtain the final octet in the subnet mask, see below.
So, 128+64+32+16= 240, therefore the full subnet mask for network 192.168.54.5/28 will be 255.255.255.240.
IPv4 Header
IP operates at Layer 3, so in order to send data across or between a network we need to encapsulate the payload within an IPv4 header. The IPv4 header is always at least 20 bytes in size and can be used to change the way a packet is handled by a router.