Subnet mask

Ethernet cable and network switches

A subnet mask is a 32-bit number that divides an IPv4 address into a network portion and a host portion. It tells a computer which addresses are directly reachable within its subnet and which require a router. For example, 192.168.1.10 with the mask 255.255.255.0, or /24, belongs to the network 192.168.1.0. A /24 is usually sufficient for a typical home network, but when joining an existing network, obtain the mask from the router or administrator rather than choosing one at random.

What is a subnet mask in simple terms?

An IPv4 address consists of four numbers from 0 to 255. Each occupies eight bits, making 32 bits in total. The mask has the same length and sets the boundary between the network and host portions. This boundary falls between individual binary digits, so it does not necessarily align with the dots separating the numbers.

A device at 192.168.1.10/24 sends data directly to its neighbour at 192.168.1.20. The address 192.168.2.20 belongs to a different subnet and requires a route through a router.

The operating system makes the final decision using its routing table. In addition to the route to its own subnet, the table may contain others, such as a route to a corporate network over a VPN.

Subnets and network addresses

A subnet is a block of IP addresses with a shared network portion. The network address identifies the entire block: all host bits in that address are zero. For 192.168.1.10/24, the network address is 192.168.1.0; for 192.168.1.10/16, it is 192.168.0.0. With different masks, the same IP address belongs to subnets of different sizes.

A conventional IPv4 subnet has three types of address:

  • The network address identifies the subnet as a whole. In 192.168.1.0/24, this is 192.168.1.0.
  • Host addresses are assigned to computers, servers, printers and router interfaces. In this example, the range is 192.168.1.1–192.168.1.254.
  • The broadcast address is used to send a packet to all hosts on the subnet. In this example, it is 192.168.1.255.

A final octet of .0 does not always identify a network address, and .255 does not always identify a broadcast address. It depends on the prefix. For example, within 192.168.0.0/23, the addresses 192.168.0.255 and 192.168.1.0 are valid host addresses: both fall inside the range rather than at its boundaries.


How to write a mask: 255.255.255.0 and /24

The notations 255.255.255.0 and /24 describe the same mask. The latter specifies the prefix length: the number of network bits counted from the start of the address.

In a /24 mask, the first 24 bits are ones and the remaining eight are zeros:

11111111.11111111.11111111.00000000

Eight ones give 255, while eight zeros give 0, resulting in 255.255.255.0. The /24 notation is used in Classless Inter-Domain Routing, or CIDR.

In the Subnet prefix length field, enter 24 without a slash. In the Subnet mask field, enter 255.255.255.0.

Modern IPv4 subnet masks contain consecutive ones on the left, followed only by zeros. An individual eight-bit number can therefore be 0, 128, 192, 224, 240, 248, 252, 254 or 255. These values cannot be combined in an arbitrary order: 255.255.0.255 breaks the continuity of the network portion.

How bitwise AND works

The network address is obtained by applying bitwise AND to the IP address and mask. For each corresponding pair of bits, the result is one only when both bits are one.

For 192.168.1.10/24, this means:

  • the first three numbers in the address remain unchanged because the corresponding mask octets are 255;
  • the last number becomes zero because the corresponding mask octet is 0;
  • the result is the network address 192.168.1.0.

With /25, /26 or /27, the boundary falls within the final octet: simply setting the last part of the IP address to zero is no longer sufficient.

Wildcard masks

A wildcard mask appears in access control lists and OSPF configuration. For a conventional subnet, it is obtained by inverting the bits: 255.255.255.0 becomes 0.0.0.255. In these rules, zero means “this bit must match”, while one means “this bit can be ignored”. Do not enter a wildcard mask in a network adapter's subnet mask field. Wildcard masks can also contain other bit patterns that do not describe a contiguous subnet.

Subnet mask table

Network and host portions of an IPv4 address

The longer the prefix, the fewer addresses remain within the subnet. Each additional network bit halves the block size: /24 contains 256 addresses in total, /25 contains 128, and /26 contains 64.

Calculate the total number of addresses using this formula:

Total addresses = 2^(32 − prefix length).

In a conventional IPv4 subnet, two addresses are reserved for the network address and broadcast address:

