How do you calculate the prefix, network, subnet, and host numbers?

Part 1 of 2

IPv4 Math

With an IPv4 address and the network mask, the network mask length, or host mask, you can calculate the Network Address, Broadcast Address, Total Addresses, Usable Addresses, First Usable Address, and Last Usable Address.

It cannot be stressed enough that you must do IPv4 math in binary. Every network engineer has tried to figure out a way to do it all in decimal, as you will*. The problem is that 10 (decimal) is not a power of 2 (binary), so decimal and binary do not easily convert between each other the way that hexadecimal (base 16) easily converts to and from binary because 16 is a power of 2. Using dotted-decimal notation for IPv4 was an early mistake that cannot now be corrected, but IPv6 adopted the use of hexadecimal from the very beginning, and it is easy to convert between hexadecimal and binary.

If you do not have an IP calculator (disallowed in exams for network courses or certifications), make a chart of the values of the bits in an octet. In binary, each bit value is 2 times the same digit value in the next less-significant digit. Each digit is the number base times the same digit value in the next less-significant digit. This is also true for all number bases, including decimal, where each digit value is 10 times the value of the same digit value in the next less-significant digit. Where decimal is powers of 10, binary is powers of 2. Notice that for each bit number in the table, the corresponding value is 2 to the power of the bit number.

+-------------------------------------------------------+
¦ BIT # ¦  7  ¦  6  ¦  5  ¦  4  ¦  3  ¦  2  ¦  1  ¦  0  ¦
¦-------+-----+-----+-----+-----+-----+-----+-----+-----¦
¦ VALUE ¦ 128 ¦ 64  ¦ 32  ¦ 16  ¦  8  ¦  4  ¦  2  ¦  1  ¦
+-------------------------------------------------------+

The dotted-decimal address 198.51.100.223

+------------------------------------------------------------------------+
¦ OCTET ¦ DEC ¦ 128 ¦ 64  ¦ 32  ¦ 16  ¦  8  ¦  4  ¦  2  ¦  1  ¦  BINARY  ¦
¦-------+-----+-----+-----+-----+-----+-----+-----+-----+-----+----------¦
¦   1   ¦ 198 ¦  1  ¦  1  ¦  0  ¦  0  ¦  0  ¦  1  ¦  1  ¦  0  ¦ 11000110 ¦
¦   2   ¦  51 ¦  0  ¦  0  ¦  1  ¦  1  ¦  0  ¦  0  ¦  1  ¦  1  ¦ 00110011 ¦
¦   3   ¦ 100 ¦  0  ¦  1  ¦  1  ¦  0  ¦  0  ¦  1  ¦  0  ¦  0  ¦ 01100100 ¦
¦   4   ¦ 223 ¦  1  ¦  1  ¦  0  ¦  1  ¦  1  ¦  1  ¦  1  ¦  1  ¦ 11011111 ¦
+------------------------------------------------------------------------+

The binary address 11000110001100110110010011011111

+------------------------------------------------------------------------+
¦ OCTET ¦  BINARY  ¦   7 ¦   6 ¦   5 ¦   4 ¦   3 ¦   2 ¦   1 ¦   0 ¦ DEC ¦
¦-------+----------+-----+-----+-----+-----+-----+-----+-----+-----+-----¦
¦   1   ¦ 11000110 ¦ 128 ¦  64 ¦   0 ¦   0 ¦   0 ¦   4 ¦   2 ¦   0 ¦ 198 ¦
¦   2   ¦ 00110011 ¦   0 ¦   0 ¦  32 ¦  16 ¦   0 ¦   0 ¦   2 ¦   1 ¦  51 ¦
¦   3   ¦ 01100100 ¦   0 ¦  64 ¦  32 ¦   0 ¦   0 ¦   4 ¦   0 ¦   0 ¦ 100 ¦
¦   4   ¦ 11011111 ¦ 128 ¦  64 ¦   0 ¦  16 ¦   8 ¦   4 ¦   2 ¦   1 ¦ 223 ¦
+------------------------------------------------------------------------+

Remember the Truth Tables from school (in binary math, 0 is False, and 1 is True).

                      +--------+                +--------+
                      ¦ RESULT ¦                ¦ RESULT ¦
