What is a Subnet Mask?
A subnet mask is a 32-bit number that divides an IP address into network and host portions. It works by masking (hiding) the network portion of an IP address, leaving only the host portion visible for local network operations. The subnet mask determines which part of an IP address identifies the network and which part identifies the specific device (host) on that network.
Subnet masks are written in the same dotted-decimal notation as IP addresses, such as 255.255.255.0. In binary, a subnet mask consists of consecutive 1s followed by consecutive 0s. The 1s represent network bits, and the 0s represent host bits. For example, 255.255.255.0 in binary is 11111111.11111111.11111111.00000000, indicating 24 network bits and 8 host bits. For complete subnet calculations, use our comprehensive subnet calculator.
Key Concept
The subnet mask determines network size: more 1s (longer prefix) means smaller networks with fewer hosts; fewer 1s (shorter prefix) means larger networks with more hosts. A /24 mask allows 254 hosts, while a /28 mask allows only 14 hosts.
How to Use the Subnet Mask Calculator
Our subnet mask calculator offers three different calculation modes to handle various scenarios:
Mode 1: CIDR to Subnet Mask
Enter a CIDR prefix length (0-32) to instantly see the corresponding subnet mask in dotted-decimal notation. This is useful when you have a network specification like /24 and need to configure a device that requires the full subnet mask format. The calculator shows 255.255.255.0 for /24, 255.255.255.128 for /25, and so on.
Mode 2: Required Hosts to Subnet Mask
Enter the number of hosts you need to support, and the calculator determines the smallest subnet mask that accommodates that requirement. This mode is essential for network planning when you know how many devices need IP addresses but aren't sure which mask to use. The calculator recommends the optimal mask while showing exactly how many usable addresses it provides.
Mode 3: Subnet Mask Converter
Enter a subnet mask in dotted-decimal format to convert it to CIDR notation and see the corresponding wildcard mask. This is particularly helpful when working with different network devices that use different notation formats. For additional conversion options, try our netmask to CIDR converter.
Understanding Subnet Mask Formats
Dotted Decimal Notation
The most common format displays the subnet mask as four decimal numbers separated by dots (e.g., 255.255.255.0). Each number represents 8 bits and ranges from 0 to 255. Valid subnet masks in this format always have values that represent consecutive 1s in binary: 0, 128, 192, 224, 240, 248, 252, 254, and 255.
CIDR Notation
CIDR (Classless Inter-Domain Routing) notation represents the subnet mask as a prefix length following a forward slash (e.g., /24). The number indicates how many leading bits are set to 1 in the subnet mask. This compact notation is widely used in modern networking and is equivalent to the dotted-decimal format. Our CIDR calculator provides detailed CIDR calculations.
Binary Format
In binary, subnet masks appear as consecutive 1s followed by consecutive 0s. For example, /24 is 11111111.11111111.11111111.00000000. Understanding the binary representation helps visualize how the mask separates network and host portions. Use our IP binary converter to explore binary representations.
Wildcard Mask
The wildcard mask is the bitwise inverse of the subnet mask, used primarily in Cisco ACLs and OSPF configuration. Where the subnet mask has 1s, the wildcard has 0s, and vice versa. For 255.255.255.0, the wildcard mask is 0.0.0.255. Calculate wildcard masks directly with our wildcard mask calculator.
Choosing the Right Subnet Mask
Selecting the appropriate subnet mask depends on your network requirements:
Based on Number of Hosts
If you know how many devices need IP addresses, choose a mask that provides enough addresses plus room for growth. Remember that each subnet loses 2 addresses (network and broadcast), so a network needing 50 hosts requires at least 52 addresses. The "Hosts to Mask" calculator mode handles this automatically.
| Hosts Needed | Minimum CIDR | Subnet Mask | Provides |
|---|---|---|---|
| 1-2 | /30 | 255.255.255.252 | 2 hosts |
| 3-6 | /29 | 255.255.255.248 | 6 hosts |
| 7-14 | /28 | 255.255.255.240 | 14 hosts |
| 15-30 | /27 | 255.255.255.224 | 30 hosts |
| 31-62 | /26 | 255.255.255.192 | 62 hosts |
| 63-126 | /25 | 255.255.255.128 | 126 hosts |
| 127-254 | /24 | 255.255.255.0 | 254 hosts |
| 255-510 | /23 | 255.255.254.0 | 510 hosts |
Based on Network Architecture
Different network segments typically use different mask sizes based on their role:
- Point-to-point WAN links: /30 or /31 (2 addresses)
- Server VLANs: /27 to /25 (30-126 hosts)
- User VLANs: /24 to /22 (254-1,022 hosts)
- Management networks: /28 to /26 (14-62 hosts)
- Loopback interfaces: /32 (1 address)
For complex networks with varying subnet sizes, our VLSM calculator can help design efficient address allocation.
Subnet Mask and Network Boundaries
The subnet mask determines where networks begin and end. When combined with an IP address using a bitwise AND operation, it produces the network address. Understanding this relationship is crucial for proper network configuration.
Example: How Subnet Mask Defines Network
Consider IP 192.168.1.150 with mask 255.255.255.192 (/26):
- Network address: 192.168.1.128
- Broadcast address: 192.168.1.191
- Valid host range: 192.168.1.129 - 192.168.1.190
- Usable hosts: 62
The same IP with mask 255.255.255.0 (/24) would be in network 192.168.1.0 with 254 usable hosts.
To visualize how different masks divide a network, try our visual subnet calculator. For calculating specific network and broadcast addresses, use our dedicated network address and broadcast address calculators.
Common Subnet Mask Mistakes
Avoid these frequent errors when working with subnet masks:
Invalid Subnet Masks
A valid subnet mask must have consecutive 1s followed by consecutive 0s in binary. Values like 255.255.255.100 or 255.0.255.0 are invalid because they don't follow this pattern. Each octet can only be: 0, 128, 192, 224, 240, 248, 252, 254, or 255.
Forgetting Reserved Addresses
When planning host capacity, remember that each subnet reserves 2 addresses (network and broadcast). A /28 has 16 total addresses but only 14 usable hosts. Always account for this when sizing networks.
Mismatched Masks
All devices on the same network segment must use the same subnet mask. A device with 255.255.255.0 cannot properly communicate with a device using 255.255.255.128 on the same segment, as they'll calculate different network boundaries.
Subnet Mask in Different Contexts
Windows Configuration
Windows displays subnet masks in dotted-decimal format in network adapter settings. When configuring static IP addresses, you'll enter the full mask (e.g., 255.255.255.0) alongside the IP address and default gateway.
Linux/Unix Systems
Linux typically uses CIDR notation in configuration files and commands (e.g., 192.168.1.100/24). The netmask command and older configurations may use dotted-decimal format.
Network Equipment
Cisco routers use both subnet masks (for interface configuration) and wildcard masks (for ACLs and OSPF). Other vendors may prefer one format over another, making conversion skills essential.
Cloud Platforms
AWS, Azure, and GCP use CIDR notation for VPC and subnet definitions. Understanding how to convert between formats helps when moving between different platforms and tools.