The Role Of The Subnet Mask (Free Preview)

You must first complete Decimal To Binary Conversion before viewing this Lesson
This is a preview lesson. Please purchase the course to access all lessons.

The subnet mask enables us to determine what is the network ID for a given IPv4 address. We learned there are two components in a 32-bit IPv4 address. The two components are

  1. Network ID
  2. Host ID

From the 32 bit IPv4 address a portion of bits are reserved for defining the network ID. This is the network portion. Then the remaining portion of bits are used to define the host IDs. This portion of bits are known as the host portion. For all hosts in the same network the network portion bit pattern is identical among all hosts in the same network. However, the host portion bit pattern MUST be unique to each host in the same network.



Figure The structure of an IPv4 address


Let’s look at /24 and /24. These are two IPv4 addresses that are in the same network. The /24 is the subnet mask. What the /24 is expressing is from left to right the first 24 bits are reserved for the network portion. This method of representing the subnet mask is known as the slash notation or prefix length. The /24 can also be expressed as This is the dotted decimal subnet mask. The /24 is the same as

As seen in the figures below, the address bits that have a corresponding mask bit (The row labelled “Binary Subnet Mask”) set to 1 represent the network portion. If you count the number of 1 bits it is equal to 24. That’s what was expressed by /24.

Any address bits that have a corresponding mask bit set to 0 represent the host portion. The Host portion consists the range of bits we can use to assign a Host ID.


We can observe that both the IPv4 addresses are having an identical network portion bit pattern. In other words they have the same network ID. The dashed line marks the boundary between where the network portion ends and the host portion begins.

However, when we examine the host portions they are not identical. This is to say they are two different host IDs. The conclusion is these are two different IPv4 addresses in the same network.



Figure Comparing the IPv4 address and the Subnet Mask of


Figure Comparing the IPv4 address and the Subnet of


As seen above, given a particular IPv4 address, the means by which we identify the Network ID and Host ID is looking at the subnet mask. Also, the subnet mask instructs a TCP/IP host which portion of the 32 bits identify the network portion and which identifies the host.



How to determine the network ID using subnet mask and logical AND

Once we have the binary representation of the IPv4 address and the subnet mask, it is fairly simple to figure out the Network ID.

The method:

Moving from left to right logically AND the IPv4 address bit with the corresponding subnet mask bit, bit by bit.


The Logical AND

The logical AND works as follows.

1 AND 1 = 1

0 AND 1 = 0

0 AND 0 = 0

1 AND 0 = 0

This is very simple. Just remember 1 AND 1 produces 1 and all other combinations produce 0.


To illustrate how AND is used to discover a network address IPv4 address and subnet mask from our earlier example.



Figure AND operations & Resulting Network Address


The resulting network ID is Therefore, is on network


Sample of various subnet masks


Decimal Subnet Mask 32-bit Binary Address Prefix Length 11111111.00000000.00000000.00000000 /8 11111111.11111111.00000000.00000000 /16 11111111.11111111.11111111.00000000 /24 11111111.11111111.11111111.10000000 /25 11111111.11111111.11111111.11000000 /26 11111111.11111111.11111111.11100000 /27 11111111.11111111.11111111.11110000 /28 11111111.11111111.11111111.11111000 /29 11111111.11111111.11111111.11111100 /30


Table Subnet mask in Dotted decimal, binary and prefix length


Back to: CCNA Routing and Switching 200-125 > IPv4 Addressing