+---------------------+--------¦  +-------------+--------¦
¦ False ¦ AND ¦ False ¦ FALSE  ¦  ¦ 0 ¦ AND ¦ 0 ¦ 0      ¦
¦ False ¦ AND ¦ True  ¦ FALSE  ¦  ¦ 0 ¦ AND ¦ 1 ¦ 0      ¦
¦ True  ¦ AND ¦ False ¦ FALSE  ¦  ¦ 1 ¦ AND ¦ 0 ¦ 0      ¦
¦ True  ¦ AND ¦ True  ¦ TRUE   ¦  ¦ 1 ¦ AND ¦ 1 ¦ 1      ¦
+------------------------------+  +----------------------+

                      +--------+                +--------+
                      ¦ RESULT ¦                ¦ RESULT ¦
+---------------------+--------¦  +-------------+--------¦
¦ False ¦ OR  ¦ False ¦ FALSE  ¦  ¦ 0 ¦ OR  ¦ 0 ¦ 0      ¦
¦ False ¦ OR  ¦ True  ¦ TRUE   ¦  ¦ 0 ¦ OR  ¦ 1 ¦ 1      ¦
¦ True  ¦ OR  ¦ False ¦ TRUE   ¦  ¦ 1 ¦ OR  ¦ 0 ¦ 1      ¦
¦ True  ¦ OR  ¦ True  ¦ TRUE   ¦  ¦ 1 ¦ OR  ¦ 1 ¦ 1      ¦
+------------------------------+  +----------------------+

                      +--------+                +--------+
                      ¦ RESULT ¦                ¦ RESULT ¦
        +-------------+--------¦      +---------+--------¦
        ¦ NOT ¦ False ¦ TRUE   ¦      ¦ NOT ¦ 0 ¦ 1      ¦
        ¦ NOT ¦ True  ¦ FALSE  ¦      ¦ NOT ¦ 1 ¦ 0      ¦
        +----------------------+      +------------------+

*If you perform IPv4 math for many years, you may get to the point where you can perform decimal/binary conversions in your head, and you can appear to be able to do IPv4 math in decimal. Even if you can do this in your head, always double-check with an IP calculator, or convert to binary and perform the math, before committing a change to a production network.

IPv4 Address

The IPv4 dotted-decimal notation, e.g., 198.51.100.223, is simply to make it easier for humans to read an address. The four separate sections, called octets, really have no meaning to IPv4. Do not make the common mistake of thinking the octets have a special meaning. An address is really a 32-bit binary number, and that is how network devices see and use an IPv4 address.

The example dotted-decimal address, 198.51.100.223, is binary 11000110001100110110010011011111 to a device on the network. You can see that the dotted-decimal representation really does make it easier for humans. Each octet is eight bits of the 32-bit address (hence the commonly used term, “octet”), so there are four octets (32 address bits / 8 bits per octet = 4 octets). The example 32-bit binary address is separated into four octets, then each binary octet is converted to a decimal number*.

Binary address: 11000110001100110110010011011111

+-----------------------------------------------------+
¦ OCTET   ¦        1 ¦        2 ¦        3 ¦        4 ¦
¦---------+----------+----------+----------+----------¦
¦ BINARY  ¦ 11000110 ¦ 00110011 ¦ 01100100 ¦ 11011111 ¦
¦ DECIMAL ¦      198 ¦       51 ¦      100 ¦      223 ¦
+-----------------------------------------------------+

Because each octet is eight bits in length, each octet will have a value between 0 and 255 (any values greater than 255 are invalid). The reason is that 28 = 256: 2 (the binary number base) to the power of 8 (eight bits per octet) equals 256, the number of different values that can be expressed by an eight-bit octet. Remember that the first value is 0, so the 256th value will be one less that the total number of values that can be expressed (256 – 1 = 255).

To correctly perform IPv4 math, you must do it in binary, otherwise you will make mistakes that will cause you problems and frustration. That means that you must convert the dotted-decimal notation to binary before trying to manipulate it.

Dotted-decimal: 198.51.100.223

