In the vast world of networking, the effective management and segmentation of networks are essential for optimal data transmission and security. Network masks, also known as subnet masks, play a pivotal role in dividing IP addresses into network and host portions. In this chapter, we will delve into the concept of network masks, explore their significance, and provide practical examples to deepen your understanding.

At its core, a network mask is a binary pattern that helps differentiate the network and host portions of an IP address. By combining an IP address with a network mask, network administrators can determine which part represents the network and which part represents the hosts within that network.
Network masks can be represented as octets, such as `255.255.255.0`, or as the number of bits set to 1, such as `24`. Both `172.16.32.32/255.255.255.0` and `172.16.32.32/24` represent the same IP and network.

### Binary representation

Network masks are typically represented using the dotted decimal notation, making them easily readable. In this notation, a network mask consists of a series of 1s followed by a series of 0s. The consecutive 1s signify the network portion, while the subsequent 0s indicate the host portion. For instance, a network mask of 255.255.255.0 has 24 1s, representing a network size of 24 bits.

To determine the network and host portions of an IP address, we perform a bitwise AND operation between the IP address and the network mask. The result of this operation yields the network portion. Let's consider an example to illustrate this process:

#### Example 1

Performing the bitwise AND operation:
Network portion: 11000000.10101000.00000000.00000000
In this example, the network portion is 192.168.0.0, while the host portion is 0.0.0.101.

#### Example 2

Performing the bitwise AND operation:
Network portion: 00001010.00000000.00000000.00000000
In this example, the network portion is 10.0.0.0, while the host portion is 0.0.0.5.