Subnet Masking Cheat Sheet: A Beginner's Guide to Subnetting

Steve Manjaly May 5, 2022
- 5 min read

Network engineers are constantly looking for ways to improve the security and efficiency of their IT networks. High latency can affect the user experience and security measures can have costly impacts on the organization. 

And splitting the organization’s assets into different networks instead of one single large network achieves this. It reduces network collisions and computing demands from the devices and improves efficiency and improves the user experience. Keeping the devices separate also reduces the IT security risks for your organization. 

VLANs and VXLANs are one way of doing this. 

Another way of creating smaller networks is subnetting. But keeping the subnet IDs, subnet masks, and addresses all in your head can be a bit tricky. Here’s a refresher course/cheat sheet to help you out.  

What is subnetting?

Subnetting is essentially creating smaller networks or subnetworks from a single large IP network. 

As you may be aware, an IPV4 address is composed of 32 bits, divided into a network part and a host ID. (Each bit can either be a 1 or a 0). Depending on the class of IP address, the host ID may be 8 bits (class C) to 24 bits (class A). There are Class D and Class E as well, but they’re not commonly used.  

For example, an IP address may look like 

11000001.10101000.00000001.10011000

Each octet represents a number in binary, so this translates to 

193.168.1.152 

This is a class C IP address and 193.168.1.0 is the network portion and 0.0.0.152 is the host ID. 

In this case, only 8 bits are available for the host ID, and 8 of these can only be either 1 or 0, which means we have 2^8 IP addresses available. The first and last addresses are reserved for the network address and broadcast address, so we can use only 254 addresses. 

In subnetting, we borrow bits from the host ID to create smaller networks. These bits are then used to create subnet IDs. 

For example, consider 

193.168.1.0

11000001.10101000.00000001.00000000

From this by borrowing the first digit of the host ID we can create two new subnetworks (since the bits can only be 1 or 0) leaving 7 digits for the host ID. 

Taking the above example, we can create two subnetworks 

11000001.10101000.00000001.00000000

translating to 

193.168.1.0

and

11000001.10101000.00000001.10000000

translating to

193.168.1.128

By borrowing the first two digits, we can create 4 subnetworks

11000001.10101000.00000001.00000000

translating to 

193.168.1.0

11000001.10101000.00000001.01000000

translating to

193.168.1.64

11000001.10101000.00000001.10000000

translating to

193.168.1.128

11000001.10101000.00000001.11000000

translating to 

193.168.1.192

In this case, we’ll have 6 bits for the host ID, and therefore we’ll get 2^6 - 2 or 62 host IDs per subnet (subtracting 2 for the network address and broadcast address). 

Subnetting in IPV6

Here the IP address is 8 blocks of 16 bits each, for example, 

0010000000000001:0000110110111000:1000010110100011:0000000000000000:0000000000000000:1000101000101110:0000001101110000:0111001100110100

This is usually expressed in hexadecimal format, with each block separated by a colon. 

And the above example becomes

2001:0db8:85a3:0000:0000:8a2e:0370:7334

In IPV6, there are no address classes; the last 64 bits are always used for hosts. And the 16 bits before that are used for the subnets. You’ll always have 2^16 or 65536 subnets with IPV6. 

What is subnet masking?

Now take a look at the above IP addresses. If you were presented with these IP addresses, will you be able to figure out if these were subnets or IP addresses? And if these were indeed subnets, can you figure out the host IDs and the network portions?

In the above situation where we take bits from the host ID to create subnet IDs, there’s no way for us (or the devices) to tell where the host ID begins and the subnet ID ends. This is where we use subnet masking. 

A subnet mask is used to separate the part of IP address that shows the network and the part that shows the host ID. 

So for 

11000001.10101000.00000001.00000000

or 

193.168.1.0

where the first bit of host ID is used to form the subnet ID

the subnet mask will be 

11111111.11111111.11111111.10000000

or

255.255.255.128

And for 

11000001.10101000.00000001.11000000

or 

193.168.1.192

where the first two bits of host ID is used to form the subnet ID, 

the subnet mask will be

11111111.11111111.11111111.11000000

or 

255.255.255.192

So the first subnet will be represented as

193.168.1.0 255.255.255.128

and the second example will be represented as

193.168.1.192 255.255.255.192

You can also represent them as the subnet ID, followed by ‘/’ followed by the number of 1s in the subnet mask (or the number of bits in the network portion, including the subnet ID). 

So 193.168.1.0 255.255.255.128

will be

193.168.1.0/25

And 193.168.1.192 255.255.255.192

will be

193.168.1.192/26 

What is the minimum subnet size for a particular number of hosts?

As we discussed in the above example, the more bits we have for the subnet ID, the more hosts we get. And there’s a simple formula to find the number of usable hosts based on the host bits used. 

Usable hosts = (2^n) - 2 

n = number of host bits available. 

We subtract 2 since we’ll need one each for the network address and the broadcast address. 

To find the subnet mask for the same, we need to find the number of network bits available. For this, we subtract the number of host bits from 32. (Yes we’re really breaking this down)

Or simply 

32 -  n

For example, let’s say that we need 30 hosts. 

2^3 = 8; won’t work

2^4 = 16; won’t work

2^5= 32; may work

32- 2 = we get 30 hosts

To find the subnet mask, we subtract 

32 - 5 = 27 

And the subnet mask is /27

Using an online subnetting calculator

Remembering how to calculate the subnet mask or subnet ID, finding out if two subnets are on the same network, etc are useful skills and worth practicing. But sometimes when you’re in a hurry or when you have other things in your mind, you don’t want to calculate these in your head.

An online subnetting calculator can help you out here. There are plenty of online subnetting calculators and tables. There are also plenty of apps that can help you with the same, in case you don’t want to switch tabs every now and then on your PC. 

Frequently asked questions

What is subnetting?

Subnetting is simply dividing a large network into smaller sub networks for better network performance and security. For forming subnetworks In an IPV4 network, bits from host ID are used to form subnet IDs.  In an IPV6 network, the 16 bits after the first 48 bits are used to form the subnet ID.

What is subnet masking or subnet masks?

Subnet masking or subnet masks are used to identify the network portion and the host ID of an IP network after subnetting. Subnet mask has the same number of bits as the IP address. And the bits corresponding to the network portion are all 1s and the bits corresponding to the host are all 0s. The subnet mask can also be represented by the number of bits in the network portion; for example if the network portion has 27 bits, the subnet mask is represented as /27. 

Read other articles like this : IT General, subnet masking

Evaluate InvGate as Your ITSM Solution

30-day free trial - No credit card needed

Get Started