+-----------------------------------------------------+
¦ OCTET   ¦        1 ¦        2 ¦        3 ¦        4 ¦
¦---------+----------+----------+----------+----------¦
¦ DECIMAL ¦      198 ¦       51 ¦      100 ¦      223 ¦
¦ BINARY  ¦ 11000110 ¦ 00110011 ¦ 01100100 ¦ 11011111 ¦
+-----------------------------------------------------+

*Leading zeroes in a dotted-decimal IPv4 address may be interpreted by some applications and programming languages as octal (base 8) rather than decimal (base 10), causing errors, and leading zeros should be avoided for the dotted-decimal IPv4 representation, but leading zeroes are necessary for the binary address octets because they represent bit positions in the full address, and leaving out a bit position will shorten the address and change the binary value.

IPv4 Network Mask

A network mask is used to divide an address into two parts: Network and Host. Because IPv4 addresses are fixed 32-bits in length, a larger Network means a smaller Host, and vice versa. The division can be at any bit number, so it may fall within an octet, not on an octet boundary (as many people incorrectly assume it always does). A network mask is the same size as an address (32 bits), and it is expressed in dotted-decimal notation the same way you would express an address in dotted-decimal notation (four 8-bit octets, separated by a period). For example, 255.255.248.0.

A network mask consists of consecutive 1 bits (representing the Network), followed by the number of 0 bits (representing the Host) to total 32 bits (the address length). The number of 1 bits plus the number of 0 bits totals 32, the number of bits in an IPv4 address or network mask. For example, a network mask of 255.255.248.0.

+--------------------------------------------------------+
¦ OCTET   ¦        1 ¦        2 ¦           3 ¦        4 ¦
¦---------+----------+----------+-------------+----------¦
¦ DECIMAL ¦      255 ¦      255 ¦         248 ¦        0 ¦
¦---------+----------+----------+-------------+----------¦
¦ BINARY  ¦ 11111111 ¦ 11111111 ¦ 11111 ¦ 000 ¦ 00000000 ¦
¦---------+-----------------------------+----------------¦
¦ # BITS  ¦         21 Network          ¦    11 Host     ¦
+--------------------------------------------------------+

As you can see, the division between Network and Host of the address using this mask falls within an octet, not on an octet boundary.

A network mask is often represented by the number of consecutive 1 bits in the mask. This is variously called the network mask length or prefix length, and it is represented as a / followed by the number of consecutive 1 bits in the network mask. Counting the number of consecutive 1 bits in the example totals 21, which can be represented as /21.

Given a mask length, you can calculate the dotted-decimal representation of the mask. Simply put down the number of 1 bits for the mask length and add enough 0 bits on the end to total 32 bits. Convert the resulting binary number into the dotted-decimal representation.

+--------------------------------------------------------+
¦ # BITS  ¦         21 Network          ¦    11 Host     ¦
¦---------+-----------------------------+----------------¦
¦ BINARY  ¦ 11111111 ¦ 11111111 ¦ 11111 ¦ 000 ¦ 00000000 ¦
¦---------+----------+----------+-------------+----------¦
¦ DECIMAL ¦      255 ¦      255 ¦         248 ¦        0 ¦
¦---------+----------+----------+-------------+----------¦
¦ OCTET   ¦        1 ¦        2 ¦           3 ¦        4 ¦
+--------------------------------------------------------+

The example 198.51.100.223 address may be represented traditionally with the example network mask as 198.51.100.223 255.255.248.0, or it may be represented in the more modern CIDR (Classless Inter-Domain Routing) notation as 198.51.100.223/21. Either representation is valid, and you can easily convert between the mask and the mask length as required (OSes and applications will require a specific representation).

IPv4 Network Address

A network address is an address with all Host bits set to 0. The network address can be calculated by a bitwise AND of the respective bits in the binary representation of the address and the network mask. Align the bits, perform a bitwise AND on each pair of the respective bits, then convert the individual octets of the result back to decimal.

For example, the IPv4 address 198.51.100.223 and network mask 255.255.248.0

