Understanding IP Addressing And Subnetting
Introduction
This article describes the basic information needed to understand how IP(Internet Protocol) addresses are breaking down and how subnetting works. This article will dive deeper into how to assign an IP address with a unique subnet and there are examples included to help you understand much better and faster.
What is an IP Address
By definition, an IP address is a unique address that identifies a device on the internet or a local network. IP stands for "Internet Protocol," which is the set of rules governing the data format sent via the internet or local network.
An IP address is an identifier that allows information to be sent over the internet across all devices on a network. An IP address is just like a carrier that carries information from one node to another for effective communication worldwide. The internet needs a way to differentiate computers, smartphones, routers, and websites, in other not to send information to the wrong address. IP addresses provide the best way to know the right address to send information to and form an essential part of how the internet works.
Type of IP Address
There are four different types of IP addresses;
Private IP Address
A private IP address is a non-routable address of your device assigned by the network router. Every device connected to the same network has a private IP or network address. An IP address allows devices connected over the same network to communicate. I'e, private IP addresses allow connected devices such as smartphones, printers, computers, or tablets to communicate without connecting to the internet.
Public IP Address
A public IP address is an IP address that can be accessed directly over the internet and it is assigned to your network router by the internet service provider(ISP). A public IP address can sometimes be called an internet IP. It is this address that the internet service provider uses to forward internet requests to specific homes or businesses, it is similar to when a delivery man delivered your purchased product bought online to the address provided or just like sending a message through a post office to a specific address. So the specific address or the address provided is your private IP address, in other words, your private IP address can not communicate outside without a public IP address being assigned by ISP(Internet Service Provider). Your public IP address is the address that all the devices outside your internet network will use to recognize your network.
Dynamic IP Address
A dynamic IP address is an address that changes automatically and regularly. The ISPs let you use the IP address temporarily and re-assign it to another customer. Dynamic IP addresses are assigned using either Dynamic Host Configuration Protocol (DHCP) or Point-to-Point Protocol over Ethernet (PPPoE).
Static IP Address
A static IP address is an address that does not change or that always remains the same. If you have a web server, File Transfer Protocol(FTP) server, or other internet resources that must have an address that cannot change, static IP address is the best address to purchase.
Understanding IP Addresses
As described above, an IP address is a unique address that identifies a device on the internet or a local network. The address is made up of 32 binary bits, which can be divisible into a network portion and a host portion with the help of a subnet mask. The 32 binary bits are broken into four octets ( 1 octet = 8 bits). Each octet is converted into decimals and is separated by a period (dots). So an IP address is said to be expressed in a dotted decimal format.
For example , An IP address of 192.168.81.100. The value in each octet ranges from 0 to 255 decimal, or 00000000 - 11111111 in binary.
This is how binary octets convert to decimal: The right most bit, or least significant bit, of an octet, holds a value of 20.
The bit just to the left of that holds a value of 21. This continues until the left-most bit, or most significant bit, which holds a value of 27. So if all binary bits are one, the decimal equivalent would be 255 as shown here:
1 1 1 1 1 1 1 1 27 26 25 24 23 22 21 20 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255
This is a sample of octet conversion in which all of its bits are not set to 1
0 0 0 1 1 0 1 0 0 0 0 24 23 0 21 0 0 + 0 + 0 + 16 + 8 + 0 + 2 + 0 = 26
And this sample shows an IP address represented in both binary and decimal.
Decimal --> 192.168.81.5 Binary --> 11000000. 10101000. 01010001. 00000101
Classes of IP Addresses
There are five classes of IP addresses which are class A, B, C, D, and E. Each class has a valid range of IP addresses. The value of the first octet determines the class. Class A, B, and C can be used for host addresses while the other two classes are used for other purposes. Class D for multicast and class E for experimental purposes.
Class A -> 1.0.0.0 - 127.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 A Network
This class of IP address is used when there is a large number of hosts needed. In a class A type the first 8 bits are identified as a network Id and the remaining 24 bits is host Id. Class A addresses are used for networks that have more than 65,536 hosts (actually, up to 16777214 hosts!).
An example of a class A address is 102.168.212.226. The "102" is the network Id while the remaining "168.212.226" is the host Id
Class B Network
In a B-class IP address, the first 16 bits (the first two octets) identify the network Id while the remaining 16 bits identify the host Id. Class B addresses are used for networks that have between 256 and 65534 hosts.
example of class B address is 102.168.212.226. The "102.168" is the network Id while "212.226" is the host Id.
Class C Network
Class C is a type of IP address is used for a small network, in this class, the first three octets (the first 24 bits) are the network Id while the remaining 8 bits identify the host Id. Class C is perfect for a network less than 254 hosts.
An example of a class C address is 102.168.212.226. The "102.168.212" is the network Id while "226" is the host Id.
Network Masks
A network mask helps you to know which portion of the address identifies the network Id and which portion of the address identifies the host Id or the node. Classes A, B, and C have a default mask known as natural masks.
As explained in the above classes of IP addresses; Class A -> 255.0.0.0 Class B -> 255.255.0.0 Class C -> 255.255.255.0
From the above masks "255.0.0.0" is the natural mask, "255" is the network Id and "0.0.0" is the host Id respectively.
Understanding Subnetting
Subnet allows you to create multiple logical networks in a single network from the classes. If you do not subnet, it will be very difficult to get multiple Ip addresses. Just imagine not subnet, that means you will only be using a single network from your classes which literally unrealistic.
Each data link on a network must have a unique network Id, and every node on that link is a member of the same network. If you break a major network (A, B, and C) into small subnetworks, it allows you to create a network of interconnecting subnetworks and each data link on this network will have a unique network/subnetwork Id. Any device that connects to the x network/subnetwork will have x distinct Ip addresses, one for each network/subnetwork that it interconnects.
To subnet a network, extend the natural mask with some of the bits from the host Id address to create a subnetwork Id. Let us use the class C network as an example which has a natural mask of 255.255.255.0. Given an IP address of 192.168.5.0. You can create a subnet in this manner:
192.168.5.0 -> 11000000. 10101000. 00000101. 00000000 From 192.168.5.0 first three octets is network Id while the last octet is the host Id.
We can now create a subnet mask on the last octet by extending the natural mask with some of the bits from the host Id.
Note1: you can extend the natural mask with some of the bits from the host Id to create a network/subnetwork Id based on the number of IP addresses you want to assign
In this article I will be extending my natural mask by 4;
IP address to create a subnetwork from -> 192.168.5.0
192.168.5.240 -> 11000000. 10101000. 00000101. 11110000
Subnetwork -> 11000000. 10101000. 00000101. 11110000
From the last octet IP given, a subnetwork is created "11110000", 1111 is the subnetwork/network Id and 0000 is the subnetwork host Id.
Now let's calculate the number of IP addresses that we will get from the subnetwork Id;
Hint 1. To find the number of network/subnetwork Id 2n ( Here n indicates the total number of bits borrowed from host Id) 2. To find the number of hosts on each network 2n( Here n indicate the total number of the host bits) 3. to find the number of IP addresses on each network 2n - 2 (Here n indicates the total number of the remaining hosts) Note2: In every network, the first IP address is reserved for the network Id and the last IP address is reserved for broadcast Id.
To calculate the number of IP addresses;
IP address -> 192.168.5.0
Subnetwork IP -> 192.168.5.240
Network ID -> 255.255.255.240
Subnetwork ID -> 2n = 24 -> 16subnet
IP Address -> 2n = 24 -> 16 IP Addresses
No. of assigned IP address = 24 - 2 -> 14 IP addresses to be assigned. (note2)
Breakdown of the above table;
The network ID is "192.168.5.0", the IP address to be assigned ranges from "192.168.5.1 to 192.168.5.14" which is the network address in the table and the broadcast ID is "192.168.5.15" just added 1 to the IP address (note2). The network number 2, the network ID "192.168.5.16", I added 2 to the last previous IP address "192.168.5.14". The two indicate the network Id and the broadcast Id, and the IP address range from "192.168.5.17 - 192.168.5.30".
The first IP address will be increased by one, I'e +1 -> previous subnetwork Id + 1 (192.168.5.16 + 1 = 192.168.5.17)
The last IP address -> the previous IP range + the total number of subnets (14 + 16 = 30) -> 192.168.5.30 respectively.
Note 3: There are two ways to denote these masks. First, since you use three bits more than the "natural" Class C mask, you can denote these addresses as a 3-bit subnet mask. Or, secondly, the mask of 255.255.255.240 can also be denoted as /28 as there are 28 bits that are set in the mask. This second method is used with this method, one of these networks can be described with the notation prefix/length. For example, 192.168.5.16/28 denotes the network 192.168.5.16 255.255.255.240.
Example2
193.16.20.35/29
What is the Network IP, number of hosts, range of IP addresses, and broadcast IP from this subnet?
193.16.20.35/29 -> 11000001. 00010000. 00010100. 00100011
Network ID -> 255.255.255.248 -> 11111111. 11111111. 11111111. 11111000
Subnetwork ID -> 2n = 23 -> 8 subnet
IP Address -> 2n = 23 -> 8 IP Addresses
No. of assigned IP address = 23 - 2 -> 6 IP addresses to be assigned. (note2)
Network IP = 193.16.20.35
Number of hosts = 3
Range of IP addresses = 193.16.20.36 - 193.16.20.41
Broadcast IP = 193.16.20.42
Conclusion
knowing how to subnet and how to assign an IP is very important for a cloud engineer or a network administrator, and I hope this article as help you to understand IP and subnet if you are struggling to wrap your head around it.
"Knowing to subnet is the best and knowing to assign an IP is great"
Subscribe to my newsletter
Read articles from Kinger Stephen Eric directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Kinger Stephen Eric
Kinger Stephen Eric
I am a developer and a DevOps engineer. I love to write about DevOps automation tools