calculate the subnet mask

Subnet Mask Calculator (IPv4)

Enter an IP and CIDR prefix to calculate the subnet mask, network address, broadcast address, and usable host range.


Need a subnet mask from host count?

Use this helper to find the smallest traditional subnet that fits your required usable hosts.

What Is a Subnet Mask?

A subnet mask is a 32-bit value used in IPv4 networking to split an IP address into two parts: the network portion and the host portion. Devices use the mask to decide whether another IP is local (same subnet) or remote (needs a router).

  • 1 bits in the mask represent the network portion.
  • 0 bits represent the host portion.
  • Example: 255.255.255.0 means the first 24 bits are network bits, often written as /24.

Why subnet masks matter

Correct subnetting improves routing efficiency, reduces unnecessary broadcast traffic, and helps you organize networks by department, floor, customer, or environment. Whether you run a small office LAN or cloud VPC design, subnet planning is essential.

How to Calculate a Subnet Mask from CIDR

CIDR notation (Classless Inter-Domain Routing) expresses subnet size with a slash and prefix length, like /26. To convert CIDR to a subnet mask:

  • Write 32 bits total.
  • Set the first N bits to 1, where N is the prefix.
  • Convert each group of 8 bits to decimal.

Example for /26:

  • Binary mask: 11111111.11111111.11111111.11000000
  • Decimal mask: 255.255.255.192

Quick CIDR reference

  • /8255.0.0.0
  • /16255.255.0.0
  • /24255.255.255.0
  • /25255.255.255.128
  • /26255.255.255.192
  • /27255.255.255.224
  • /28255.255.255.240
  • /29255.255.255.248
  • /30255.255.255.252

How to Calculate Subnet Size from Host Needs

If you know how many hosts a subnet must support, use this traditional formula:

  • Find host bits h such that 2^h - 2 ≥ required hosts.
  • Then prefix length is 32 - h.

Example: if you need 50 usable hosts:

  • 2^5 - 2 = 30 (not enough)
  • 2^6 - 2 = 62 (enough)
  • So you need 6 host bits → prefix /26 → mask 255.255.255.192.

Common Subnetting Mistakes

  • Using the wrong mask in DHCP settings, leading to communication failures.
  • Forgetting that network and broadcast addresses are typically not assignable host addresses.
  • Mixing CIDR and dotted-decimal values incorrectly.
  • Not leaving room for growth when planning subnets.

Practical workflow

A reliable approach is: estimate hosts, choose a CIDR prefix, compute mask and ranges, then verify with a calculator (like the one above). This reduces outages and makes documentation much easier.

Final Thoughts

Learning to calculate a subnet mask is one of the highest-value networking skills. Once you can move comfortably between CIDR, subnet mask, and host capacity, you'll design cleaner networks and troubleshoot faster. Use the calculator above whenever you need fast, accurate results for IPv4 planning.

🔗 Related Calculators