+-------------------------------------------------------------+
¦ OCTET           ¦        1 ¦        2 ¦        3 ¦        4 ¦
¦-----------------+----------+----------+----------+----------¦
¦ BINARY ADDRESS  ¦ 11000110 ¦ 00110011 ¦ 01100100 ¦ 11011111 ¦
¦ BINARY MASK     ¦ 11111111 ¦ 11111111 ¦ 11111000 ¦ 00000000 ¦
¦ BITWISE AND     ¦ 11000110 ¦ 00110011 ¦ 01100000 ¦ 00000000 ¦
¦-----------------+----------+----------+----------+----------¦
¦ DECIMAL NETWORK ¦      198 ¦       51 ¦       96 ¦        0 ¦
+-------------------------------------------------------------+

The network address of 198.51.100.223/21 is 198.51.96.0. Notice that you cannot depend on the octets to distinguish between Network and Host.

This method is used to determine if two addresses are on the same or different networks*. For example, if you want to determine if your example address is on the same network with a target address, 198.51.102.57, find the example network address (as above). Next, find the target network address using the same network mask (addresses on the same network use the same network mask, and you may not have the target mask, only the target address).

+-------------------------------------------------------------+
¦ OCTET           ¦        1 ¦        2 ¦        3 ¦        4 ¦
¦-----------------+----------+----------+----------+----------¦
¦ BINARY ADDRESS  ¦ 11000110 ¦ 00110011 ¦ 01100110 ¦ 00111001 ¦
¦ BINARY MASK     ¦ 11111111 ¦ 11111111 ¦ 11111000 ¦ 00000000 ¦
¦ BITWISE AND     ¦ 11000110 ¦ 00110011 ¦ 01100000 ¦ 00000000 ¦
¦-----------------+----------+----------+----------+----------¦
¦ DECIMAL NETWORK ¦      198 ¦       51 ¦       96 ¦        0 ¦
+-------------------------------------------------------------+

Compare the target network address to the example network address, and notice that the network addresses are equal, meaning the example and target addresses are on the same network.

Now, test if the example address is on the same network as the 74.125.69.100 Google address.

+-------------------------------------------------------------+
¦ OCTET           ¦        1 ¦        2 ¦        3 ¦        4 ¦
¦-----------------+----------+----------+----------+----------¦
¦ BINARY ADDRESS  ¦ 01001010 ¦ 01111101 ¦ 01000101 ¦ 01100100 ¦
¦ BINARY MASK     ¦ 11111111 ¦ 11111111 ¦ 11111000 ¦ 00000000 ¦
¦ BITWISE AND     ¦ 01001010 ¦ 01111101 ¦ 01000000 ¦ 00000000 ¦
¦-----------------+----------+----------+----------+----------¦
¦ DECIMAL NETWORK ¦       74 ¦      125 ¦       64 ¦        0 ¦
+-------------------------------------------------------------+

Compare the target network address to the example network address, and notice that the network addresses are different, meaning the example and target addresses are not on the same network.

*This is the method a source uses to determine if a destination is on the same network as the source. Packets destined to a different network must be sent to a router for forwarding to a different network.

IPv4 Host Mask

One useful, often overlooked, value for IPv4 addressing is the host mask. A host mask is simply the inverse (bitwise NOT) of the network mask.

Network mask to host mask

+-----------------------------------------------------------------+
¦ OCTET #             ¦        1 ¦        2 ¦        3 ¦        4 ¦
¦---------------------+----------+----------+----------+----------¦
¦ BINARY NETWORK MASK ¦ 11111111 ¦ 11111111 ¦ 11111000 ¦ 00000000 ¦
¦ BITWISE NOT         ¦ 00000000 ¦ 00000000 ¦ 00000111 ¦ 11111111 ¦
¦---------------------+----------+----------+----------+----------¦
¦ HOST MASK           ¦        0 ¦        0 ¦        7 ¦      255 ¦
+-----------------------------------------------------------------+

Host mask to network mask

+--------------------------------------------------------------+
¦ OCTET #          ¦        1 ¦        2 ¦        3 ¦        4 ¦
¦------------------+----------+----------+----------+----------¦
¦ BINARY HOST MASK ¦ 00000000 ¦ 00000000 ¦ 00000111 ¦ 11111111 ¦
¦ BITWISE NOT      ¦ 11111111 ¦ 11111111 ¦ 11111000 ¦ 00000000 ¦
¦------------------+----------+----------+----------+----------¦
¦ NETWORK MASK     ¦      255 ¦      255 ¦      248 ¦        0 ¦
+--------------------------------------------------------------+

