Demystifying Subnet Masking: How I Finally Cracked the Code

Olumide AdeolaOlumide Adeola
12 min read

In this article, I take you through my journey of understanding subnet masking—an essential networking concept that seemed daunting at first but eventually clicked. By breaking down the basics, performing simple bitwise operations, and using relatable examples, I'll show you how subnet masks work and how they help manage IP networks more efficiently. Whether you're just starting out or looking for a fresh perspective, this guide will help you see subnet masking in a whole new light!

Its my little way of perfecting what I have learnt by passing the knowledge across in a clear and understandable way.

So what is Subnet Masking ?

Subnet masking is a fundamental concept in networking that helps ORGANIZE and SECURE IP addresses WITHIN a network. It's crucial for anyone working with computer networks to understand how subnet masks work and their role in dividing an IP network into subnets.

Subnet Masking is a process that involves :

  • Dividing a network into smaller, more manageable subnetworks or subnets. T

  • The subnet mask itself is a 32-bit number that masks an IP address and separates the IP address into the network and host parts.

A quick look at the Anatomy of an IP Address


Before diving deeper into subnet masking, it’s essential to understand the structure of an IP address:

  • IPv4 Address: An IPv4 address consists of four octets (8 bits each), separated by dots. For example, 192.168.1.10 is an IPv4 address.

  • Binary Representation: Each octet in an IP address can range from 0 to 255 and is represented in binary form. For example, the IP address 192.168.1.10 in binary is:

192      .   168    .  1       .   10
11000000 . 10101000 . 00000001 . 00001010

Network and Host Portions: In a typical IP address such as the one above, some bits represent the network portion (192.168.1) , and the rest represent the host portion (specific devices on that network).

Now what's a subnet mask ?

A subnet mask is also a 32-bit number that is used in conjunction with an IP address to define the network and host portions. The subnet mask looks similar to an IP address but serves a different purpose.

For example, the subnet mask 255.255.255.0 in binary form is

 255     .   255    .   255    .   0
11111111 . 11111111 . 11111111 . 00000000

Here, the first 24 bits (represented by 1s) correspond to the network portion, and the remaining 8 bits (0s) are used for the host portion.

When a subnet mask is applied to an IP address, it determines which part of the address is the network and which part is for the host.

Example: Subnet Masking in Action

Let’s consider the following IP address and subnet mask:

  • IP Address: 192.168.1.10

  • Subnet Mask: 255.255.255.0

In binary, this looks like:

  • IP Address: 11000000.10101000.00000001.00001010

  • Subnet Mask: 11111111.11111111.11111111.00000000

Understanding CIDR Notation

Classless Inter-Domain Routing (CIDR) notation provides a compact way of representing an IP address and its subnet mask. It uses a "slash" notation (e.g., 192.168.1.10/24), where the number after the slash indicates the number of bits set to 1 in the subnet mask and can also tell you the number of potential or actual hosts that can occupy the network

In our example, 255.255.255.0 is represented as /24 because the first 24 bits are 1.

Common Subnet Masks and Their Uses

Here are some common subnet masks and their corresponding CIDR notation:

  • /8: 255.0.0.0 – Used for very large networks (e.g., Class A networks)

  • /16: 255.255.0.0 – Used for medium-sized networks (e.g., Class B networks)

  • /24: 255.255.255.0 – Used for smaller networks (e.g., Class C networks)

Important points to note before moving ahead ?

We will use a network with the IP address of 192.168.1.0 /24

  1. How many hosts can be on this network ?

  2. Number of Hosts=2^n −2. Implies 2 to the power of n , then subtract 2 from it, where n is the number of bits apportioned to the hosts

  3. The subtraction of 2 accounts for the network address (the first address in the range i.e. 192.168.1.0 ) and the broadcast address (the last address in the range i.e. 192.168.1.255), both of which cannot be assigned to hosts. The rest of the addresses are for potential or actual hosts(.e devices such as printers, mobiles, computers etc.). That's the rationale for the formula.

  4. Again 192.168.1.0 /24 . There are 32 bits in total , the /24 here represents the network bits, whereas 32-24 =8 represents the host bits.

  5. So back to Question 1: How many hosts can be on this network ?? Its simple now 2*8 which give 256 IP addresses, but you reserve 2 addresses for the network address(the first address) and the broadcast address (the last address) , hence we subtract those 2 from the total , and we have 256-2 = 254 IP addresses are left for the hosts on the network.

  6. So, the subnet mask tells us , how many hosts can be on a network.

  7. Then the idea of subnetting a network (Subnet masking) is now to let us see how we can divide the hosts into manageable groups .

Why Use Subnet Masking?

