For the complete documentation index, see llms.txt. This page is also available as Markdown.

Convert the netmask between different formats

There are several ways to write a netmask. This guide will explain the different formats and how to convert between them.


Different operating systems, services, and equipment take the netmask in different formats. This can make the netmask hard to grasp.

The netmask shows you how large a network is, or rather, how many bits are reserved for the network, and thus how many addresses can fit in a given network.

First example

Let's start with a typical home network, 192.168.0.0/24, and what it means.

192.168.0.0/24 is one of the three ways to write the netmask. This way combines the netmask with the network address. For example, this is the way Ubuntu's installation program expects the netmask to be written.

192.168.0.0 is the network address. This address can't be used for any computers; it's only used to denote the network.

/24 is another way to write the netmask (that is, just /24 without any network or address). This means that 24 bits are reserved for the network. There are 32 bits in an IP address, so there are 8 bits left for addresses inside that network. A bit is either on or off, 1 or 0. So a bit only has 2 states.

With this information, it's possible to calculate how many addresses fit in that network. Take the 2 and raise it to the power of 8 (for the 8 bits left for addresses):

28=2562^8 = 256

However, you can't use the first address since that is the network address (192.168.0.0). You can't use the last address either, since that is the broadcast address (192.168.0.255). So there's actually only 254 usable addresses in that network. To get the number of usable addresses in the network, it's really:

282=2542^8-2=254

And those 254 addresses are 192.168.0.1 to 192.168.0.254.

Another way to write the same netmask is 255.255.255.0. This way makes it easier to visualize the network. 255 is the highest value in any octet (octet comes from the fact that each group has 8 bits).

Since the first three groups are all maxed out, only the last octet (the 0) can contain any addresses.

Seen in binary, 255.255.255.0 will look like this:

11111111.11111111.11111111.00000000

And 11111111 in binary equals 255 in decimal. This can be calculated by hand by adding the decimal numbers where a bit is set (a 1).

Four ways to write this netmask

  • 255.255.255.0. This is often called dotted decimal notation.

  • /24. This is often called slash notation.

  • 192.168.0.0/24. This way of writing shows both the network address and the netmask. The previous two ways, on their own, don't say anything about which network it is.

  • 192.168.0.5/24. This is a common way to write both the IP address and the netmask together. That is, the IP address is 192.168.0.5, and the corresponding netmask is /24. It's important not to confuse this with the network address. But since the IP address is 192.168.0.5 and the netmask is /24, the network address has to be 192.168.0.0. However, it can be tricky to differentiate when the netmask isn't cut at the octet boundaries.

Second example

A slightly more complicated example is 203.0.213.64/26.

This time, let's start by converting /26 to dotted decimal by writing it all out in binary. Write out 26 ones, and fill in the rest of the 32 bits with zeros.

11111111.11111111.11111111.11000000.

You already know that 11111111 = 255, so let's focus on the fourth and last octet, which is 11000000. Remember that you should only add the numbers where there's a one.

Hence, the last octet is 192. The complete netmask, in dotted decimal notation, is 255.255.255.192.

Now you have three ways of writing this netmask:

  • 255.255.255.192. The dotted decimal notation.

  • /26. The slash notation.

  • 203.0.213.64/26. The network address (203.0.213.64) and the netmask in slash notation (/26).

This poses two important questions. How do you know which IP addresses you can use inside this network, since it isn't cut at the octet boundary? And second, how do you know where the next network begins?

These questions can be answered using the equation used previously to calculate the number of addresses in a network. In this case, the slash notation netmask is /26. Subtracting 26 from 32 equals 6. That means there are 6 bits left for the addresses.

262=622^6-2 = 62

You can use 62 addresses in this network. Since 203.0.213.64 is the network address, the first available address is 203.0.213.65. The last usable address is 203.0.213.126. This makes the next address the broadcast address, that is, 203.0.213.127. This must mean that the next network starts at 203.0.213.128. You can double-check this by calculating all addresses:

26=642^6 = 64

The current network is 203.0.213.64. Adding 64 to the last octet gives you 203.0.213.128, which is the next network address.

Four ways to write this netmask

Let's summarize this network and its netmask:

  • 255.255.255.192. The dotted decimal notation.

  • /26. The slash notation.

  • 203.0.213.64/26. The network address (203.0.213.64) and the netmask in slash notation (/26).

  • 203.0.213.72/26. You now know that 203.0.213.72 is a valid IP address in this network (the first valid IP address is 203.0.213.65, the last is 203.0.213.126, and the broadcast address is 203.0.213.127).

Conversion table

To avoid doing math every time you need to convert /26 to 255.255.255.192 or vice versa, you can use a simple conversion table with common netmasks. There are more netmasks than this table shows, but these are the most common ones.

Slash notation
Dotted decimal

/8

255.0.0.0

/16

255.255.0.0

/17

255.255.128.0

/18

255.255.192.0

/19

255.255.224.0

/20

255.255.240.0

/21

255.255.248.0

/22

255.255.252.0

/23

255.255.254.0

/24

255.255.255.0

/25

255.255.255.128

/26

255.255.255.192

/27

255.255.255.224

/28

255.255.255.240

/29

255.255.255.248

/30

255.255.255.252

/31

255.255.255.254

/32

255.255.255.255

Last updated

Was this helpful?