It is possible to use subtraction to create a host mask from the network mask, or the network mask from the host mask by subtracting the starting mask from the longest mask (/32 all-ones mask 255.255.255.255).

Binary network mask to host mask

+-----------------------------------------------------------------+
¦ OCTET #             ¦        1 ¦        2 ¦        3 ¦        4 ¦
¦---------------------+----------+----------+----------+----------¦
¦ BINARY /32 MASK     ¦ 11111111 ¦ 11111111 ¦ 11111111 ¦ 11111111 ¦
¦ BINARY NETWORK MASK ¦ 11111111 ¦ 11111111 ¦ 11111000 ¦ 00000000 ¦
¦ SUBTRACTION         ¦ 00000000 ¦ 00000000 ¦ 00000111 ¦ 11111111 ¦
¦---------------------+----------+----------+----------+----------¦
¦ HOST MASK           ¦        0 ¦        0 ¦        7 ¦      255 ¦
+-----------------------------------------------------------------+

Binary host mask to network mask

+--------------------------------------------------------------+
¦ OCTET #          ¦        1 ¦        2 ¦        3 ¦        4 ¦
¦------------------+----------+----------+----------+----------¦
¦ BINARY /32 MASK  ¦ 11111111 ¦ 11111111 ¦ 11111111 ¦ 11111111 ¦
¦ BINARY HOST MASK ¦ 00000000 ¦ 00000000 ¦ 00000111 ¦ 11111111 ¦
¦ SUBTRACTION      ¦ 11111111 ¦ 11111111 ¦ 11111000 ¦ 00000000 ¦
¦------------------+----------+----------+----------+----------¦
¦ NETWORK MASK     ¦      255 ¦      255 ¦      248 ¦        0 ¦
+--------------------------------------------------------------+

Decimal network mask to host mask

+------------------------------------------+
¦ OCTET #          ¦   1 ¦   2 ¦   3 ¦   4 ¦
¦------------------+-----+-----+-----+-----¦
¦ DECIMAL /32 MASK ¦ 255 ¦ 255 ¦ 255 ¦ 255 ¦
¦ NETWORK MASK     ¦ 255 ¦ 255 ¦ 248 ¦   0 ¦
¦------------------+-----+-----+-----+-----¦
¦ HOST MASK        ¦   0 ¦   0 ¦   7 ¦ 255 ¦
+------------------------------------------+

Decimal Host mask to Network mask

+------------------------------------------+
¦ OCTET #          ¦   1 ¦   2 ¦   3 ¦   4 ¦
¦------------------+-----+-----+-----+-----¦
¦ DECIMAL /32 MASK ¦ 255 ¦ 255 ¦ 255 ¦ 255 ¦
¦ HOST MASK        ¦   0 ¦   0 ¦   7 ¦ 255 ¦
¦------------------+-----+-----+-----+-----¦
¦ NETWORK MASK     ¦ 255 ¦ 255 ¦ 248 ¦   0 ¦
+------------------------------------------+

IPv4 Network Broadcast Address

A network broadcast address is the network address with all the host bits set to 1. There are several ways to calculate the network broadcast address.

For example, address 198.51.100.223 and network mask 255.255.248.0.

You can perform a bitwise OR with the address or network address with the host mask.

+---------------------------------------------------------------+
¦ OCTET             ¦        1 ¦        2 ¦        3 ¦        4 ¦
¦-------------------+----------+----------+----------+----------¦
¦ BINARY ADDRESS    ¦ 11000110 ¦ 00110011 ¦ 01100100 ¦ 11011111 ¦
¦ BINARY HOST MASK  ¦ 00000000 ¦ 00000000 ¦ 00000111 ¦ 11111111 ¦
¦ BITWISE OR        ¦ 11000110 ¦ 00110011 ¦ 01100111 ¦ 11111111 ¦
¦-------------------+----------+----------+----------+----------¦
¦ BROADCAST ADDRESS ¦      198 ¦       51 ¦      103 ¦      255 ¦
+---------------------------------------------------------------+

