Timedora

1 IPv4 Addressing and CIDR Fundamentals

Learn how IPv4 addresses are represented, how subnet masks divide network and host bits, and how CIDR notation identifies address blocks.

structure

An is a 32-bit value presented as four decimal octets separated by periods. For example, 192.168.10.77 contains the octets 192, 168, 10, and 77; each contains 88 bits and ranges from 00 to 255255.

An address can be understood as two parts: the , which identifies a block of addresses, and the remaining , which identify an address within that block. A or CIDR prefix length specifies where the network bits end and the begin.

Binary and decimal conversion

Each bit in an has a place value. From the leftmost bit to the rightmost bit, the values are 128128, 6464, 3232, 1616, 88, 44, 22, and 11. To convert binary to decimal, add the place values corresponding to bits that are 11.

For example, 1100000011000000 represents 128+64=192128+64=192, while 0100110101001101 represents 64+8+4+1=7764+8+4+1=77. To convert decimal to binary, express the decimal value as a sum of place values and mark those positions with 11. Thus, 77=64+8+4+177=64+8+4+1, giving 0100110101001101.

The address 192.168.10.77 in binary is:

The binary representation has four octets of 88 bits each, for a total of 3232 bits.

Subnet masks and network addresses

A is another 32-bit value. Its leading 11 bits mark the , and its remaining 00 bits mark the host portion. In a valid contiguous mask, all the 11 bits come first, followed by all the 00 bits.

For example, 255.255.255.192 is represented in binary as:

This mask has 2626 leading 11 bits and 66 trailing 00 bits. To find the network address, apply a between the IP address and its mask: each result bit is 11 only when both corresponding input bits are 11.

For 192.168.10.77 with mask 255.255.255.192, the operation is:

The result is 192.168.10.64. The first three octets remain unchanged because their mask bits are all 11; in the last , 7777 AND 192192 equals 6464.

CIDR prefixes and address blocks

writes an followed by a slash and a decimal prefix length from 00 through 3232. The number after the slash specifies how many leading bits belong to the . For example, /26 means 2626 network bits and 66 .

To convert a prefix length to a mask, write that many 11 bits from the left, fill the remaining bits with 00 bits, and group them into octets. These examples show the prefix, corresponding mask, and number of network and :

  • /8: mask 255.0.0.0; 88 network bits and 2424 .

  • /16: mask 255.255.0.0; 1616 network bits and 1616 .

  • /24: mask 255.255.255.0; 2424 network bits and 88 .

  • /26: mask 255.255.255.192; 2626 network bits and 66 .

  • /30: mask 255.255.255.252; 3030 network bits and 22 .

  • /32: mask 255.255.255.255; 3232 network bits and 00 .

For example, 172.16.5.9/16 means that the first 1616 bits—172.16—are the prefix. CIDR makes the prefix length explicit; it is not inferred from the address’s first .

For a prefix of length pp, the number of addresses in its block is:

232−p2^{32-p}

Thus, a /26 block contains 26=642^6=64 addresses. The address written before the slash is not necessarily the block’s starting network address. Apply the mask to find the network address, as in the example using 192.168.10.77 and 255.255.255.192.