Most of you reading already know in some capacity what an IP Address is. You may also have seen addresses like 192.168.1.0 or some variant of it in your home network. If you didn’t know, there are currently 4.3 billion IPv4 addresses as part of the IPv4 space, which is divided into subnets by the Internet Assigned Numbers Authority (IANA). Today we will talk about how IPv4 addressing and subnetting works. The 3 main sections that we will cover are:
- Subnets and netmasks
- How the IPv4 space is subnetted
- Subnetting and routing
Subnets and Netmasks
An IP address has four sets of numbers, which are called octets, that can range from 0 to 255 (8 bits). For this reason, an IPv4 address ranges from 0.0.0.0 to 255.255.255.255. IP networks are generally described with an IP address followed by a netmask in the following way: 192.168.0.0/24. The netmask /24 dictates what portion in the address is the network portion, which is common to all hosts within the same network, and what portion in the address is the host portion, which is unique and assigned to one host only within that network. The following image shows three different netmasks (/8, /16, and /24) applied to the same base network, 10.0.0.0.
In the first case, 10.0.0.0/8 ranges from 10.0.0.0 to 10.255.255.255 and includes 256 x 256 x 256 – 2 = 16,777,214 hosts. The second subnet 10.0.0.0/16 ranges from 10.0.0.0 to 10.0.255.255 and includes 256 x 256 – 2 = 65,654 hosts. Lastly, 10.0.0.0/24 ranges from 10.0.0.0 to 10.0.0.255 and includes 256 -2 = 254 hosts. If you noticed in the previous calculations we always remove two to account for two reserved IP addresses: the Netmask ID, which is the IP address assigned to identify the network itself, and the broadcast address, which is a reserved address that is used to broadcast messages to all hosts. The netmasks that we just covered are relatively easy to understand. Let’s see what’s the role of subnets when we review the IPv4 space.
The IPv4 Space
As mentioned before, IANA subnetted the IPv4 space to provide a way to address a host based on its function and role. From a high level perspective, there are public subnets that are used to address Internet hosts and private subnets as documented in RFC1918 to address internal, private hosts. There are also subnets that have a special purpose, such as the subnet 184.108.40.206/4 reserved for multicast addresses.
A private network is an internal network that is composed of hosts whose addresses fall into the RFC1918 private space. Whether it’s your house, your company’s office or a Fortune 500 company, devices such as computers, routers, switches, and printers will have an IP address. Private addresses explain how come the estimated number of internet-connected devices (more than 26 billions at the moment) is already much higher than the 4.3 billions of IP addresses that are supported by IPv4. Since IANA lets anyone use private addresses for their internal networks, there’s no risk that two hosts on the Internet will carry the same IP address. This is also thanks to NAT (Network Address Translation), which is the process that enables a router to convert an internal IP address into a public one.
Subnetting and Routing
Below is an example of how subnets and network aggregation can be implemented in an enterprise network. When looking to the left, each building has a /24 netmask which gives 254 IP addresses to address computers, printers, etc in each building. Since we have four buildings to address, we will use four different networks . Building 1 uses the network 192.168.0.0/24, building 2 uses 192.168.1.0/24, building 3 uses 192.168.2.0/24, and building 4 uses 192.168.3.0/24.
Each region includes two buildings, with two /24 networks that can be aggregated with /23 netmasks. For instance the Region 1 router includes subnets 192.168.0.0/24 and 192.168.1.0/24 that can be aggregated as 192.168.0.0/23 while the Region 2 router includes subnets 192.168.2.0/24 and 192.168.3.0/24 that can be aggregated with the supernet 192.168.2.0/23.
Then if we go one step further the WAN router aggregates the entire network into a 192.168.0.0/22 netmask which covers all the four subnets and buildings.
IPv4 subnetting and addressing is an important aspect of networking. It is how computer networks are designed, oftentimes hierarchically via aggregation, to ensure an efficient way to organize resources (IP addresses and hosts). For some time now we’ve been dealing with the “small” IPv4 address space composed of only 4.3 billion of addresses. As we learned, not all these addresses are available for public use, and assigning private addresses paired with NAT enabled us to extend the life of IPv4. Eventually the networking world will fully adopt IPv6 addresses. You can already see many Internet Service Providers only assigning IPv6 addresses to their subscribers.