Usable host addresses = 2^(32 − prefix length) − 2.

The table values use these formulas. Do not subtract two for the last two rows.

Prefix Mask Total addresses Usable host addresses
/8 255.0.0.0 16 777 216 16 777 214
/9 255.128.0.0 8 388 608 8 388 606
/10 255.192.0.0 4 194 304 4 194 302
/11 255.224.0.0 2 097 152 2 097 150
/12 255.240.0.0 1 048 576 1 048 574
/13 255.248.0.0 524 288 524 286
/14 255.252.0.0 262 144 262 142
/15 255.254.0.0 131 072 131 070
/16 255.255.0.0 65 536 65 534
/17 255.255.128.0 32 768 32 766
/18 255.255.192.0 16 384 16 382
/19 255.255.224.0 8 192 8 190
/20 255.255.240.0 4 096 4 094
/21 255.255.248.0 2 048 2 046
/22 255.255.252.0 1 024 1 022
/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
/31 255.255.255.254 2 2 — point-to-point
/32 255.255.255.255 1 1 — single address
Get Expert Help
Choosing the Right Equipment

Our specialists will contact you and answer all your questions

I agree to process my personal data

/31 is used for point-to-point links: both addresses are assigned to the link endpoints. This is defined in RFC 3021. For example, in 192.168.10.0/31, the addresses .0 and .1 can belong to two routers. Both endpoints must support /31; it is not a mask to choose for a conventional workstation network.

/32 identifies a single IPv4 address: a host route, a router loopback interface address or an individual address in a filtering rule. It is unsuitable for a shared network containing several devices.

The gateway and infrastructure addresses must also come from the “Usable host addresses” capacity. This figure does not indicate how many clients the equipment can handle: performance depends on its capabilities and workload.

Common subnet masks

255.255.255.0 — /24

A /24 mask provides 256 addresses, of which 254 are usable for hosts. It is often used in homes and small offices: the range is easy to read and provides enough addresses for the main devices.

If the router uses one address, up to 253 remain for other devices. The automatic address allocation pool may be smaller than the subnet itself.

Masks from /25 to /30 for small networks

  • /25, 255.255.255.128: 128 addresses in total, with 126 usable for hosts. Suitable for a segment that has outgrown /26 but does not need a full /24.
  • /26, 255.255.255.192: 64 addresses in total, with 62 usable for hosts. For example, this can accommodate several dozen workstations, allowing for network equipment and spare capacity.
  • /27, 255.255.255.224: 32 addresses in total, with 30 usable for hosts. Convenient for a small department or group of equipment.
  • /28, 255.255.255.240: 16 addresses in total, with 14 usable for hosts. Suitable for a small server or infrastructure segment.
  • /29, 255.255.255.248: eight addresses in total, with six usable for hosts. Suitable for a very small group of hosts if there are enough addresses for the gateway and spare capacity.
  • /30, 255.255.255.252: four addresses in total, with two usable for hosts. A traditional choice for a dedicated link between two routers.

Masks /16, /20, /23 and /32

  • /16, 255.255.0.0: 65,536 addresses in total, with 65,534 usable for hosts. It is often more practical to divide a block of this size into several subnets than to use it as one large segment.
  • /20, 255.255.240.0: 4,096 addresses in total, with 4,094 usable for hosts. Block boundaries occur in increments of 16 in the third octet: for example, 192.168.16.0/20 covers addresses up to 192.168.31.255.
  • /23, 255.255.254.0: 512 addresses in total, with 510 usable for hosts. For example, 192.168.10.0/23 includes the range 192.168.10.0–192.168.11.255.
  • /32, 255.255.255.255: a single address. Appropriate when a rule or route must apply to one specific host.

How to find your subnet mask

Network cables connected to LAN equipment

Network cables connected to local network equipment. Photo: Brett Sayles / Pexels.

Check the mask for the relevant network connection. Ethernet, Wi-Fi, VPN and virtual adapters may all have different addresses and prefixes at the same time.

Windows

Open Command Prompt, PowerShell or Windows Terminal and run:

ipconfig

Find the section for the active Ethernet or wireless adapter. It shows the IPv4 address, subnet mask and default gateway. For example:

