Subnet Mask Calculator: How Masks Are Calculated
Short answer
A subnet mask is a 32-bit sequence used in IPv4 networking to divide an IP address into a network prefix and a host identifier. Calculation relies on a bitwise AND operation between the binary address and the mask to determine the starting network address, while assigning all host bits to one identifies the broadcast address. Modern network planning relies on Classless Inter-Domain Routing (CIDR) notation to allocate exact address blocks and control traffic boundaries.
Key points
- A subnet mask separates an IP address into its routing prefix and local device identifier.
- Network addresses result from applying a bitwise AND logic gate between the binary IP and the mask.
- Classless Inter-Domain Routing (CIDR) replaced rigid address classes by expressing mask lengths as a prefix count such as /24.
- Usable host counts per subnet equal two raised to the power of unmasked host bits minus two.
A subnet mask calculator eliminates manual binary arithmetic when dividing an Internet Protocol network into smaller logical segments. Every device connected to an Internet Protocol version 4 (IPv4) network requires an IP address and a subnet mask to communicate across local and external segments. The subnet mask determines where the network portion of the address ends and where the host portion begins. Network engineers rely on this division to control broadcast domains, improve routing efficiency, and protect internal subnets.
What a Subnet Mask Is and Does
An IPv4 address consists of 32 binary bits grouped into four octets of 8 bits each. A subnet mask mirrors this structure with an identical 32-bit length, written in dotted-decimal format such as 255.255.255.0. In binary, a subnet mask consists of a continuous sequence of ones followed by a continuous sequence of zeros. The ones represent the network prefix, while the trailing zeros represent host bits.
When a host prepares to transmit data, it compares its own subnet mask with the destination IP address. If the network segment matches its own, the host delivers the frame directly across the local switch. If the destination network bits differ, the host forwards the packet to a default gateway. Understanding this handoff is fundamental when evaluating the difference between a modem and a router, because routers operate at layer 3 to direct packets between these distinct subnet boundaries.
Binary Math Behind Subnet Mask Calculations
Subnetting relies on basic Boolean logic, specifically the bitwise AND operation. Under bitwise AND rules, a resulting bit is 1 only when both comparing bits are 1; otherwise, the result is 0. Applying a subnet mask to an IP address isolates the network address by stripping away the specific host identifiers.
The Bitwise AND Operation
Consider the host address 192.168.1.130 with a subnet mask of 255.255.255.192. Converting both values to binary exposes the mechanics:
- IP Address (192.168.1.130): 11000000.10101000.00000001.10000010
- Subnet Mask (255.255.255.192): 11111111.11111111.11111111.11000000
- Network Address (192.168.1.128): 11000000.10101000.00000001.10000000
The bitwise comparison shows that the first 26 bits remain identical to the original IP address, defining the subnet boundary. The remaining 6 bits belong to the host range.
Determining the Broadcast Address
The broadcast address allows a host to send data to every device on its local subnet simultaneously. To find the broadcast address, take the network address and flip all host bits from 0 to 1:
- Network ID Binary: 11000000.10101000.00000001.10000000
- Host Bits Set to One: 11000000.10101000.00000001.10111111
- Broadcast Address: 192.168.1.191
How an Online Subnet Mask Calculator Works
A subnet mask calculator processes an IP address alongside either a prefix length or a decimal mask to generate immediate network parameters. Instead of manually converting each octet into 8-bit binary strings, network administrators use these tools to design IP scopes, access control lists, and firewall rules in real time.
When provided with an IP address and prefix, the calculator outputs several key values:
- Network Address: The baseline identity of the subnet, where all host bits are binary zeros.
- Broadcast Address: The highest numeric address on the subnet, where all host bits are binary ones.
- Usable Host Range: The pool of assignable IP addresses between the network address and the broadcast address.
- Total and Usable Hosts: The total mathematical address count versus the assignable count after subtracting two reserved addresses.
- Wildcard Mask: The inverse of the subnet mask, created by flipping all ones to zeros and zeros to ones, frequently used in Cisco access control lists.
- Subnet Bitmap: A visual diagram displaying which bits are allocated to network routing versus local hosts.
CIDR Notation and Classless Addressing
Before the establishment of Classless Inter-Domain Routing (CIDR), IPv4 networks were divided into rigid classes based on their leading bits:
- Class A: Addresses 1.0.0.0 to 126.255.255.255 with a default mask of 255.0.0.0 (/8), supporting over 16 million hosts per network.
- Class B: Addresses 128.0.0.0 to 191.255.255.255 with a default mask of 255.255.0.0 (/16), supporting 65,534 hosts.
- Class C: Addresses 192.0.0.0 to 223.255.255.255 with a default mask of 255.255.255.0 (/24), supporting 254 hosts.
Classful allocation resulted in massive address exhaustion. An organization needing 500 IP addresses had to obtain a Class B license, leaving more than 65,000 addresses unused. CIDR removed these rigid boundaries by allowing arbitrary prefix lengths. A forward slash followed by a number indicates the exact count of masked network bits, such as 10.0.0.0/22.
Calculating Usable Hosts on a Subnet
To calculate the number of usable hosts within an IPv4 subnet, use the standard mathematical formula:
Usable Hosts = 2h - 2
In this formula, h represents the number of host bits available (32 minus the CIDR prefix length). The subtraction of two accounts for the network address and the broadcast address, neither of which can be assigned to an individual network interface card.
For instance, a /28 prefix reserves 28 bits for the network, leaving 4 bits for hosts (32 - 28 = 4). Calculating 24 yields 16 total IP addresses. Subtracting 2 provides 14 usable addresses. If a point-to-point router link uses a /30 prefix, 2 host bits remain: 22 - 2 yields exactly 2 usable addresses, preventing address waste on private routing links.
When planning address distribution across remote branches or home offices, proper subnetting ensures that access points and endpoints communicate reliably without broadcast saturation. This design is equally relevant when deciding whether an is mesh WiFi better than range extender layout fits a facility, because wireless backhauls and guest networks often depend on isolated subnets with dedicated DHCP ranges.
IPv4 Subnet Reference Table
The following table lists common IPv4 subnet configurations, showing how borrowed bits alter host capacities and dotted-decimal values within a single octet block.
| CIDR Prefix | Subnet Mask | Total Addresses | Usable Hosts | Wildcard Mask |
|---|---|---|---|---|
| /24 | 255.255.255.0 | 256 | 254 | 0.0.0.255 |
| /25 | 255.255.255.128 | 128 | 126 | 0.0.0.127 |
| /26 | 255.255.255.192 | 64 | 62 | 0.0.0.63 |
| /27 | 255.255.255.224 | 32 | 30 | 0.0.0.31 |
| /28 | 255.255.255.240 | 16 | 14 | 0.0.0.15 |
| /29 | 255.255.255.248 | 8 | 6 | 0.0.0.7 |
| /30 | 255.255.255.252 | 4 | 2 | 0.0.0.3 |
IPv6 Subnetting Differences
Internet Protocol version 6 (IPv6) expands address capacity from 32 bits to 128 bits, written in hexadecimal groups separated by colons (for example, 2001:0db8:85a3::8a2e:0370:7334). IPv6 does not use dotted-decimal subnet masks or broadcast addresses. Instead, IPv6 subnetting relies entirely on prefix lengths, with multicast protocols handling functions formerly assigned to broadcasts.
A typical IPv6 allocation assigns a /48 prefix to an enterprise or an Internet service subscriber. The customer then allocates 16 bits to create 65,536 distinct subnets, each utilizing a /64 prefix length. Because a single /64 subnet contains 264 addresses (over 18 quintillion), network planners no longer need to calculate granular host restrictions to conserve space. However, resolving hostnames to these expansive addresses still depends on robust Domain Name System DNS server mapping across local and global scopes.
Questions people also ask
Why cannot the first and last addresses of a subnet be assigned to a host?
The first address represents the network identifier for routing tables, while the last address acts as the broadcast address to deliver packets to all hosts on that subnet.
What is the difference between a subnet mask and CIDR notation?
A subnet mask writes the 32-bit network boundary in dotted-decimal numbers like 255.255.255.0, whereas CIDR notation denotes the exact count of masked network bits using a slash prefix like /24.
What is an ACL wildcard mask?
A wildcard mask is the binary inverse of a subnet mask where zeros match exact bits and ones allow any value, primarily used in network firewalls and router access control lists.
Related pages
- WPA2 vs WPA3 Security: Differences and Router Setup
WPA2 and WPA3 are encryption protocols designed to shield wireless network traffic from unauthorized access. WPA2 uses a four-way handshake vulnerable to offline dictionary attacks and deauthentication spoofing, whereas WPA3 introduces Simultaneous Authentication of Equals, mandatory management frame protection, and forward secrecy to resist interception.
- What Is Wi-Fi 6 and How Does It Compare to Wi-Fi 5?
Wi-Fi 6 is the Wi-Fi Alliance name for IEEE 802.11ax, a wireless standard for 2.4 GHz and 5 GHz networks that is built for homes with many connected devices. It raises theoretical peak speed to 9.6 Gbps and improves efficiency through OFDMA, while Wi-Fi 5 remains adequate for many lighter networks.
- Public vs Private IP Address: Key Differences
A public IP address is globally routable and identifies a network on the internet, while a private IP address works only inside a local network. Routers use NAT to let many private devices share one public address. The choice affects reachability, cost, security, and configuration.
- 2.4 GHz vs 5 GHz Wi-Fi: Which Band Should You Use?
2.4 GHz Wi-Fi reaches farther and passes through walls more easily, while 5 GHz Wi-Fi is faster and more reliable at short to medium range. Most dual-band routers broadcast both, so the best choice depends on distance, obstacles, and the speed your devices need.
- MAC Address How It Works: Local Network Guide
A Media Access Control (MAC) address is a twelve-digit hexadecimal identifier assigned to a network interface controller for local communications. It operates at the data link layer to direct frames between devices sharing the same network segment. While IP addresses route traffic across interconnected internet paths, network hardware relies on the MAC address to pinpoint the exact physical recipient of each transmission.
- Is Mesh WiFi Better Than Range Extender Setups?
Mesh Wi-Fi is generally better than a range extender for medium to large homes requiring broad coverage, fast data rates, and automatic device transitions under a single network name. Range extenders serve as low-cost solutions for bridging coverage into a single dead room. When coverage must span multiple rooms or floors, mesh hardware avoids the severe bandwidth loss and connection drops typical of extenders.
How this page was prepared
Before writing, the topic was researched in the sources below. The page then passed automatic quality checks.