How-to Guides Networking

How to Choose a Subnet Mask

Pick the right subnet mask for the number of devices you need, then split one network into right-sized subnets with a VLSM plan.

Last reviewed:

AdSense Placeholder
Slot: header_reference_page
On this page

Steps

  1. Count the devices and add room to grow

    Count every address the network needs: computers, phones, printers, access points, the router itself and the DHCP pool. Add the growth you expect over the next few years.

  2. Let the calculator suggest the prefix

    In the IPv4 Subnet Calculator, type the total into Hosts Needed under Reverse Subnet Design and press Suggest Subnet. It shows the Suggested Prefix, the Subnet Mask and the Usable Hosts Provided.

  3. Check the resulting range

    Press Use This Subnet, enter the network's starting address in IP Address and press Calculate. Read the Network Address, Broadcast Address, Usable Host Range and Wildcard Mask.

  4. Plan several subnets at once with VLSM

    If one block must be split between groups of different sizes, open the VLSM Calculator, enter the block in Network to divide and one line per subnet such as Staff: 100, then press Plan Subnets.

  5. Convert the mask to the format your device wants

    Routers and operating systems ask for either /25 or 255.255.255.128. The Subnet Mask ⇄ CIDR Converter converts in both directions and rejects masks that are not a contiguous run of 1-bits.

  6. Verify addresses before you configure them

    Use the IP in CIDR Checker to confirm the gateway and any static addresses fall inside the new subnet, and the CIDR to IP Range Converter to list its first and last address.

What you need

The number of devices per network segment, the address block you are allowed to use (in a private network, usually part of 10.0.0.0/8, 172.16.0.0/12 or 192.168.0.0/16) and an idea of how much each group will grow. The examples below use the documentation block 198.51.100.0/24.

Reading the result

A subnet with prefix length p has 2^(32 − p) addresses. Two of them, the network and broadcast addresses, are reserved, so the usable count is 2^(32 − p) − 2. Pick the largest prefix (the smallest subnet) whose usable count still covers your total:

Prefix Mask Addresses Usable hosts
/22 255.255.252.0 1024 1022
/23 255.255.254.0 512 510
/24 255.255.255.0 256 254
/25 255.255.255.128 128 126
/26 255.255.255.192 64 62
/27 255.255.255.224 32 30
/28 255.255.255.240 16 14
/29 255.255.255.248 8 6
/30 255.255.255.252 4 2

So 60 devices need a /26, 90 or 100 need a /25, and 127 already need a /24.

Now split 198.51.100.0/24 between five groups. The VLSM planner places the largest block first so every block stays aligned:

Subnet Hosts needed Block Usable range Broadcast Spare
Staff 100 198.51.100.0/25 .1 – .126 .127 26
Guest Wi-Fi 50 198.51.100.128/26 .129 – .190 .191 12
Servers 20 198.51.100.192/27 .193 – .222 .223 10
Printers 10 198.51.100.224/28 .225 – .238 .239 4
Router link 2 198.51.100.240/30 .241 – .242 .243 0

The plan uses 244 of the 256 addresses and leaves 12 free (198.51.100.244 to .255). The Staff network's mask is 255.255.255.128 and its wildcard mask, used in many access lists, is 0.0.0.127.

Common pitfalls

  • Forgetting the two reserved addresses. 64 devices do not fit in a /26: it has 64 addresses but only 62 usable.
  • Sizing for today only. A subnet with zero spare addresses means renumbering later. The Router link above is fine at zero spare because a point-to-point link never grows.
  • Starting a subnet in the wrong place. A block must start on a multiple of its size: a /26 can start at .0, .64, .128 or .192, never at .100. The calculators always return the aligned network address.
  • Mixing /30 and /31. For two hosts the Subnet Calculator suggests a /31, which RFC 3021 allows on point-to-point links; the VLSM planner uses the classic /30. Use /31 only where both devices support it.
  • Mismatched masks. Every device in a subnet, and its gateway, must use the same mask. A device with the wrong mask can reach some neighbours and not others.

Going further

The binary arithmetic behind all of this, including how the mask selects the network part of an address, is explained step by step in How Subnetting Works. Keep CIDR and Subnet Mask Cheat Sheet handy for every prefix from /8 to /32 with its mask and wildcard.

Try these tools

See also

  • Guide How Subnetting Works
    How an IP address splits into network and host parts, how to find a network and broadcast address.
  • Cheat sheet CIDR and Subnet Mask Cheat Sheet
    Every IPv4 prefix from /8 to /32 with its subnet mask, wildcard mask, address count and usable hosts.
  • Glossary Subnet mask
    A subnet mask is a 32-bit value that marks which part of an IPv4 address identifies the network and which part identifies the host.
  • Glossary CIDR
    CIDR (Classless Inter-Domain Routing) is the notation that writes an IP network as an address plus a prefix length, such as 192.168.1.0/24.
  • Glossary Default gateway
    The default gateway is the router a device sends traffic to when the destination is outside its own subnet.

Frequently Asked Questions

A /24 has 256 addresses, but the first is the network address and the last is the broadcast address. Neither can be given to a device, which leaves 254. The same two are lost in every subnet up to /30.

It gives room to grow, but every device in a subnet shares one broadcast domain, and a very large subnet wastes addresses and makes firewall rules coarser. Size for today's devices plus realistic growth, and split groups that need different rules.

AdSense Placeholder
Slot: footer_leaderboard