IPv4 Address:     192.168.1.10
Subnet Mask:      255.255.255.0
Default Gateway:  192.168.1.1

For more details, use ipconfig /all: among other things, it shows whether DHCP is enabled. Microsoft's ipconfig documentation describes the address, mask and gateway output.

In the graphical interface, open Settings → Network & Internet, then Ethernet or the properties of the connected Wi-Fi network. The names of the options depend on the Windows version.

In the IP assignment form, the “Subnet mask” field takes 255.255.255.0, while “Subnet prefix length” takes 24. You do not need to switch to manual assignment just to view the settings.

Linux

In a terminal, run:

ip addr

A shorter version of the same command is ip a. To display only IPv4 addresses, use ip -4 addr. Find the inet line for the active interface, for example:

inet 192.168.1.10/24 brd 192.168.1.255 scope global enp3s0

Here, /24 corresponds to the mask 255.255.255.0, and brd contains the broadcast address. The interface name may differ. For a specific connection, use ip -4 addr show dev enp3s0, replacing the name with your own.

macOS

In macOS, the easiest way to view the mask is through System Settings → Network → the relevant connection → Details → TCP/IP. The IPv4 section contains the address, subnet mask and router address.

In a terminal, you can run:

ifconfig

Find the line containing the active interface's IPv4 address. It may look like this:

inet 192.168.1.10 netmask 0xffffff00 broadcast 192.168.1.255

The mask 0xffffff00 is written in hexadecimal. Remove 0x and split the remaining characters into pairs: ff.ff.ff.00. Each pair represents a mask octet: ff is 255 and 00 is 0. This gives 255.255.255.0, or /24. Similarly, 0xfffffe00 means 255.255.254.0, or /23: fe is 254.

The ip addr command familiar from Linux is not included in macOS by default. You do not need to copy it from instructions for a different operating system.

Laptop and equipment for checking network settings

On the router

Open the router's web interface at its management address: at home, this often matches the computer's default gateway. Find the LAN, Local Network or Home Network section.

The mask appears next to the local IP address. For example, 192.168.1.1 and 255.255.255.0 indicate the network 192.168.1.0/24.

Do not confuse LAN with WAN: the ISP connection, guest network and individual VLANs may have different settings. There is no single mask shared by every router interface.

You cannot determine the mask from an IP address alone. The address 192.168.1.10 can be used with different prefixes. The mask is set in the configuration or supplied with the address through DHCP.


Subnet masks and the default gateway

The default gateway is the router address to which a computer sends packets when no more specific route is available. At home, this role is usually performed by the router connecting the local network to the ISP's network.

In a conventional Ethernet or Wi-Fi network, the gateway must be in the same subnet as the device: the computer needs to reach it directly. For example, 192.168.1.1 is a suitable gateway for 192.168.1.10/24, while 192.168.2.1 lies outside the local range.

A gateway address does not have to end in .1. It could be 192.168.1.254 or another address actually assigned to the router. An arbitrary unused IP address will not act as a gateway.

A default gateway is not required for communication within a single subnet. Special-purpose connections can use other arrangements, but a conventional local network is configured with a directly reachable gateway.

When choosing routers from the Servermall network equipment catalogue, consider port speeds as well as support for the required number of subnets, VLANs and access rules. The role of this equipment is explained in more detail in “What Is a Router?”.

What to enter when configuring settings manually

Suppose an administrator has assigned a computer an address in 192.168.1.0/24 with the gateway 192.168.1.1. The values might be:

  • IP address: 192.168.1.10 — an unused address agreed as part of the addressing plan.
  • Subnet mask: 255.255.255.0, or prefix length: 24.
  • Default gateway: 192.168.1.1 — the address of the router's local interface.
  • DNS server: the address specified by the network configuration; it is not determined by the subnet mask.

These values are examples. A manually assigned IP must be excluded from automatic allocation to other devices or reserved using an appropriate method; otherwise, an address conflict may occur.


Why Windows reports a different network segment

The message “The default gateway is not on the same network segment (subnet) that is defined by the IP address and subnet mask” means that the entered gateway does not belong to the connected subnet defined by the specified IP address and mask.

For example, 192.168.10.77/27 belongs to 192.168.10.64/27. The gateway 192.168.10.1 lies outside that subnet, even though the first three octets match.

