# How to calculate IPv4 subnet masks

Calculating IPv4 subnet masks is a crucial skill for network administrators and IT professionals alike. In this blog post, we will discuss the process of calculating IPv4 subnet masks using binary and decimal notation, and provide a step-by-step guide to performing subnetting calculations for various network scenarios.

## What is a Subnet Mask?

A subnet mask is a 32-bit number used in IPv4 networks to distinguish the network prefix and host identifier portions of an IP address. The network prefix identifies the specific network, while the host identifier identifies a device within that network. Subnet masks help define the structure of IP addresses and facilitate efficient routing within and between networks.

## Binary and Decimal Notation

IPv4 addresses and subnet masks consist of 32 bits, which can be represented in both binary and decimal notation. Binary notation uses 1's and 0's to represent each bit, while decimal notation groups the bits into four octets and converts each octet into a decimal number between 0 and 255. Understanding binary and decimal notation is essential for calculating subnet masks and performing subnetting tasks.

1. Determine the required number of network bits: Assess the network's requirements to determine the appropriate number of network bits. This will depend on factors such as the number of subnets and the size of each subnet.
2. Convert network bits to binary: Fill the required number of network bits with 1's, followed by 0's for the remaining bits. This binary number will represent the subnet mask.
3. Convert binary to decimal: Split the binary number into four octets and convert each octet into its decimal equivalent. The resulting decimal number is the subnet mask in dotted-decimal notation.

For example, if a network requires a /26 subnet mask (26 network bits), the subnet mask in binary notation would be 11111111.11111111.11111111.11000000. Converting each octet to decimal results in a subnet mask of 255.255.255.192.

## Subnetting Scenarios

Here are some common subnetting scenarios and how to calculate the subnet masks for each:

### Scenario 1: Dividing a network into equal-sized subnets

To divide a network into equal-sized subnets, determine the number of subnets required, and then calculate the subnet mask:

1. Calculate the number of subnet bits: Use the formula 2n ? number of subnets, where n is the number of subnet bits.
2. Determine the network bits: Add the number of subnet bits to the original network bits of the IP address class (A, B, or C).

### Scenario 2: Allocating a specific number of hosts per subnet

To allocate a specific number of hosts per subnet, follow these steps:

1. Calculate the number of host bits: Use the formula 2n - 2 ? number of hosts, where n is the number of host bits. The subtraction of 2 accounts for the network and broadcast addresses, which cannot be assigned to hosts.
2. Determine the network bits: Subtract the number of host bits from 32.