When it comes to configuring networks in Linux, understanding IP addressing is the foundational baseline you cannot move forward without. You can blindly copy interface parameters, but it is always better to grasp the underlying subnet logic once and for all.

Let us break down how IP addresses are structured and how subnet masks actually operate.


IP Addresses#

To us, an IP address looks like four numbers separated by dots (for example, 172.29.35.1). However, the system perceives it as a solid 32-bit string of ones and zeros.

Each address consists of two parts:

  • Network ID: a common identifier shared by all devices within the same segment.
  • Host ID: a unique identifier assigned to a specific computer or server.

The boundary between these two parts is defined by the subnet mask.

How a Subnet Mask Works#

A mask is a similar 32-bit block where ones indicate the network portion and zeros indicate the host portion. The ones in a mask always run consecutively, without any gaps.

Binary Example#

Let us take a popular mask: 255.255.255.0. In binary format, it looks like this:

11111111.11111111.11111111.00000000

Here we can see 24 ones.

Prefix Notation (CIDR)#

Instead of writing out the full 255.255.255.0 format, a shorthand notation is often used: /24. This number simply represents the total count of ones in the mask.

  • /24 means 24 ones and 8 zeros (24 + 8 = 32).
  • /30 means 30 ones and 2 zeros.

Network Calculation: The AND Operation#

To determine the network address, the operating system performs a bitwise AND operation between the IP address and the subnet mask.

The AND Rule: The result is 1 only if both bits are 1. In all other cases, it evaluates to 0.

Mathematical Example#

Given the IP address 192.168.1.15 and the mask 255.255.255.0 (/24).

  1. IP in binary: 11000000.10101000.00000001.00001111
  2. Mask in binary: 11111111.11111111.11111111.00000000
  3. Result (Network): 11000000.10101000.00000001.00000000 (192.168.1.0)

Host Count, Calculation Formula#

To determine how many devices a subnet can accommodate, you need to count the number of zeros in the mask. Let us denote this number as n.

The formula for the number of available host addresses is:

2^n - 2

We subtract two addresses because the first address (where the host portion consists entirely of zeros) is the Network Address, while the last address (where the host portion consists entirely of ones) is the Broadcast Address.


Common Subnet Masks#

Prefix Host Capacity Purpose
/30 2 Point-to-point connections (e.g., between two routers)
/24 254 Standard for small office or home networks (SOHO)
/22 1022 Large segments for data centers or corporate networks

A Few Practical Tips#

  • Use ipcalc or our IPv4 Calculator. This utility is an indispensable helper in any GNU/Linux distribution. Run ipcalc 10.0.0.1/22, and it will instantly display the complete network layout in a clean, human-readable format.
  • Plan for the future. If you are designing a subnet for a department that currently has 10 employees, do not restrict yourself to a /28 mask (14 hosts). It is always wiser to leave room for scaling.
  • Avoid overlaps. When configuring VPNs or connecting remote offices, ensure that local network ranges do not overlap; otherwise, routing will break down entirely.