You can simply add the value of the host mask to the value of the network address (not the host address) and you can do this either in decimal or binary.

Decimal

+-------------------------------------------+
¦ OCTET #           ¦   1 ¦   2 ¦   3 ¦   4 ¦
¦-------------------+-----+-----+-----+-----¦
¦ DECIMAL NETWORK   ¦ 198 ¦  51 ¦  96 ¦   0 ¦
¦ DECIMAL HOST MASK ¦   0 ¦   0 ¦   7 ¦ 255 ¦
¦-------------------+-----+-----+-----+-----¦
¦ BROADCAST ADDRESS ¦ 198 ¦  51 ¦ 103 ¦ 255 ¦
+-------------------------------------------+

Binary

+--------------------------------------------------------------+
¦ OCTET #          ¦        1 ¦        2 ¦        3 ¦        4 ¦
¦------------------+----------+----------+----------+----------¦
¦ BINARY NETWORK   ¦ 11000110 ¦ 00110011 ¦ 01100000 ¦ 00000000 ¦
¦ BINARY HOST MASK ¦ 00000000 ¦ 00000000 ¦ 00000111 ¦ 11111111 ¦
¦ ADDITION         ¦ 11000110 ¦ 00110011 ¦ 01100111 ¦ 11111111 ¦
¦------------------+----------+----------+----------+----------¦
¦ NETWORK MASK     ¦      198 ¦       51 ¦      103 ¦      255 ¦
+--------------------------------------------------------------+

Total IPv4 Network Host Addresses

The total number of host addresses for a network is 2 to the power of the number of host bits, which is 32 (IPv4 address bits) minus the number of network bits. For example, for a /21 (network mask 255.255.248.0) network, there are 11 host bits (32 address bits – 21 network bits = 11 host bits). That means there are 2048 total host addresses in a /21 network (211 = 2048).

Total Usable IPv4 Network Host Addresses

Except for /31 (255.255.255.254) and /32 (255.255.255.255) networks, the number of usable host addresses in a network is the total number of network host addresses minus 2 (because the network and broadcast addresses are unusable for host addresses on the network, you must subtract them from the number of usable host addresses). For example, in a /21 (255.255.248.0) network, there are 2046 usable host addresses (211 - 2 = 2046).

First Usable IPv4 Network Host Address

Except for /31 (255.255.255.254) and /32 (255.255.255.255) networks, the first usable network host address is the network address plus (either addition or bitwise OR) 1 (the network address is not usable for a network host address). For example, in the 198.51.96.0/21 network, the first usable network host address is 198.51.96.1 (198.51.96.0 + 1 = 198.51.96.1 or 198.51.96.0 OR 1 = 198.51.96.1). Set the low-order bit of the binary network address to 1.

+------------------------------------------------------------------+
¦ OCTET                ¦        1 ¦        2 ¦        3 ¦        4 ¦
¦----------------------+----------+----------+----------+----------¦
¦ BINARY NETWORK       ¦ 11000110 ¦ 00110011 ¦ 01100000 ¦ 00000000 ¦
¦ 1                    ¦ 00000000 ¦ 00000000 ¦ 00000000 ¦ 00000001 ¦
¦ ADD (OR)             ¦ 11000110 ¦ 00110011 ¦ 01100000 ¦ 00000001 ¦
¦----------------------+----------+----------+----------+----------¦
¦ FIRST USABLE ADDRESS ¦      198 ¦       51 ¦       96 ¦        1 ¦
+------------------------------------------------------------------+

Last Usable IPv4 Network Host Address

Except for /31 (255.255.255.254) and /32 (255.255.255.255) networks, the last usable network host address is the network broadcast address minus 1 (the network broadcast address is not usable for a network host address). For example, in the 198.61.96.0/21 network, the last usable network host address is 198.51.103.254 (198.51.103.255 - 1 = 198.51.103.254). Set the low-order bit of the binary IPv4 network broadcast address to 0.

