Timedora

1 IPv4 Addresses, Subnet Masks, and CIDR

Learn how IPv4 addresses are divided into octets, how subnet masks identify network-prefix bits, and how to convert between CIDR prefix lengths and dotted-decimal masks.

IPv4 address structure

An IPv4 address is 3232 bits long and is divided into four groups of 88 bits, called octets. Each is written as a decimal number from 00 to 255255, and periods separate the octets. For example, 192.168.1.70 contains four octets.

Subnet masks and

A separates the bits that belong to the network prefix from the bits available for addresses within that prefix. In a standard CIDR mask, the network bits are contiguous: they are 1 bits from the left, followed only by host bits represented by 0 bits.

writes an address followed by a slash and a number from 00 to 3232. That number is the . For example, 192.168.1.70/26 has 2626 prefix bits and 66 remaining host bits. CIDR makes the explicit instead of inferring it from an address’s historical class.

Convert a to a mask

To convert a to a dotted-decimal mask, each complete group of 88 prefix bits becomes an of 255. If the prefix ends partway through an , use the matching partial- value below; all following mask octets are 0.

  • 00 set bits: 00000000 = 0

  • 11 set bit: 10000000 = 128

  • 22 set bits: 11000000 = 192

  • 33 set bits: 11100000 = 224

  • 44 set bits: 11110000 = 240

  • 55 set bits: 11111000 = 248

  • 66 set bits: 11111100 = 252

  • 77 set bits: 11111110 = 254

  • 88 set bits: 11111111 = 255

For example, /26 fills the first three octets with 2424 prefix bits, giving 255.255.255. The remaining 22 prefix bits make the next 11000000, or 192, so /26 is 255.255.255.192.

Convert a mask to a

To convert a dotted-decimal mask to a , count the 1 bits in each and add the counts. For example, 255.255.255.192 contains 8+8+8+2=268+8+8+2=26 one-bits, so its is /26.

A valid CIDR must have all its 1 bits together on the left, followed only by 0 bits. 255.255.255.160 is not a valid contiguous CIDR mask: its final is 10100000, which has a 1 after a 0.

Common masks and conversion summary

The following common CIDR prefixes correspond to these dotted-decimal masks:

  • /8: 255.0.0.0

  • /16: 255.255.0.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

  • /30: 255.255.255.252

In short, an IPv4 address has four octets, totaling 3232 bits. A distinguishes prefix bits from remaining bits, while CIDR expresses the number of prefix bits as /n. To convert /n to a mask, use 255 for each complete , then the partial- value if needed. To convert a mask to CIDR, count its contiguous leading 1 bits.