A subnet mask is a pattern of bits that can be used to isolate specific portions of an Internet Protocol (IP) address. When it is applied to an IP address, the network interface's host address and network routing prefix are produced. The routing prefix is also known as the subnet or subnetwork. Subnet masks are used by network software and hardware to isolate and manage portions of the network.
When a subnet mask is logically ANDed or added with a network interface's IP address, the result is the starting address of the subnet that interface belongs to. The remaining part of the IP network address is the interface's host identifier. An IP Version 4 (IPv4) subnet mask is usually expressed by four octets in dotted decimal notation. As an example, one can consider a 32-bit IP address of 220.127.116.11 with a mask of 255.255.255.0. In this case, the subnet starting address or routing prefix is 18.104.22.168, and the host interface identifier is 5.
A routing prefix is usually expressed in Classless Inter-Domain Routing (CIDR) notation. This entails following the prefix with a slash and the number of significant bits in the prefix. For example, a subnet mask of 255.255.255.0 has 24 significant bits—all ones in this case. If this subnet mask is applied to IPv4 address 22.214.171.124, the resulting prefix in CIDR notation is 126.96.36.199/24. CIDR notation is also used with IP Version 6 (IPv6) addresses.
In IPv4 networks, all addresses with the same routing prefix are on the same subnet. They are usually on the same link or physical network behind a single router. The subnet can consist of multiple network segments, bridges and switches, however. IP packets destined for a different routing prefix are forwarded by the router attached to the current routing prefix. In IPv6 networks, addresses with identical routing prefixes are not necessarily on the same link.
The concept of a subnet mask was introduced in the early 1990s along with CIDR. Before that, the four high-order bits of an IP address determined which class of addresses it belonged to. The class determined the number of bits in the routing prefix and the host identifier, as well as the subnet starting and ending addresses. No subnet mask was needed because the IP address implied all the necessary information by itself. This type of architecture is known as a classful network.
The process of utilizing a subnet mask to divide a network is known as subnetting. With limited address space available in IPv4 networks, subnetting can be used to efficiently organize larger networks. IPv6 networks provide vast address spaces in comparison. IPv6 subnets are more often used to separate local networks from the Internet or to organize networks on a worldwide scale.