# What is prefix and prefix length in IPv6, Similarity between IPv4 subnet mask CIDR notation and IPv6 prefix

Before learning what is IPv6 address network prefix, and IPv6 address network prefix length, let us try to understand what is CIDR notation (Classless Inter-Domain Routing).

We had already learned from our previous IPv4 lessons that an IP address (IPv4 or IPv6) consists of two parts; a NETWORK part and a HOST part. NETWORK part is used to identify the network that the specified address belongs to, and the HOST part is used to identify the host (a server, a workstation, a printer etc.) within that network. In an IPv4 address, we use subnet mask to differentiate between the network part and the host part.

For example, consider the below Class B IPv4 address:

Above IPv4 address format is exactly what we use, when we configure IPv4 address in a Windows Operating System based computer. Please refer below image, where you can see the text-boxes where you can enter IPv4 address and its subnet mask.

Here 172.16 - denotes the network part and 133.18 denotes the host part.

The meaning is that, where 255 is appearing in the subnet mask, that part of the IPv4 address belongs to the network part, and where 0 is appearing in the subnet mask, that part of the IPv4 address belongs to the host part.

We had already learned that IPv4 addresses and its subnet mask are really 32-bit binary numbers, represented as decimal numbers to handle IPv4 addresses easily. The equivalent of the decimal number 255 in binary number system is 11111111. So, the first two 255 numbers in above shown subnet mask can be represented as 1111111111111111. If you count all the 1-bits, there are total sixteen 1-bits in the subnet mask. Those left-most 1-bits belongs to the network part. There are sixteen 0-bits remaining in the right-most side of above subnet mask. Those sixteen 0-bits belongs to the host part.

There is another way of representing above IPv4 address, without using its subnet mask. An un-subnetted Class B IPv4 address can also be represented as 172.16.133.18/16, which means that the first sixteen bits of the above IPv4 address belongs to the network part, and hence the remaining sixteen bits belongs to the host part. This way of representing an IPv4 address is called as CIDR notation (Classless Inter-Domain Routing).

## What is IPv6 Network Prefix

IPv6 addresses use a similar mechanism as described above, called IPv6 network prefixes to identify the network part and the host part. The leftmost fields of the IPv6 address along with the network bits length represented in CIDR notation is known as the network prefix. The prefixes in IPv6 can be considered similar to the subnet mask used in IPv4 addresses. In IPv6, we use a notation similar to CIDR notation (using a decimal number between 1-128 to represent the network bits) representation in IPv4.

For example, in next IPv6 address 2001:0DB8:0000:000b:0000:0000:0000:001A/64, the first sixty-four bits, that is, 2001:0DB8:0000:000b::/64 represents the network prefix and the possible IPv6 addresses ranges from 2001:0DB8:0000:000b:0000:0000:0000:0001/64 to 2001:0DB8:0000:000b:ffff:ffff:ffff:ffff/64.

You can see that the above IPv6 network prefix representation is similar to IPv4 network address and subnet mask representation. 172.16.0.0/16 represents all IPv4 addresses from 172.16.0.0 to 172.16.255.255.

Note that the network prefix shown above, 2001:0DB8:0000:000b::/64, includes the 48 bit IPv6 global routing prefix 2001:0DB8:0000::/48 and the next 16 bits "000b" are used for internal subnetting within an organization.

## What is IPv6 Prefix Length

IPv6 Prefix Length is used to identify how many bits of a Global Unicast IPv6 Address are there in network part. For example, in 2001:0DB8:0000:000b::/64, the number 64 is used to identify that the first 64 bits are in network part, and in this case the number 64 is the prefix length.