Subnetting offers several advantages:

  1. Efficient IP Management: Subnetting divides a large network into smaller, more manageable sub-networks, conserving IP addresses and reducing wastage.

  2. Improved Security: It allows network administrators to isolate segments of a network, limiting broadcast domains and enhancing security.

  3. Optimized Network Performance: Smaller networks reduce congestion and improve overall network performance.

  4. Simplified Troubleshooting: By organizing devices into subnets, troubleshooting becomes more focused and manageable.


Being a medic, let me use a typical illustration that is fun to me, lets go .

Suppose We have a medical college(faculty) that has an IP network of 192.168.1.0/24. Already we know there are about 254 hosts or devices that can be connected to this network right. One device may have had 192.168.1.1, 192.168.1.2.... up to 192.168.1.254 right? Yes.

Now, this network needs to be divided into smaller subnets to accommodate the three existing departments — Physiology, Anatomy, and Biochemistry — and possibly a fourth department.

The existing Medical college network: 192.168.1.0/24

  • IP Address Range: 192.168.1.0 to 192.168.1.255

  • Total Number of IP Addresses: 256 (including network and broadcast addresses), if you exclude the network and broadcast addresses, I told you, you would have 254 IP addresses for the hosts right? Yes!

  • Default Subnet Mask: 255.255.255.0

This /24 network has 256 IP addresses, out of which 254 are usable for hosts. Now, let's subnet this network to create separate subnets for each department. This network needs to be divided into smaller subnets to accommodate the three existing departments — Physiology, Anatomy, and Biochemistry — and possibly a fourth department.

Practical Example: Subnetting the Medical College Network

To divide the 192.168.1.0/24 network into subnets for 3 or 4 departments, we need to determine how many subnets are required and how many IP addresses each department might need.

Lets focus 4 department use case here. Let's assume we want 4 subnets for the 4 departments to allow room for growth or future use.

Step 1: Determine the Number of Subnets

