Networking is the practice of connecting two or more devices together so that they can communicate with each other and exchange data. While the internet is the largest and most well-known network example, it consists of various smaller groups and divisions of networks called subnets.
As a rule, subnets belong mostly to large organizations. Subnets can also exist internally within organizations to separate users according to different departments’ network needs. They also exist in homes, hotels, and other settings, though these internal subnets may not be directly exposed to the internet. Connections can be established via various transmission mediums, such as network cables or other wireless technologies.
In this article, you’ll learn and understand at a basic level how subnetting works and see how beneficial it is to know about subnetting and implementing subnets. You’ll also learn about the subnet mask and CIDR notations, and you’ll be introduced to common subnet sizes, network classes, and how to easily calculate subnets for a specific number of hosts on your network.
A subnet is a logical subdivision of an IP network. It allows a larger network to be divided into smaller, more manageable subnetworks, each with its own unique IP address range. Internet Protocol (IP) is a set of rules and procedures that govern how devices identify themselves and exchange data with other devices on a network. One of the most important components of the internet Protocol is the IP address.
An IP address is a unique identifier assigned to each device on a network and used to route data between them. An IP address is made up of four sections separated by dots, each with a decimal number ranging from 0 to 255. These four sections are also called octets, and when you combine all of them, you get a total of 32 bits. So, for example, an IP address could look like this: ‘192.168.100.10’.
There are two versions of IP currently in use: IPv4 and IPv6. The previous example uses IPv4, which is the older and more widely used version, while IPv6 is newer and designed to address the limitations of IPv4. There’s more about this later in the article, but for now, this article will focus on IPv4.
In many medium- to large-sized network environments, it’s common to split the network into smaller subnetworks for various reasons. This process is known as subnetting, and it’s used to improve network performance, manage resources more easily, enforce security policies, and monitor network traffic, among other benefits.
While the subject of subnetting can be technical and mathematical, the following analogy should help you understand the basic concept.
Imagine you have a large field with many people playing different sports, such as football, basketball, and baseball. Without any form of organization, it can be chaotic and difficult for players to focus on their game. By creating separate areas on the field for each sport, such as a football field, a basketball court, and a baseball diamond, players can focus on their game without interference from other sports.
Similarly, subnetting can be considered as dividing the field into smaller sections, each with its own set of boundaries and rules. Subnetting allows a large network to be divided into smaller segments, each with its own IP address range, allowing a specific number of devices to communicate with each other more efficiently in that segment.
Just as the lines and boundaries marking a field take up physical space, subnetting requires the use of a portion of the address space to delineate and organize the network. In each subnet, the first and last IP addresses are reserved for the network address and the broadcast address, while everything in between represents the range of IP addresses that can be assigned to devices within that subnet (*ie*, the playing area).
Using subnetting in your network can offer several important benefits. Here are a few of the most significant:
Below we will take a closer look at the constituent components of subnets. An IP address has two parts: the network portion and the host portion, which respectively identify the network (network address) and the specific device within that network.
The subnet mask is a set of 32-bit decimal numbers that determines how many bits of the IP address are used for the network and how many bits are used for the host. In practice, a subnet mask is usually expressed in dotted decimal notation, like an IP address.
To understand how subnet masks work, it helps to think about IP addresses and subnet masks in binary notation. An IP address is a 32-bit number represented as a sequence of 0s and 1s. A subnet mask is also a 32-bit number, with a sequence of 1s followed by a sequence of 0s.
The sequence of 1s in the subnet mask indicates which bits of the IP address belong to the network portion, while the sequence of 0s indicates which bits belong to the host portion.
As seen in the example above, a subnet mask of ‘255.255.255.0’ indicates that the first three octets with eight 1s (8 bits) each and a total of 24 bits represent the portion of the IP address that is reserved for the network, and the last octet (8 bits) is reserved for the host portion.
There are two main ways you can write or define a subnet to determine the network and host segments of an IP address: subnet mask notation and classless inter-domain routing (CIDR) notation.
In this notation, the subnet mask is written using decimal numbers in four parts separated by periods, and as seen earlier, each part is called an octet. A subnet mask of ‘255.255.255.0’ indicates that the first 24 bits of the IP address are reserved for the network portion, and the remaining 8 bits are reserved for the host portion.
To express a subnet using subnet mask notation, you simply add the subnet mask to the end of the IP address, separated by a space. For example, ‘192.168.100.10 255.255.255.0’ represents a subnet with an IP address of ‘192.168.100.0’ and a subnet mask of ‘255.255.255.0’. Then, the network portion of the IP address is ‘192.168.100’, and the host portion is ‘10’, exactly as seen in the previous illustration.
CIDR notation is a compact way of indicating a subnet by using a single number to represent the subnet mask. In CIDR notation, a subnet is indicated by adding a forward slash (‘/’) and a number to the end of the IP address.
The number after the slash indicates the number of bits that are reserved for the network portion of the address. For example, ‘192.168.100.0/24’ means the first 24 bits of the IP address are for the network portion, automatically leaving the last 8 bits for the host. This is equivalent to ‘192.168.100.0’ with a subnet mask of ‘255.255.255.0’.
CIDR notation allows for a more concise representation of subnets, especially when dealing with large networks. It also provides a more explicit indication of how many bits of the IP address are used for the network portion of the subnet, which can save you the trouble of having to calculate it yourself, as you might need to do with subnet mask notation. These benefits have led to CIDR notation becoming increasingly popular.
In the early days of the internet, IP addresses and subnets were divided into classes based on their initial bits, with each class having a fixed number of bits reserved for the network portion and the host portion of the address.
This made it easier to memorize subnet masks and identify them based on the leading numbers of the IP address. The three most commonly used classes are Class A, Class B, and Class C, which correspond to the most common subnet sizes of ‘/8’, ‘/16’, and ‘/24’, respectively.
Here’s a brief explanation of how they differ:
You should keep in mind that the use of classful addressing has largely been replaced by classless addressing, as mentioned. However, the terms Class A, Class B, and Class C are still commonly used to refer to the traditional subnet sizes of ‘/8’, ‘/16’, and ‘/24’, respectively.
Calculating the number of possible hosts on a subnet is essential in order to ensure that the network can support the required number of devices while avoiding potential performance issues. To calculate the number of possible hosts, you need to know the subnet mask for the network and use that to determine the number of host bits in the IP address.
You can obtain this by subtracting the total number of network bits from 32. Once you have that, you can determine the number of hosts using the following formula:
Number of hosts = 2^(number of host bits)-2
In this formula, the number of host bits is equal to the total number of bits in the host portion of the subnet mask. The “-2” at the end is because the first address in the subnet is reserved for the network address and the last address is reserved for the broadcast address, as explained earlier in the article.
You can use a subnet mask of ‘255.255.255.0’ as an example. With this subnet mask, the first 24 bits are used for the network portion of the address, and the remaining 8 bits are used for the host portion. This means that you can have 2^8 (256) possible values in the host portion of the address.
However, as you’ve learned, the first and last addresses in the subnet are reserved. In this case, ‘192.168.1.0’ is the network address, and ‘192.168.1.255’ is the broadcast address. Therefore, the actual number of hosts or devices that can be assigned to this subnet is 256 − 2 = 254.
While the example given earlier for calculating subnet masks may seem easy, it is only the most basic one. In reality, there are much more complex subnet masks that you may need to calculate, and doing so manually can be prone to errors. So, it’s important to take care and be precise to obtain accurate results.
Thankfully, for more complex calculations, online tools like Gcore’s IPv4 subnet calculator can help you perform these calculations more precisely and guarantee accurate results every time.
IPv6 (Internet Protocol version 6) is the most recent version of the Internet Protocol. It was developed as a replacement for IPv4, which has been the primary protocol over the last few decades.
IPv6 uses 128-bit addresses, which results in a much larger address space compared to IPv4’s 32-bit addresses. This allows for a virtually unlimited number of devices to be connected to the internet.
IPv6 addresses are expressed in hexadecimal notation and are typically written as eight groups of four hexadecimal digits, separated by colons. This allows for a more efficient use of address space compared to the decimal notation used in IPv4, which is being exhausted.
IPv6 also includes built-in security features such as IPsec, improved support for quality of service (QoS), and some new features and enhancements that are not present in IPv4.
Despite the advantages of IPv6, its adoption has been slow. This is because IPv4 is already widely used and deeply embedded in the infrastructure of the internet, so many networks and devices still use it. Additionally, IPv6 is not backward compatible with IPv4, and there are no mechanisms to enable devices to communicate between the two protocol versions. This is a major issue that needs to be resolved before IPv6 can become the dominant protocol used on the internet.
Subnets and how subnetting works are topics that are quite complicated, but with the help of this article, you should now have a solid grounding in the basics. You learned what subnets are, how to identify networks and hosts on a network using IP addresses and subnet masks, and how to express subnets and calculate the number of hosts on a subnet. Additionally, you were introduced to IPv6 and its advantages over IPv4 in terms of available IPs for devices and security features.
If you plan to create a new network and set up subnets within an existing one, Gcore Cloud will serve you well. You can connect different Cloud products such as virtual instances, bare metal servers, AI clusters, and others, in one single cloud infrastructure by creating networks and subnetworks. You can also make your private subnetworks routable, providing access to the internet. Additionally, you can enable DHCP to simplify the process of assigning IP addresses to devices and add custom DNS servers for better name resolution.
Written by Rexford A. Nyarko