Check the IP address, mask and gateway against the relevant router interface settings or the information supplied by your administrator. If manual configuration is unnecessary, restore DHCP. Do not expand the subnet to /16 simply to dismiss the warning: doing so changes routing.

What happens if the mask is incorrect?

  • Prefix too short: the computer treats remote addresses as local. With an incorrect /16 instead of /24, it may try to reach 192.168.2.20 directly when it should use the gateway.
  • Prefix too long: some neighbouring devices fall outside the subnet, and the gateway may become unreachable.

The mask itself does not create an IP address conflict. It changes where packets are sent, and reachability may differ between the two directions.

How to calculate the network address and address range

Router connecting a local network to other networks

Consider 192.168.10.77/27. A /27 prefix has the mask 255.255.255.224, 32 addresses in total and 30 usable host addresses.

Finding the block boundaries

The first three mask octets are 255, so in this example the boundary is calculated using the last octet. The block increment is:

256 − 224 = 32.

The subnets therefore start at .0, .32, .64, .96, .128, .160, .192 and .224. The number 77 falls within the block from 64 to 95.

  1. Network address: 192.168.10.64 — the start of the block.
  2. Broadcast address: 192.168.10.95 — the last address before the next network, .96.
  3. First host address: 192.168.10.65.
  4. Last host address: 192.168.10.94.
  5. Usable host addresses: 30; the gateway address, if needed, is included in this number.

The gateway could be 192.168.10.65 if that address is assigned to the router. The address .77 is suitable for a computer: it is neither the network address nor the broadcast address.

Confirming the result with bitwise AND

The last IP address octet, 77, is 01001101 in binary. The last mask octet, 224, is 11100000. Applying bitwise AND leaves 01000000, or 64. This gives the same network address, 192.168.10.64.

For the broadcast address, set all five host bits to one: 01011111, or 95. The last host address is 94.

Calculate the increment, 256 minus the mask octet value, in the part of the address containing the prefix boundary. For /20, this is the third octet: 256 − 240 = 16. The following, fourth octet varies across its full range, from 0 to 255.

In a subnet calculator, entering an IP address with its prefix is enough to obtain the network address and range. Do not confuse “total addresses” with “usable host addresses”; remember the /31 and /32 exceptions.

Get Expert Help
Choosing the Right Equipment

Our specialists will contact you and answer all your questions

I agree to process my personal data

How to choose a mask for your network

Address allocation across subnets

Count the addresses for all connections

In an existing network, use the mask in its configuration. Choose a subnet size when designing a new subnet or changing the addressing plan.

Count the addresses needed by phones, printers, cameras, servers and management equipment. One server may have several IP addresses, while virtual machines may have their own connections.

A practical sequence is:

  1. Determine how many IP addresses the current workload needs.
  2. Add the gateway, infrastructure interfaces and expected growth.
  3. Choose the smallest sufficient capacity from the table.
  4. Place the subnet on the correct boundary within the available address block.

For example, 40 devices, one gateway and room for 15 new addresses require 56 addresses. A /26 provides 62 and is sufficient; a /27, with 30, is too small. For further growth, plan for a /25 or a separate segment.

More addresses require a shorter prefix. Expansion must not create overlaps with neighbouring subnets.

Separate the network by purpose

Workstations, servers, cameras and guest devices are often placed in separate VLANs, or virtual local area networks. Each segment is usually assigned its own IP subnet. Sizes can differ: workstations may need a /25, while a few infrastructure hosts may only need a /28.

For this separation, choose managed switches with the required VLAN support. Communication between subnets is handled by a router or a switch with routing capabilities. Servermall's article “Layer 1, 2, and 3 Switches: What They Are and How They Differ” explains these capabilities.

The mask itself does not create a VLAN or restrict access. Protecting infrastructure resources from guest devices requires rules on the equipment that handles traffic between segments.

Example: dividing a /24 into subnets of different sizes

Suppose a company has the block 192.168.10.0/24 available. It needs subnets for 90 workplace devices, 40 cameras and 12 servers. Allowing one gateway address per group means at least 91, 41 and 13 addresses are required.

