Anda di halaman 1dari 5

How to calculate a subnet mask

This guide helps you understand how to calculate a subnet mask, including understanding how a subnet
mask works, stepping you through the calculation itself, giving you handy tricks for subnetting and IP
addressing, and pointing you to a subnet calculator you can use.

How does a subnet mask work?

A subnet mask works like a filter, helping to route traffic inside a subnet. Basically, the subnet mask tells
the router which numbers it should look at and which ones it should ignore beneath the mask.

For example, when a binary mask is laid over an IP address also translated into binary, a 1 over a number
tells the router to look at the number beneath, and a 0 says to ignore the number. The subnet mask tells
a router which bits to pay attention to when calculating the network ID portion of an IP address.

Calculating subnets by hand

You can calculate IPv4 subnet masks by hand if you so desire, but it is much easier to just use a subnet
calculator. For the die hard, however, let’s walk you through IP subnetting step by step.

By default, the subnet mask for a Class C IP address class is set to 255.255.255.0, meaning that the first 3
octets (24 bits) in an IP address are used to identify the network ID, and the last octet (8 bits) are
dedicated to the host ID.

But subnetting your network by hand can be tricky. Using an online subnet calculator like the Spiceworks
Subnet Calculator can quickly help you divide your IP network into smaller subnet ranges.

That means that on this particular subnet, there are 256 possible IP addresses. How did we figure this
out? Remember that 255 is the highest number that can be represented in binary with 8 bits. To get to
255, all of the 8 bits must be set to 1, each one representing a number in decimal (1 + 2 + 4 + 8 + 16 + 32
+ 64 + 128 = 255). When you include the number zero that makes 256 possible values.
But if we had a subnet mask of 255.255.255.192, that would mean there are only 6 bits available to us
(we get 192 because the bits representing 128 and 64 are masked out). Because 63 is the highest
decimal value that can be represented with 6 binary bits (1 + 2 + 4 + 8 + 16 + 32), when you add the zero,
that makes 64 possible values.

How to calculate hosts or subnets based on the subnet mask

A quicker way to figure out how many hosts will exist on a particular subnet is to use the formula 2n-2,
where n is the number of bits available to the host ID, where 2n represents 2 raised to the nth power.
You must then subtract two from the result because 2 addresses are reserved for the network ID and
broadcast address or ID.

So in our examples above:

2^8 – 2 = 254

2^6 – 2 = 62

Subnetting a Class C Address Using the Binary Method

We will use a Class C address which takes 5 bits from the Host field for subnetting and leaves 3 bits for
defining hosts as shown in figure 1 below. Having 5 bits available for defining subnets means that we can
have up to 32 (2^5) different subnets.

It should be noted that in the past using subnet zero (00000---) and all-ones subnet (11111---) was not
allowed. This is not true nowadays. Since Cisco IOS Software Release 12.0 the entire address space
including all possible subnets is explicitly allowed.

Cisco Subnetting 1

Let's use IP address 192.168.10.44 with subnet mask 255.255.255.248 or /29.


STEP 1: Convert to Binary

Cisco Subnetting 2

STEP 2: Calculate the Subnet Address

To calculate the Subnets IP Address you need to perform a bit-wise AND operation (1+1=1, 1+0 or 0+1
=0, 0+0=0) on the host IP address and subnet mask. The result is the subnet address in which the host is
situated.

Cisco Subnetting 3

STEP 3: Find Host Range

We know already that for subnetting this Class C address we have borrowed 5 bits from the Host field.
These 5 bits are used to identify the subnets. The remaining 3 bits are used for defining hosts within a
particular subnet.

The Subnet address is identified by all 0 bits in the Host part of the address. The first host within the
subnet is identified by all 0s and a 1. The last host is identified by all 1s and a 0. The broadcast address is
the all 1s. Now, we move to the next subnet and the process is repeated the same way. The following
diagram clearly illustrates this process:

Cisco Subnetting 4
STEP 4: Calculate the Total Number of Subnets and Hosts Per Subnet

Knowing the number of Subnet and Host bits we can now calculate the total number of possible subnets
and the total number of hosts per subnet. We assume in our calculations that all-zeros and all-ones
subnets can be used. The following diagram illustrated the calculation steps.

Cisco Subnetting 5

Subnetting a Class C Address Using the Fast Way

Now let's see how we can subnet the same Class C address using a faster method. Let's again use the IP
address 192.168.10.44 with subnet mask 255.255.255.248 (/29). The steps to perform this task are the
following:

1. Total number of subnets: Using the subnet mask 255.255.255.248, number value 248 (11111000)
indicates that 5 bits are used to identify the subnet. To find the total number of subnets available simply
raise 2 to the power of 5 (2^5) and you will find that the result is 32 subnets.

Note that if subnet all-zeros is not used then we are left with 31 subnets and if also all-ones subnet is not
used then we finally have 30 subnets.

2. Hosts per subnet: 3 bits are left to identify the host therefore the total number of hosts per subnet is 2
to the power of 3 minus 2 (1 address for subnet address and another one for the broadcast address)
(2^3-2) which equals to 6 hosts per subnet.
3. Subnets, hosts and broadcast addresses per subnet: To find the valid subnets for this specific subnet
mask you have to subtract 248 from the value 256 (256-248=8) which is the first available subnet
address.

Actually the first available one is the subnet-zero which we explicitly note. Next subnet address is
8+8=16, next one is 16+8=24 and this goes on until we reach value 248. The following table provides all
the calculated information.

Note that our IP address (192.168.10.44) lies in subnet 192.168.10.40.