To create 4 subnets, we need to borrow 2 bits from the host part of the IP address (since This changes our subnet mask from /24 to /26 (adding 2 bits to the network part).

Step 1: Determine the New Subnet Mask

To create four subnets, we need to borrow 2 bits from the host portion of the original subnet mask (/24).

  • Original Subnet Mask: 255.255.255.0 (/24)

  • New Subnet Mask: 255.255.255.192 (/26)

The issue here is to know what the slash changes to right ? So lets see how we come about the network bits becoming /26

Please take a look at the picture for the mathematical explanation, which I will explain afterwards, don't despise the looks(smiles). I am definitely improving on it. Trust me.

How we came about the calculation of the new subnet network bits

The explanation of the calculation

  • The n represents the number of subnets we need, whereas x represents the number of potential IP addresses we want. In our example, we know n is 4, why ? Because we need just for 4 subnets for 4 potential departments (Anatomy and others) .

  • The Medical faculty has the initial IP 192.168.1.0 /24 , we know the number of hosts it can have from the subnets as explained earlier right ? 24 is the network bits, then 32-24=8 is the host bits, so raising 2 to the power of 8 gives us 256 IP addresses we have available for the hosts on this network

  • So since we need just 4 subnets, it means x=256/4 gives us the now reduced potential number of hosts in each subnets. We can have about 64 IP addresses in each subnets. Just recall that the network address and broadcast addresses will be exempted right ? Yes , of course.

  • Now we solve for the value of n, we are not subtracting 2 now cause , we are including the default gateway address and the network address too, so by calculation we have a new host bits of 6

  • Lastly, we can solve for out network bits , which is simply 32-6= 26 bits i.e. /26

I bet the explanation is simple and straightforward right. Yes of course, you can go over it as many times, its straightforward.

So what next ? its natural to simply construct our new subnets right, Yes.

Bear these in mind

  • Now we are creating just 4 subnets for Anatomy, Physiology, Biochemistry and some other potential department in the future

  • Each of these subnets can have 64 IP addresses , and about 62 hosts each(when we exempt the first address, for the network address and then the last address for the broadcast address)

  • Now we have 4 new network addresses (smaller subnets) with the /26

Now lets commence the last section. Just follow carefully, its simple.

Step 2: Calculating the new Subnets with /26

When we divide the 192.168.1.0/24 network into four subnets, each will have a /26 subnet mask, which provides 64 total IP addresses per subnet, of which 62 are usable for hosts (2 addresses are reserved for the network address and broadcast address).

Subnet Details

Subnet 1: Physiology Department

  • Network Address: 192.168.1.0/26

  • Gateway Address: 192.168.1.1 (often the first usable IP in the range)

  • Usable IP Range for Hosts: 192.168.1.1 to 192.168.1.62

  • Broadcast Address: 192.168.1.63

  • Number of Usable Hosts: 62.

  • NB: The 192.168.1.0 to 192.168.1.63 means 64 IP addresses

Subnet 2: Anatomy Department

  • Network Address: 192.168.1.64/26

  • Gateway Address: 192.168.1.65

  • Usable IP Range for Hosts: 192.168.1.65 to 192.168.1.126

  • Broadcast Address: 192.168.1.127

  • Number of Usable Hosts: 62

  • NB: The 192.168.1.64 to 192.168.1.127 means 64 IP addresses

Subnet 3: Biochemistry Department

  • Network Address: 192.168.1.128/26

  • Gateway Address: 192.168.1.129

  • Usable IP Range for Hosts: 192.168.1.129 to 192.168.1.190

  • Broadcast Address: 192.168.1.191

  • Number of Usable Hosts: 62

  • NB: The 192.168.1.128 to 192.168.1.191 means 64 IP addresses

Subnet 4: Future Department (or additional use)

  • Network Address: 192.168.1.192/26

  • Gateway Address: 192.168.1.193

  • Usable IP Range for Hosts: 192.168.1.193 to 192.168.1.254

  • Broadcast Address: 192.168.1.255

  • Number of Usable Hosts: 62

  • NB: The 192.168.1.192 to 192.168.1.255 means 64 IP addresses

Summary

Each subnet has:

  • 64 IP addresses in total

  • 62 usable IP addresses for hosts

  • 1 network address (e.g., 192.168.1.0 for Subnet 1)

  • 1 broadcast address (e.g., 192.168.1.63 for Subnet 1)

Explanation

  • Network Address: Identifies the subnet. It's the first IP address in the range (e.g., 192.168.1.0 for Subnet 1 in Physiology Department).

  • Gateway Address: Typically, the first usable IP in the subnet and used by devices to communicate outside the subnet (e.g., 192.168.1.1 for Subnet 1 in Physiology Department ).

  • Usable Hosts: These are the addresses available for assignment to devices (e.g., 192.168.1.1 to 192.168.1.62 for Subnet 1 in Physiology Department).

  • Broadcast Address: The last IP address in the range, used for broadcasting messages to all devices in the subnet (e.g., 192.168.1.63 for Subnet 1 in Physiology Department).

By dividing the network into these subnets, you efficiently allocate resources and provide isolation between departments, enhancing both security and manageability.

How to Check Your IP Address and Subnet

To relate this concept to your own device, you can check your IP address and subnet information with a few simple commands. Here’s a quick guide on how to do this on different operating systems:

For Windows:

Open Command Prompt:

  • Press Win + R to open the Run dialog.

  • Type cmd and press Enter

Check IP Information:

  • Type ipconfig and press Enter.

  • Look for your network adapter (e.g., "Ethernet adapter" or "Wireless LAN adapter") to find the IPv4 Address (your device’s IP) and Subnet Mask.

Calculate the Number of Hosts:

  • Identify the subnet mask (e.g., 255.255.255.0).

  • Convert the subnet mask to CIDR notation (e.g., /24).

  • Use the formula 2^(32 - subnet bits) - 2 to find the number of hosts. For /24, the calculation is 2^(32-24) - 2 = 254 hosts.

For Linux or macOS:

Open Terminal:

  • On macOS, you can use Spotlight (Cmd + Space) and type "Terminal."

  • On Linux, use Ctrl + Alt + T or search for "Terminal" in the application menu

Check IP Information:

  • Type ifconfig (for most Linux distributions) or ip a (a more modern and universal command) and press Enter.

  • Look for your active network interface (e.g., eth0 or wlan0) to find the inet (IP address) and netmask (Subnet Mask).

Assignment:

  1. Use the steps above to find your own IP address, subnet mask, and calculate the number of hosts in your network.

  2. Share your results and any observations you make in the feedback section. If you're having trouble, feel free to reach out!

Conclusion

Subnet masking is a powerful tool in the arsenal of network administrators, allowing them to efficiently manage, secure, and optimize networks. By dividing a network into subnets, you can ensure better performance, improve security, and simplify management.

With the knowledge of how subnet masks work and how to apply them practically, you are now better equipped to handle real-world networking challenges. Whether you are setting up a small home network or managing a large corporate infrastructure, understanding subnet masking is essential for effective network management.

About Me:

I'm passionate about teaching and writing, especially on topics related to networking, cybersecurity, and tech tutorials. I'm always looking for opportunities to share knowledge, collaborate, or contribute to educational projects. If you’re interested in connecting or have an opportunity in mind, I’d love to hear from you!

Feel free to visit my portfolio and find many of my links : My Online Portfolio

Do well to also connect with me . I would love and appreciate it.

Looking forward to engaging with you.

0
Subscribe to my newsletter

Read articles from Olumide Adeola directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Olumide Adeola
Olumide Adeola

Classical | Health | Academics | Services et Solutions | Finance | Agriculture | Technology This is what my passion revolves round....