+----------------------------------------------------------------------+
¦ OCTET                    ¦        1 ¦        2 ¦        3 ¦        4 ¦
¦--------------------------+----------+----------+----------+----------¦
¦ BINARY BROADCAST ADDRESS ¦ 11000110 ¦ 00110011 ¦ 01100111 ¦ 11111111 ¦
¦ 1                        ¦ 00000000 ¦ 00000000 ¦ 00000000 ¦ 00000001 ¦
¦ SUBTRACT                 ¦ 11000110 ¦ 00110011 ¦ 01100111 ¦ 11111110 ¦
¦--------------------------+----------+----------+----------+----------¦
¦ LAST  USABLE ADDRESS     ¦      198 ¦       51 ¦      103 ¦      254 ¦
+----------------------------------------------------------------------+

IPv4 /31 (255.255.255.254) Networks

Originally, /31 (255.255.255.254) networks were unusable because there is only one host bit, giving you two total network host addresses, but the number of usable network host addresses is the total number of network host addresses minus 2 (2 total host addresses - 2 = 0 usable host addresses).

Point-to-point links only need two host addresses (one for each end of the link). The traditional way of assigning IPv4 networks required the use of /30 (255.255.255.252) networks for point-to-point links, but that wastes half the network host addresses because a /30 network has four total network host addresses, but only two are usable network host addresses (22 – 2 = 2).

With the critical IPv4 address shortage, a standard was created (RFC 3021, Using 31-Bit Prefixes on IPv4 Point-to-Point Links) to allow the use of /31 networks for point-to-point links. That makes sense because there is no need for broadcast on such networks: any packets sent by a host on the network are destined for the only other host on the network, effectively broadcasting. In a /31 network, the network address is the first usable host address, and the broadcast address is the last usable host address.

Unfortunately, not all vendors (Microsoft in particular) support the standard for using /31 networks on point-to-point links, and you will most often see point-to-point links using /30 networks.

IPv4 /32 (255.255.255.255) Networks

A /32 (255.255.255.255) network is both a network with no host addresses, and a host address, itself. There is only one address in the network, and that is the network address. Because there are no other hosts are on the network, traffic must be routed to and from the network address.

These addresses are often used on virtual network interfaces defined inside a device that can route packets between its virtual and physical interfaces. An example of this is to create a virtual interface in a network device to be used as the source or destination for the device itself. A virtual interface cannot drop because of a physical problem, e.g., cable unplugged, and if the device has multiple paths into it, other devices can still communicate with the device using the virtual interface address when a physical interface of the device is inoperable for some reason.

Putting IPv4 Network Addressing All Together

For example, the network address 198.51.100.223 and mask 255.255.248.0 (or 198.51.100.223/21), we can calculate the network information.*

+--------------------------------------------+
¦ HOST ADDRESS              ¦ 198.51.100.223 ¦
¦ NETWORK MASK              ¦  255.255.248.0 ¦
¦ NETWORK MASK LENGTH       ¦             21 ¦
¦ HOST MASK                 ¦      0.0.7.255 ¦
¦ HOST MASK LENGTH          ¦             11 ¦
¦ NETWORK ADDRESS           ¦    198.51.96.0 ¦
¦ FIRST USABLE HOST ADDRESS ¦    198.51.96.1 ¦
¦ LAST USABLE HOST ADDRESS  ¦ 198.51.103.254 ¦
¦ NETWORK BROADCAST ADDRESS ¦ 198.51.103.255 ¦
¦ TOTAL HOST ADDRESSES      ¦           2048 ¦
¦ USABLE HOST ADDRESSES     ¦           2046 ¦
+--------------------------------------------+

*Network education class exams and certification tests will ask you to be able to quickly calculate these values, given a host address and mask (or mask length). You can use the hints below for a quick check of your answers:

  • Network Address (hint: an even number)
  • First Usable Host Address (hint: Network Address plus 1, an odd number)
  • Last Usable Host Address (hint: Broadcast Address minus 1, an even number)
  • Broadcast Address (hint: Network Address plus Host Mask, an odd number)

The above hints do not apply to /31 (255.255.255.254) or /32 (255.255.255.255) networks.

Given enough time on your exam, and a problem that has multiple methods to arrive at an answer, you should use the multiple methods to double-check the answer.

Continued in Part 2…