Hostwinds Blog

Search results for:


What is a Subnet Mask? Featured Image

What is a Subnet Mask?

by: Hostwinds Team  /  September 17, 2024


If you've ever worked with networking, you've likely come across the term "subnet mask." But what exactly is it, how does it work, and why is it important?

Let's find out…

What is a Subnet Mask?

A subnet mask is a 32-bit number that divides an IP address into two parts: the network portion and the host portion. This separation is used to determine which part of the address refers to the overall network and which part identifies specific devices within that network.

How Subnet Masks Work

A subnet mask is used in conjunction with an IP address to define the boundaries of your network. For example, the common subnet mask 255.255.255.0 translates to the first 24 bits of the IP address being reserved for the network, while the last 8 bits are reserved for hosts within that network.

Think of it as dividing a postal address into a zip code (network) and a home address (host). The subnet mask defines how much of the IP address is used for the network (the zip code) and how much is used for individual devices (house numbers).

Why Subnet Masks Matter in Networking

The importance of subnet masks can be broken down into three core categories:

  1. Efficient Network Management: They allow large networks to be divided into smaller, manageable subnets. This reduces congestion and improves security by limiting the broadcast domain.
  2. IP Addresses Conservation: Particularly important for IPv4 networks, subnetting helps make better use of limited IP address spaces. By segmenting networks logically, fewer public IP addresses are needed.
  3. Improved Security: Subnet masks can isolate sensitive parts of a network, making it harder for unauthorized access or malicious activities to affect the entire network.

Ultimately, subnet masks are valuable for conserving IPv4 addresses, as they allow for more efficient use of limited IP resources. They are also particularly useful for isolating sensitive areas of a network, and adding extra layers of protection against unauthorized access or potential threats.

The Basics of IP Addresses and Subnet Masks

IPv4 addresses consist of four numbers (called octets) separated by periods, such as 192.168.1.1. Each octet is made up of 8 bits, and since there are four octets, this gives a total of 32 bits to work with in an IP address. These bits are divided between the network portion (which identifies the overall network) and the host portion (which identifies individual devices on that network).

To make this distinction, we use a subnet mask. The subnet mask is also composed of four octets, but it is structured using 1's and 0's. Here's how it works:

  • The 1's represent the network portion of the IP address.

  • The 0's represent the host portion, which identifies specific devices within the network.

Example:

  • IP Address: 192.168.1.1

  • Subnet Mask: 255.255.255.0

In this case:

  • The first three octets (192.168.1) represent the network.

  • The final octet (the "1") identifies the specific host or device within that network.

So, if you're on the 192.168.1 network, each device will have a unique number in the last octet, such as 192.168.1.2, 192.168.1.3, and so on.

Using CIDR Notation

Another popular method for defining subnet masks is called CIDR, which stands for Classless Inter-Domain Routing. CIDR notation offers a simpler shorthand way to write subnet masks compared to the traditional format.

Instead of writing out the entire subnet mask, CIDR notation allows you to use a compact format by appending a slash (/) followed by a number to the IP address. This number represents the number of bits used for the network portion of the address.

For example:

  • Traditional Subnet Mask: 255.255.255.0

  • CIDR Notation: 192.168.1.0/24

In this example, 192.168.1.0/24 means that the first 24 bits of the IP address are used to identify the network, which is the same as the traditional subnet mask 255.255.255.0. ​

Different Classes of Subnet Masks

Subnet masks can be used across 3 of the 5 traditional IPv4 classes, with each class designed to accommodate different size networks.

  • Class A: Used for very large networks with over 16 million addresses (Subnet mask: 255.0.0.0).

  • Class B: Mid-sized networks with up to 65,000 addresses (Subnet mask: 255.255.0.0).

  • Class C: Smaller networks, commonly used in home or small business networks, supporting up to 254 devices (Subnet mask: 255.255.255.0).

How to Calculate a Subnet Mask

Calculating a subnet mask can be done manually or with the help of subnet calculators.

Manual Calculation

For the manual portion, you need to use a bit of binary math. Here's a quick breakdown of the process:

1.Convert to Binary: First, both the IP address and subnet mask are converted into binary form. This just means turning the numbers into a series of 0s and 1s.
For example:

  • IP Address: 192.168.1.5 becomes 11000000.10101000.00000001.00000101
  • Subnet Mask: 255.255.255.0 becomes 11111111.11111111.11111111.00000000

2. Use Bitwise AND Operation: Next, you perform a bitwise AND operation. This means you compare each bit of the IP address with the corresponding bit of the subnet mask, and apply the AND rule:

  • 1 AND 1 = 1
  • 1 AND 0 = 0
  • 0 AND 1 = 0
  • 0 AND 0 = 0

So, you'll end up with a new binary number where only the bits that matched (1 AND 1) are set to 1.

3. Convert Back to Decimal: Finally, convert the result back to decimal form to get the network address.
Using our example:

  • The binary result of the bitwise AND operation is 11000000.10101000.00000001.00000000
  • This converts back to decimal as 192.168.1.0

Network Address: 192.168.1.0

Once you have the network address, it helps in identifying all devices on the same subnet. Devices within the same subnet will share the same network portion of their IP addresses.

For instance, if another device has the IP address 192.168.1.10 and the same subnet mask, it will also fall within the 192.168.1.0 network.

Automated Calculations

Subnet mask calculators simplify the subnetting process by automating the calculations. You can input an IP address and either the number of subnets or required hosts, and the tool will generate the necessary information, such as the subnet mask, network address, broadcast address, and available IP range.

Here are some popular subnet calculators:

  • SolarWinds Advanced Subnet Calculator: This tool supports both CIDR and classful subnetting for IPv4 and IPv6 addresses. It quickly computes the subnet mask and IP address ranges

  • Spiceworks Subnet Calculator: Another free and easy-to-use tool that can calculate subnet masks and address ranges, and provide detailed information on IP allocation​

  • IP Calculator by SubnetOnline: This tool offers advanced features like calculating wildcard masks and providing detailed subnetting results. It is useful for both IPv4 and IPv6 addresses.

Subnet vs. Subnet Mask

Subnets and subnet masks are closely related but serve distinct purposes.

A subnet is like a smaller section within a larger network. It shares the larger network IP address but has its own subnet address and is commonly used to group related devices.

A subnet mask, on the other hand, defines the boundaries of these sections by indicating which part of an IP address is used for the network and which part is for the devices.

In short, the subnet breaks the network into smaller parts, while the subnet mask specifies how those parts are divided.

IPv4 vs. IPv6 Subnet Masks

Both IPv4 and IPv6 use subnet masks to divide networks, but the methods differ due to the size and structure of each protocol.

  • IPv4 Subnet Masks: IPv4 addresses are 32 bits long and use subnet masks like 255.255.255.0 (or /24 in CIDR notation) to separate the network and host portions. This allows for around 4.3 billion addresses, which are now running out due to the rapid growth of the internet.

  • IPv6 Subnet Masks: IPv6 addresses, on the other hand, are 128 bits long, vastly expanding the available address space. Instead of traditional subnet masks, IPv6 uses prefix lengths, such as /64, which is commonly used in most network configurations. The larger address pool eliminates the need for NAT (Network Address Translation), allowing for direct IP communication between devices.

Written by Hostwinds Team  /  September 17, 2024