In IPv4, you have:
- Addresses, which are 32-bit identifiers, usually represented in the "dotted quad" representation, like
192.168.1.2.
- Networks, which are a range of IP addresses, and are defined by a start address and a netmask.
The netmask is used as a 32-bit value, but its binary representation will always starts with 0 or more 1 bits, and the rest will be 0 bits.
Being a 32-bit value like an IP address, it used to be the norm to represent netmasks like IP addresses, using the "dotted-quad" notation, like 255.255.240.0.
But this is a lot of data to type when there are only 33 possible values (see below), and more recently people just give the number of "1" bits, also called the "prefix length".
255.255.240.0 in binary is 11111111 11111111 11110000 00000000, i.e. 20 1 bits and 12 0 bits.
So instead of using the pretty long 255.255.240.0 notation, only will just give the prefix-length: 20.
The prefix-length is usually appended to the end of the start IP address, separated by a /.
So the following are different representations of the same network:
10.1.16.0 netmask 255.255.240.0 (start address + netmask)
10.1.16.0/20 (start address + prefix length)
10.1.16.0 - 10.1.31.255 (start and end addresses)
An IP address, per se, does not have a subnet mask or prefix length, but to configure an interface you need to define not only the IP address, but also the network (as this is required to know which other addresses are on the same network, or need to be sent to the gateway for further routing).
Given the subnet mask (or prefix length) and the IP address, one can find the network (just "AND" the binary representation of the IP address and the subnet mask, and you'll get the starting IP).
So:
192.168.2.1/24
192.168.2.1 netmask 255.255.255.0
both mean:
- The IP address is
192.168.2.1
- The network is
192.168.2.0/24, also known as 192.168.2.0 netmask 255.255.255.0, also known as the 192.168.2.0 - 192.168.2.255 range.
Here are the equivalents between prefix lengths and netmasks, and the associated network size:
/0 0.0.0.0 the whole IP address space, over 4 billion values
/1 128.0.0.0 half of it, over 2 billion values
/2 192.0.0.0 half again, over 1 billion values
/3 224.0.0.0 over 536 million
/4 240.0.0.0 over 268 million
/5 248.0.0.0 over 134 million
/6 252.0.0.0 over 67 million
/7 254.0.0.0 over 33 million
/8 255.0.0.0 over 16 million
/9 255.128.0.0 over 8 million
/10 255.192.0.0 over 4 million
/11 255.224.0.0 over 2 million
/12 255.240.0.0 over 1 million
/13 255.248.0.0 524288
/14 255.252.0.0 262144
/15 255.254.0.0 131072
/16 255.255.0.0 65536
/17 255.255.128.0 32768
/18 255.255.192.0 16384
/19 255.255.224.0 8192
/20 255.255.240.0 4096
/21 255.255.248.0 2048
/22 255.255.252.0 1024
/23 255.255.254.0 512
/24 255.255.255.0 256
/25 255.255.255.128 128
/26 255.255.255.192 64
/27 255.255.255.224 32
/28 255.255.255.240 16
/29 255.255.255.248 8
/30 255.255.255.252 4
/31 255.255.255.254 2
/32 255.255.255.255 1
Note that on an Ethernet LAN (and some other similar networks), the first and last address of a network are reserved.
/31s are a special case used for point-to-point links on routers which support it.
/32s designate a single IP address, so they have specific use-cases (anycast, router IDs in networks using unnumbered interfaces...).