Tuesday, 10 October 2017

Some notes on TCP/IP - Addressing, CIDR and Masking

This came up recently during some discussions about IP addressing, subnet masks, CIDR etc.

IP address classes

With an IPv4 IP address, there are five classes of available IP ranges: Class A, Class B, Class C, Class D and Class E, while only A, B, and C are commonly used. Each class allows for a range of valid IP addresses, shown in the following table.

Ranges 127.x.x.x are reserved for the loopback or localhost, for example, is the loopback address. Range broadcasts to all hosts on the local network.

CIDR Notation

CIDR notation is a compact representation of an IP address and its associated routing prefix. The notation is constructed from an IP address, a slash ('/') character, and a decimal number. The number is the count of leading 1 bits in the routing mask, traditionally called the network mask. The IP address is expressed according to the standards of IPv4 or IPv6.

The address may denote a single, distinct interface address or the beginning address of an entire network. The maximum size of the network is given by the number of addresses that are possible with the remaining, least-significant bits below the prefix. The aggregation of these bits is often called the host identifier.

For example:

• represents the IPv4 address and its associated routing prefix, or equivalently, its subnet mask, which has 24 leading 1-bits.
• the IPv4 block represents the 1024 IPv4 addresses from to
• the IPv6 block 2001:db8::/48 represents the block of IPv6 addresses from 2001:db8:0:0:0:0:0:0 to 2001:db8:0:ffff:ffff:ffff:ffff:ffff.
• ::1/128 represents the IPv6 loopback address. Its prefix length is 128 which is the number of bits in the address.
Before the implementation of CIDR, IPv4 networks were represented by the starting address and the subnet mask, both written in dot-decimal notation. Thus, was often written as

The number of addresses of a subnet may be calculated as 2address length − prefix length, in which the address length is 128 for IPv6 and 32 for IPv4. For example, in IPv4, the prefix length /29 gives: 232 − 29 = 23 = 8 addresses.

Subnet masks

A subnet mask is a bitmask that encodes the prefix length in quad-dotted notation: 32 bits, starting with a number of 1 bits equal to the prefix length, ending with 0 bits, and encoded in four-part dotted-decimal format: A subnet mask encodes the same information as a prefix length, but predates the advent of CIDR. In CIDR notation, the prefix bits are always contiguous. Subnet masks were allowed by RFC 950 to specify non-contiguous bits until RFC 4632[4]:Section 5.1 stated that the mask must be left contiguous. Given this constraint, a subnet mask and CIDR notation serve exactly the same function.

In addition, using this CIDR/VLSM Supernet Calculator I was able to work out the CIDR notation for a common IP address of with a netmask of as 

No comments: