Hello! Welcome back to our journey through networking fundamentals.
In the last lesson, we established that an IPv4 address is a 32-bit number, like 192.168.1.1, and we learned the crucial difference between public and private IP ranges. We ended by noting that these addresses are grouped into networks, like the 192.168.1.0 network.
Today, we're going to learn the mechanics behind creating and defining these groups. Our goal is to calculate subnet masks, network addresses, and broadcast addresses for a given network block. This is a core skill for any DevOps engineer. When you design a cloud environment, you don't just get a pile of IP addresses; you get a large block that you must "carve up" into smaller, logical sub-networks (subnets) for different purposes—one for your web servers, one for your databases, and so on. This lesson will give you the foundational math to do that correctly.
Part 1: The Subnet Mask - The Divider
At the heart of subnetting is the subnet mask. Its single purpose is to tell a computer which part of an IP address is the network portion and which part is the host portion.
- Network Portion: Identifies the subnet the device belongs to. All devices on the same subnet share the same network portion.
- Host Portion: Uniquely identifies the device within that subnet.
Like an IP address, a subnet mask is a 32-bit number. The rule is simple: in the mask's binary representation, all the 1s represent the network portion, and all the 0s represent the host portion.
For example, a very common subnet mask is 255.255.255.0. In binary, this is:11111111.11111111.11111111.00000000
This mask tells us that the first 24 bits of an IP address are for the network, and the last 8 bits are for the host.
To get a formal definition and see a helpful table of default masks, let's turn to a quick reading.
Determining Network and Broadcast Address Using IP ...
This article from Baeldung clearly defines the subnet mask and its purpose in dividing a network. It also introduces the default masks for historical IP classes, which helps build context.
Please read section 5, titled 'Subnet Mask'. Focus on its role in determining the network and host address portions.
The CIDR Cheat Sheet
In modern networking, we rarely write out the full 255.255.255.0. Instead, we use CIDR (Classless Inter-Domain Routing) notation, which is simply a slash (/) followed by the number of network bits.
255.255.255.0has 24 network bits, so it's written as /24.255.255.0.0has 16 network bits, so it's written as /16.
The cheat sheet below is an invaluable tool that you will likely reference throughout your career. It maps CIDR notations to their dotted-decimal masks and shows how many addresses are in a given subnet.

Part 2: Calculating the Network and Broadcast Address
Every subnet has two special, reserved addresses:
- Network Address: The very first address in the subnet. It represents the subnet itself and cannot be assigned to a device.
- Broadcast Address: The very last address in the subnet. Sending data to this address sends it to every device on the subnet. It also cannot be assigned to a single device.
The process of finding these two addresses is a fundamental binary operation. Let's learn how it's done.
Determining Network and Broadcast Address Using IP ...
The following section from the Baeldung article provides a perfect, step-by-step example of calculating the network and broadcast addresses from a given IP and subnet mask. It shows the binary conversion, which is key to truly understanding the process.
Please read section 6, 'Determining Network and Broadcast Address'. Follow the example with IP address 192.168.1.1 and subnet mask 255.255.255.240. Pay close attention to how the binary IP and mask are used to find the network and broadcast addresses.
Let's break down the logic from the article with our own example.
Scenario:
- Our IP Address:
172.16.10.135 - Subnet Mask:
255.255.255.192(which is/26)
Step 1: Convert to Binary
- IP:
10101100.00010000.00001010.10000111 - Mask:
11111111.11111111.11111111.11000000
Step 2: Calculate the Network Address
The rule is: Set all host bits to 0.
The mask has 26 ones, so the last 6 bits are the host bits. We take the host bits from the IP (000111) and change them all to zeros (000000).
- Network Addr:
10101100.00010000.00001010.10000000 - Converting back to decimal:
172.16.10.128
This is the network address for our subnet.
Step 3: Calculate the Broadcast Address
The rule is: Set all host bits to 1.
We take the network address we just found and flip its 6 host bits from zeros to ones (111111).
- Broadcast Addr:
10101100.00010000.00001010.10111111 - Converting back to decimal:
172.16.10.191
This is the broadcast address.
Step 4: Determine the Usable Host Range
The usable IPs are everything between the network and broadcast addresses.
- Usable Range:
172.16.10.129to172.16.10.190 - Total Hosts: A subnet with
hhost bits can have2^htotal addresses. Since 2 are reserved (network and broadcast), we have2^h - 2usable hosts. In our/26example, there are32 - 26 = 6host bits. So,2^6 - 2 = 64 - 2 = 62usable hosts.
Part 3: A Practical DevOps Scenario
Now, let's apply this to a situation you'd encounter as a DevOps engineer: designing subnets based on requirements.
Subnetting Made Easy: A Step-by-Step Guide - Medium
The article 'Subnetting Made Easy' provides a fantastic, real-world example. It starts with a large block of addresses and carves it into smaller subnets to meet specific host requirements. This is exactly what you do when planning a VPC.
Please read sections 4 and 5, starting from 'Subnetting Example'. This walks through taking the 192.168.0.0/24 network and creating three subnets for 60, 30, and 10 hosts. Focus on how it calculates the required subnet mask for each and then determines the network, broadcast, and usable addresses.
The key takeaways from that example are:
- Start with the largest requirement first. This makes allocating the address space much easier.
- Find the number of host bits needed. For 60 hosts, you need a subnet that can hold at least
60 + 2 = 62addresses. You find the smallest power of 2 that is greater than or equal to this number.2^5 = 32(too small).2^6 = 64(just right). So you need 6 host bits. - Calculate the subnet mask. If you need 6 host bits, then you need
32 - 6 = 26network bits. This gives you a/26subnet mask. - Allocate the subnets sequentially. The first subnet (
/26) starts at192.168.0.0and ends at192.168.0.63. The next subnet can then start at192.168.0.64.
This process of using different-sized subnet masks within a larger network is called Variable Length Subnet Masking (VLSM).
Test your understanding!
You have been assigned the network block 10.20.0.0/16 for a new project. You need to create a subnet for a small database cluster that will contain up to 10 servers. You decide to use the very first available addresses from the block for this new subnet.
- How many host bits (
h) do you need to accommodate 10 servers? - What is the correct CIDR notation (
/n) for this subnet? - What is the Network Address of this new subnet?
- What is the Broadcast Address of this new subnet?
- What is the range of usable IP addresses you can assign to your database servers?
Show answer
- Host bits: You need addresses for 10 servers, plus 2 reserved addresses (network and broadcast), for a total of 12.
2^3 = 8(too small).2^4 = 16(correct). So, you need 4 host bits. - CIDR notation: With 4 host bits, you have
32 - 4 = 28network bits. The CIDR notation is /28. - Network Address: The
/28subnet will occupy the first 16 addresses of the/16block. Since the block starts at10.20.0.0, this first subnet also starts there. The network address is10.20.0.0. - Broadcast Address: A
/28subnet has 16 total addresses (from 0 to 15). The last address is the broadcast address. The broadcast address is10.20.0.15. - Usable Range: Everything between the network and broadcast address. The usable range is
10.20.0.1to10.20.0.14.
Conclusion
Mastering these calculations is a rite of passage in IT and is absolutely essential for cloud and DevOps roles. It removes the "magic" from IP addressing and gives you precise control over your network architecture.
Key Takeaways:
- A Subnet Mask divides an IP address into a network portion (
1s) and a host portion (0s). CIDR notation (/n) is a shorthand for the number of network bits. - The Network Address is the first address in a subnet, where all host bits are
0. It's calculated by performing a bitwiseANDbetween an IP address and its subnet mask. - The Broadcast Address is the last address in a subnet, where all host bits are
1. - The number of usable hosts in a subnet is
2^h - 2, wherehis the number of host bits.
In our next lesson, we will solidify these concepts by focusing specifically on using CIDR notation to define network sizes and allocate IP address ranges. Now that you understand the underlying math, we will practice applying CIDR as a high-level tool for network planning and design, making you faster and more efficient.