Press "Enter" to skip to content

How to Calculate Subnet Mask from IP Address

In a world brimming with articles on subnetting, I’ve ventured to craft a comprehensive guide entitled “How to Calculate Subnet Masks from IP Addresses, Step by Step.” It’s a practical roadmap born from real-world subnetting experience, and it’s here to demystify this intimidating topic once and for all.





For a broader understanding of subnetting, you can dive into Cisco’s extensive resources on the subject.
You can read more on the subject broadly from Cisco’s website here.

Step by step guide to IP Subnetting Video

Below is a simple 6 step by step method I use to perform subnetting calculations.

Let us look at this question below;

1: You have been given an IP Address 10.20.4.13/29 and been asked to find out the following pieces;

  1. Subnet Address
  2. First Valid Host Address
  3. Last Valid Host Address
  4. Broadcast Address
  5. Subnet Mask

How to Calculate Subnet Mask from IP Address Step by Step

Before we attempt this question, let us understand that each bit in an IPv4 subnet mask corresponds to a specific value based on powers of 2. These values are represented by the following sequence:

– 128
– 64
– 32
– 16
– 8
– 4
– 2
– 1

Each bit’s position in the subnet mask corresponds to one of these values, with the leftmost bit being the highest value (128) and the rightmost bit being the lowest value (1).

Here’s how it works:

The leftmost bit in an 8-bit subnet mask, when turned on (set to 1), represents a value of 128.
– The second leftmost bit, when turned on, represents a value of 64.
– The third leftmost bit represents 32.
– The fourth leftmost bit represents 16.
– The fifth leftmost bit represents 8.
– The sixth leftmost bit represents 4.
– The seventh leftmost bit represents 2.
The rightmost bit, when turned on, represents a value of 1.

By combining these bits in various combinations (turning them on or off), you can create different subnet mask values that allow you to define the network and host portions of an IP address. For example, a subnet mask of 255.255.255.0 (or /24 in CIDR notation) means that the leftmost 24 bits are used for the network, and the rightmost 8 bits are used for hosts within that network. This allows for up to 256 host addresses (2^8) within that subnet.

Let us do it the hard way;

The given IP Address is 10.20.4.13/29. In IPv4, the subnet mask is represented as four 8-bit octets, so the subnet mask 255.255.255.255 is represented in binary as:

11111111.11111111.11111111.11111000

In CIDR notation, “/29” means that the leftmost 29 bits are used for the network portion of the address, leaving 3 bits for host addresses within the subnet.

To calculate the subnet mask:

Start with the binary representation of the subnet mask: 11111111.11111111.11111111.11111000.

Convert each octet to decimal: 11111111 = 255, 11111111 = 255, 11111111 = 255, 11111000 = 248.

The correct subnet mask is 255.255.255.248

With the above step, we now have a real understanding of how to calculate the Subnet Mask from a Network Prefix.

Now let us use a simpler or perhaps call it the easier way to calculate the same below;

Step 1: Find Subnet Number
Subtract the prefix number from /32: 32-29 = 3.
Calculate the subnet mask: 8 Bits – 3 Bits = 5 Bits (Network Bits Turned On).
You might wonder why 8 bits? Well, each octet requires 8 bits for a subnet mask.

To visualize this:

128 64 32 16 8 4 2 1
1 1 1 1 1 0 0 0
128 + 64 + 32 + 16 + 8 = 248
Subnet Mask = 255.255.255.248
Subnet Mask = 255.255.255.248

Step 2: Find Subnet Size
Raise 2 to the power of deduction (8-3 = 5 bits). Let’s denote these bits as ‘n’:
2^n = Subnet Size
2^5 = Subnet Sizes for each subnet.
2 * 2 * 2 = 8

Note: 8 represents the block size for the subnet. For instance, the increments will be 0, 8, 16, 32, 40, and so forth

Step 3: Find Broadcast Address
Subnet Size – 1
(2^n) – 1 = Broadcast Address
(2^3) – 1 = (8-1) = 7

Step 4: Locate IP Address Subnet
Identify the subnet block for the IP Address:
Where does the address 10.20.4.13/29 fall within the increments 0, 8, 16, 32, 40?
13 falls between 8 and 16, placing it within the valid host range of the subnet 10.20.4.8/29.

Step 5: Calculate Valid Hosts | How to calculate number of hosts in the subnet
2**n – 2 = Valid Host Range
2**3 – 2 = (8-2) = 6

Answer for question now is as follows;

Subnet Address: 10.20.4.8/29
Min Host Address: 10.20.4.9/29
Max Host Address: 10.20.4.14/29
Broadcast Address: 10.20.4.15/29

There you have it. A simple 6 step by step guide to subnetting effectively.

Variable Length Subnets Mask Table

Prefix size Network mask Usable hosts per subnet
/1 128.0.0.0 2,147,483,646
/2 192.0.0.0 1,073,741,822
/3 224.0.0.0 536,870,910
/4 240.0.0.0 268,435,454
/5 248.0.0.0 134,217,726
/6 252.0.0.0 67,108,862
/7 254.0.0.0 33,554,430
Class A
/8 255.0.0.0 16,777,214
/9 255.128.0.0 8,388,606
/10 255.192.0.0 4,194,302
/11 255.224.0.0 2,097,150
/12 255.240.0.0 1,048,574
/13 255.248.0.0 524,286
/14 255.252.0.0 262,142
/15 255.254.0.0 131,070
Class B
/16 255.255.0.0 65,534
/17 255.255.128.0 32,766
/18 255.255.192.0 16,382
/19 255.255.224.0 8,190
/20 255.255.240.0 4,094
/21 255.255.248.0 2,046
/22 255.255.252.0 1,022
/23 255.255.254.0 510
Class C
/24 255.255.255.0 254
/25 255.255.255.128 126
/26 255.255.255.192 62
/27 255.255.255.224 30
/28 255.255.255.240 14
/29 255.255.255.248 6
/30 255.255.255.252 2
/31 255.255.255.254 0
/32 255.255.255.255 0
    Related Posts:

How to connect GNS3 to a Physical Network Step by Step