TCP/IP Concepts   «Prev  Next»

Lesson 8Netmask Structure and Usage
ObjectiveWhat is the Structure and use of a netmask?

Netmask Structure and Usage

The netmask, also known as a subnet mask, is one of the fundamental elements of IP networking. It defines how an IP address is divided into two parts: the network identifier and the host identifier. Understanding the netmask is essential for configuring networks, designing subnets, and managing routing in both IPv4 and IPv6 environments.

From Classful to Classless Addressing

In early TCP/IP implementations, networks followed a classful addressing scheme:

ClassDefault Netmask
Class A255.0.0.0
Class B255.255.0.0
Class C255.255.255.0

Each class reserved a fixed number of bits for the network portion. However, this approach led to address waste and limited scalability. Modern networks use CIDR (Classless Inter-Domain Routing), which replaces rigid class boundaries with prefix lengths (e.g., /24, /20). CIDR allows variable subnet sizes and more efficient use of IP space.

Structure of a Netmask

A netmask is a 32-bit binary number that separates the network and host portions of an IP address. The bits set to 1 mark the network portion, and those set to 0 mark the host portion. For example:


IP Address:   192.168.1.25
Netmask:      255.255.255.0
Binary form:  11111111.11111111.11111111.00000000
Network part: 192.168.1
Host part:    .25

The count of 1 bits in the mask determines the prefix length. Thus, 255.255.255.0 corresponds to /24 since 24 bits are reserved for the network portion.

Using a Netmask: Subnetting and Supernetting

  1. Identifying Network and Host Portions: Every device uses its netmask to determine which addresses are part of its local network and which must be reached via a router. Example: a host with 192.168.10.14/24 recognizes that 192.168.10.0 – 192.168.10.255 are local addresses.
  2. Subnetting: Network administrators divide a large network into smaller, more manageable subnets by extending the netmask. For instance, splitting 192.168.1.0/24 into four subnets uses /26 masks:
    
    192.168.1.0/26     → hosts 1–62
    192.168.1.64/26    → hosts 65–126
    192.168.1.128/26   → hosts 129–190
    192.168.1.192/26   → hosts 193–254
          
    Subnetting improves performance and security by isolating traffic.
  3. Supernetting (Route Aggregation): The opposite of subnetting, supernetting merges smaller networks into a larger one by reducing the prefix length. Example: combining four /24 networks (192.168.0.0–192.168.3.255) into one 192.168.0.0/22 aggregate simplifies routing tables and reduces overhead.
  4. Efficient IP Management: Modern Linux systems, routers, and firewalls use CIDR-based netmasks for flexible assignment and routing efficiency. This approach supports complex topologies without relying on outdated classful rules.

Common Netmask and Prefix Length Reference

Prefix Netmask Usable Hosts Typical Use
/30255.255.255.2522Point-to-point links
/29255.255.255.2486Small subnets (firewall segments)
/24255.255.255.0254Standard LAN
/16255.255.0.065,534Enterprise campus networks

IPv6 Prefix Lengths

In IPv6, the concept of a netmask still exists but is expressed exclusively with prefix lengths. IPv6 addresses typically use a /64 prefix for LANs, reserving 64 bits for network routing and 64 bits for interface identifiers (derived from MAC addresses or randomly generated for privacy). Example:


IPv6 Address: 2001:db8:abcd:12::1/64
Network ID:   2001:db8:abcd:12::

IPv6 eliminates broadcast traffic entirely, replacing it with multicast mechanisms for efficiency and scalability.

Linux Commands for Netmask and Routing Verification


# Display all network interfaces and prefixes
ip addr show

# View routing tables with netmask or CIDR notation
ip route show

# Add an address with a specific netmask
sudo ip addr add 10.42.1.10/24 dev eth0

# Add a static route
sudo ip route add 10.42.0.0/16 via 10.42.1.1

Security and Legacy Considerations


Summary

A netmask identifies the boundary between the network and host portions of an IP address. Modern networks use CIDR prefixes instead of rigid class-based masks, enabling flexible subnetting and efficient routing. Whether you’re designing a small LAN or configuring routes for a hybrid cloud, understanding how netmasks define network scope is essential for stable, scalable connectivity.


SEMrush Software 8 SEMrush Banner 8