Use VLSM, or variable-length subnet masking, to divide the address block into subnets with different prefix lengths. Allocate the largest segment first, followed by the smaller ones:

Purpose Subnet and mask Host address range Broadcast address
Workplace devices 192.168.10.0/25, 255.255.255.128 192.168.10.1–192.168.10.126 192.168.10.127
Cameras 192.168.10.128/26, 255.255.255.192 192.168.10.129–192.168.10.190 192.168.10.191
Servers 192.168.10.192/28, 255.255.255.240 192.168.10.193–192.168.10.206 192.168.10.207

If .1, .129 and .193 are assigned to the gateways, 125, 61 and 13 addresses remain for other devices respectively. The subnets do not overlap and fit within the original /24.

With 12 servers and a gateway, a /28 leaves only one spare address. For growth or gateway redundancy, it is better to allocate 192.168.10.192/27, which provides 30 usable host addresses.

Plan private address ranges with other sites in mind

RFC 1918 reserves three private blocks for local IPv4 addressing:

  • 10.0.0.0/8: 10.0.0.0–10.255.255.255.
  • 172.16.0.0/12: 172.16.0.0–172.31.255.255.
  • 192.168.0.0/16: 192.168.0.0–192.168.255.255.

Not every 172.x.x.x address is private: the second octet must be between 16 and 31 inclusive.

A private block can be subdivided: for example, individual /24 subnets can be allocated within 10.0.0.0/8. Coordinate addresses before connecting sites over a VPN: identical subnets at both ends interfere with routing.

For addressing plans, automatic configuration and equipment connections, see “Local Network and Server”.

Classful and classless addressing

In the old classful IPv4 scheme, classes A, B and C had default masks of /8, /16 and /24. Network size was determined by the address class, making it difficult to accommodate requirements between these sizes.

With classless addressing, or CIDR, a network is defined by an address and prefix length. The principles are described in RFC 4632. This allows appropriately sized blocks to be allocated and aggregated for routing.

In a historical description, “default mask” means the class mask; in router instructions, it may refer to the factory-set /24. In a live network, its actual configuration matters, rather than the first numbers in the IP address.

Masks in IPv6

An IPv6 address contains 128 bits, and the network boundary is specified by a prefix length. Masks such as 255.255.255.0 are not used. For example, a valid network notation is 2001:db8:1234:abcd::/64. This is a teaching example from the address range reserved for documentation.

The number 64 is the prefix length in decimal. The first 64 bits specify the network portion, and the remaining 64 form the interface identifier. In the network address, all bits beyond the prefix boundary are zero.

A conventional local IPv6 network with automatic address configuration uses /64. RFC 7421 explains why. Other prefix lengths also exist: a /48 or /56 block assigned to an organisation can be divided into individual /64 subnets.

Do not apply the IPv4 formula that subtracts two addresses: IPv6 has no broadcast addressing. Choose a prefix based on the network design and automatic configuration requirements, rather than just the number of devices.

Frequently asked questions

What mask is 255.255.255.0?

It is /24: 256 addresses in total, with 254 usable for hosts. For example, the host address range in 192.168.1.0/24 is 192.168.1.1–192.168.1.254.

How many addresses does a /29 contain?

Eight in total, with six usable for hosts. The mask is 255.255.255.248. If the gateway uses one address, five remain for other hosts.

What is the standard mask for a home network?

Often 255.255.255.0, or /24, but there is no mandatory value. Use the mask for your local network: check it on the router or obtain it through DHCP.

Can you determine a subnet mask from an IP address?

No: an IP address does not contain the prefix length. You need the interface settings, DHCP information or router configuration. You cannot automatically assume /24 for 192.168.1.10.

What should I enter in the “Subnet mask” field?

Your network's mask, for example 255.255.255.0. Its corresponding prefix length is 24. If a manual address is unnecessary, leave automatic configuration through DHCP enabled.

In an existing network, use its IP settings. For a new network, choose prefixes based on the number of addresses, segment layout and expected growth.


Get Expert Help
Choosing the Right Equipment

Our specialists will contact you and answer all your questions

I agree to process my personal data
Comments
(0)
No comments
Write the comment
I agree to process my personal data

Next news

Be the first to know about new posts and earn 50  €