What is a subnet mask?
A subnet mask is a 32-bit number that separates an IPv4 address into two parts: the network portion and the host portion. It tells devices which part of an IP address identifies the network and which part identifies a specific device (host) on that network. Routers and switches use this mask to decide whether a destination is local or must be forwarded to another network.
IPv4 addresses in brief
An IPv4 address is written as four decimal octets separated by dots, for example 192.168.1.10. Each octet represents 8 bits, so the full address is 32 bits. The subnet mask uses the same format β for instance 255.255.255.0 β where 255 means "this bit belongs to the network" and 0 means "this bit belongs to the host."
CIDR notation explained
CIDR (Classless Inter-Domain Routing) notation is a compact way to write a subnet mask. Instead of writing 255.255.255.0, you write /24 after the IP address. The number after the slash is the count of consecutive 1-bits in the mask, starting from the left. So /24 means the first 24 bits are network bits and the remaining 8 bits are host bits.
Network bits vs host bits
In a /24 network, the first three octets (192.168.1) are the network bits and the last octet is the host bits. Changing the host bits gives you different devices on the same network; changing the network bits means you are on a different subnet. The boundary between network and host bits is determined entirely by the CIDR prefix.
The classic /24 example
For 192.168.1.0/24:
- β’ Subnet mask:
255.255.255.0 - β’ Network address:
192.168.1.0 - β’ Broadcast address:
192.168.1.255 - β’ First usable host:
192.168.1.1 - β’ Last usable host:
192.168.1.254 - β’ Total addresses: 256
- β’ Usable hosts: 254
Network vs broadcast address
The network address is the lowest address in a subnet β all host bits are 0. It identifies the subnet itself and cannot be assigned to a device. The broadcast address is the highest address β all host bits are 1. Packets sent to the broadcast address are delivered to every device in that subnet. Neither address is usable for a normal host.
Usable hosts and special cases
For most prefixes, the number of usable hosts is 2^(host bits) β 2 because the network and broadcast addresses are reserved. Two exceptions exist:
- β’ /31 β point-to-point links. Both addresses are usable, giving 2 hosts with no network or broadcast address.
- β’ /32 β a single host route. The address refers to one specific device; there is no host range.
Wildcard mask
A wildcard mask is the bitwise inverse of the subnet mask. Where the subnet mask has a 1, the wildcard has a 0, and vice versa. Wildcard masks are used in Cisco ACLs and OSPF configurations to match ranges of addresses. For /24 the subnet mask is 255.255.255.0 and the wildcard is 0.0.0.255.
Practical examples
10.0.0.0/8
Large private network β 16,777,214 usable hosts. Common in enterprises and cloud VPCs.
172.16.0.0/12
Private range β 1,048,574 usable hosts. Often used for medium-sized internal networks.
192.168.1.0/24
Home or small office β 254 usable hosts. The most common residential subnet.
203.0.113.5/32
Single host route β used for loopback interfaces and host-specific routing entries.