Fundamentals6 min read

What is a Subnet Mask?

A subnet mask is a 32-bit number that divides every IP address into a network portion and a host portion. Understanding subnet masks is the foundation of all IP networking.

What is a Subnet Mask?

A subnet mask is a 32-bit number used in IPv4 networking to determine which portion of an IP address refers to the network and which portion refers to the individual host (device). Every IPv4 address has an associated subnet mask that makes IP routing possible.

Without a subnet mask, a router or device cannot determine whether a destination IP address is on the local network (reachable directly) or on a remote network (must be forwarded to a gateway). The subnet mask answers this question by separating the IP address into two parts.

Binary Representation

At its core, a subnet mask is a 32-bit binary number consisting of a run of 1s followed by a run of 0s. The 1-bits indicate the network portion and the 0-bits indicate the host portion. For example:

11111111.11111111.11111111.00000000
└─────────── 24 ones ───────────┘└── 8 zeros ──┘

This binary mask means the first 24 bits of any IP address identify the network, and the last 8 bits identify the host within that network.

Dotted-Decimal Notation

Because binary is hard to read, subnet masks are typically written in dotted-decimal notation — the same format as IPv4 addresses. Each 8-bit group (octet) is converted from binary to a decimal number:

Binary OctetDecimal Value
11111111255
11111110254
11111100252
11111000248
11110000240
11100000224
11000000192
10000000128
000000000

So the binary mask above — 24 ones followed by 8 zeros — becomes 255.255.255.0 in dotted-decimal.

CIDR Notation

CIDR (Classless Inter-Domain Routing) notation is an even more compact way to express a subnet mask. Instead of writing the full mask, you simply write the number of 1-bits (the prefix length) after a slash:

192.168.1.0/24   ← IP address + prefix length
                ↑
         24 bits = network portion

This is exactly equivalent to 192.168.1.0 with subnet mask 255.255.255.0. CIDR notation is standard in modern networking, cloud platforms (AWS, GCP, Azure), and all network documentation.

Network vs Host Bits

Applying a subnet mask to an IP address involves a bitwise AND operation. The result identifies the network address — the base address of the subnet that all hosts share:

IP address:    11000000.10101000.00000001.01100100  (192.168.1.100)
Subnet mask:   11111111.11111111.11111111.00000000  (255.255.255.0)
               ─────────────────────────────────────
Network addr:  11000000.10101000.00000001.00000000  (192.168.1.0)

The broadcast address is found by setting all host bits to 1:

Broadcast:     11000000.10101000.00000001.11111111  (192.168.1.255)

The usable host range is everything between the network address and broadcast address: 192.168.1.1 through 192.168.1.254 — giving 254 usable hosts.

Common Subnet Masks

CIDRSubnet MaskUsable HostsCommon Use
/8255.0.0.016,777,214Class A (ISP blocks)
/16255.255.0.065,534Class B (large orgs)
/24255.255.255.0254Class C (home/office)
/28255.255.255.24014Cloud VPC subnets
/30255.255.255.2522Point-to-point links
/32255.255.255.2551Single host route

How to Calculate a Subnet Mask

You can calculate a subnet mask manually by following these steps:

  1. Decide on the CIDR prefix length (e.g. /24).
  2. Write 32 binary bits: place 1s for the first N bits (the prefix length), then 0s for the remaining bits.
  3. Group the 32 bits into four 8-bit octets.
  4. Convert each octet from binary to decimal.

Alternatively, use our free netmask calculator — enter any IP address and CIDR prefix and it instantly computes the subnet mask, network address, broadcast address, wildcard mask, host range, and more.