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 bits and ranges from to .
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 , , , , , , , and . To convert binary to decimal, add the place values corresponding to bits that are .
For example, represents , while represents . To convert decimal to binary, express the decimal value as a sum of place values and mark those positions with . Thus, , giving .
The address 192.168.10.77 in binary is:
The binary representation has four octets of bits each, for a total of bits.
Subnet masks and network addresses
A is another 32-bit value. Its leading bits mark the , and its remaining bits mark the host portion. In a valid contiguous mask, all the bits come first, followed by all the bits.
For example, 255.255.255.192 is represented in binary as:
This mask has leading bits and trailing bits. To find the network address, apply a between the IP address and its mask: each result bit is only when both corresponding input bits are .
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 ; in the last , AND equals .
CIDR prefixes and address blocks
writes an followed by a slash and a decimal prefix length from through . The number after the slash specifies how many leading bits belong to the . For example, /26 means network bits and .
To convert a prefix length to a mask, write that many bits from the left, fill the remaining bits with bits, and group them into octets. These examples show the prefix, corresponding mask, and number of network and :
/8: mask255.0.0.0; network bits and ./16: mask255.255.0.0; network bits and ./24: mask255.255.255.0; network bits and ./26: mask255.255.255.192; network bits and ./30: mask255.255.255.252; network bits and ./32: mask255.255.255.255; network bits and .
For example, 172.16.5.9/16 means that the first 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 , the number of addresses in its block is:
Thus, a /26 block contains 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.