Computer Networks / Practical class / Practical class 2
Practical class · Computer Networks

IPv6 addressing and structure

IPv4’s 4.3 billion addresses are not even enough for the world’s smartphones today. The solution is IPv6: 128-bit addresses, about 3.4·1038 of them — enough for every grain of sand on Earth. Today you will learn the rules for shortening and writing out in full long, «scary»-looking addresses such as 2001:0db8:0000:0000:0000:ff00:0042:8329, tell the address types apart, build an interface identifier from a MAC address and check everything with Python’s ipaddress module.

:ik-kitob: Practical class 2 ⏱ 2 academic hours (80 minutes) 🚇 Packet simulators ⚡ 128 bits — unlimited addresses
02

Lesson goals and plan

By the end of the lesson you will…

  • You can explain the structure of an IPv6 address (128 bits, 8 groups of 16 bits, hexadecimal notation)
  • You can shorten an address and write it out in full by applying the zero-compression and “::” rules (RFC 5952)
  • You can tell global unicast, link-local, ULA, multicast and loopback addresses apart by their prefix
  • You can split an address into the prefix (/64) and the interface identifier
  • You can build an interface identifier from a MAC address using the EUI-64 method
  • You can compare IPv4 and IPv6 by their main characteristics

Plan (according to the syllabus)

  1. IPv6 addressing and structure

The golden rule of not getting lost in IPv6: “::” only once! If you write it twice, nobody (not even the computer) will know how many zeros were hidden. The second rule: every group is 4 hexadecimal digits = 16 bits.

What is the fe80::4d2a:91c3:7b1e:2f10%12 you saw in ipconfig?

In the last class we read the IPv4 address, but above it there was also a strange, long string with colons. That is your computer’s IPv6 address. You never configured it — it appeared by itself. How? And why is there a “::” in the middle? Today we will uncover these secrets.

Key terms

Theory reminder

An IPv6 address is 128 bits. It is divided into 8 groups of 16 bits, and each group is written as 4 hexadecimal (hex) digits (one hex digit = 4 bits). For example:

full (exploded) form2001:0db8:0000:0000:0000:ff00:0042:8329
 g1   g2   g3   g4   g5   g6   g7   g8
# each group: 4 hex digits × 4 bits = 16 bits;  8 × 16 = 128 bits
Table 2.1. Shortening rules (RFC 5952 — the recommended notation)
№RuleExample
1Leading zeros in each group are dropped (at least one digit remains)0db8 → db8, 0042 → 42, 0000 → 0
2Two or more consecutive zero groups are replaced with ::2001:db8:0:0:0:ff00:42:8329 → 2001:db8::ff00:42:8329
3:: is used only once in an address; the longest chain of zeros is chosen2001:0:0:1:0:0:0:1 → 2001:0:0:1::1
4If the lengths are equal, the first (leftmost) chain is shortened2001:db8:0:0:1:0:0:1 → 2001:db8::1:0:0:1
5A single lone zero group is not shortened with ::2001:db8:0:1:1:1:1:1 stays unchanged
6Letters are written in lowercase2001:DB8::FF → 2001:db8::ff
Table 2.2. Main IPv6 address types
TypePrefixStarts withIPv4 equivalent
Global unicast2000::/32… or 3…public address
Link-localfe80::/10fe80:…169.254.x.x (APIPA)
Unique local (ULA)fc00::/7fc… or fd…10.x, 172.16–31.x, 192.168.x
Multicastff00::/8ff…224.0.0.0/4 (class D)
Loopback::1/128::1127.0.0.1
Unspecified::/128::0.0.0.0

IPv6 has no broadcast — multicast takes its place. The prefix of a typical LAN segment is /64: the first 64 bits are the network (global routing prefix + subnet ID), the last 64 bits are the interface identifier.

2001:0db8:abcd0012021a:2bff:fe3c:4d5e Global routing prefix (48 bits) Subnet ID (16) Interface identifier (64 bits) ◀── network prefix /64 ──▶ ◀── device ──▶
Fig. 2.1. Typical structure of a global unicast address: 48 + 16 + 64 bits
Python: ipaddress and IPv6import ipaddress
a = ipaddress.IPv6Address("2001:0db8:0000:0000:0000:ff00:0042:8329")
a.compressed    # '2001:db8::ff00:42:8329'
a.exploded      # '2001:0db8:0000:0000:0000:ff00:0042:8329'
a.is_link_local, a.is_multicast, a.is_loopback
a in ipaddress.ip_network("2000::/3")          # is it global unicast?
ipaddress.ip_interface("2001:db8:1:2::7/64").network  # 2001:db8:1:2::/64
Table 2.3. A short comparison of IPv4 and IPv6
FeatureIPv4IPv6
Length32 bits128 bits
Entrydotted decimalhexadecimal with colons
Number of addresses≈ 4,3·109≈ 3,4·1038
Broadcastyesno (multicast)
AutoconfigurationDHCP (or manual)SLAAC (self-configured), DHCPv6
Need for NATwidely usedusually not needed

IPv6 addressing and structure

Three sample tasks: shortening, writing in full, and building an interface identifier from a MAC. Then you will see the shortening step by step in a simulator and test yourself.

Sample task 1. Shortening

Given: 2001:0db8:0000:0000:0000:ff00:0042:8329

  1. Drop the leading zeros

    2001:db8:0:0:0:ff00:42:8329 — at least one digit remains in every group.

  2. Find the longest chain of zero groups

    Groups 3, 4 and 5: 0:0:0 — length 3.

  3. Replace the chain with “::”

    2001:db8::ff00:42:8329.

  4. Check: how many groups were hidden?

    Visible groups: 5. 8 − 5 = 3 zero groups are hidden inside “::”. ✓

Sample task 2. Writing in full (expand)

Given: fe80::21a:2bff:fe3c:4d5e

  1. Count the visible groups

    fe80, 21a, 2bff, fe3c, 4d5e — 5 of them. So “::” stands for 8 − 5 = 3 groups of 0000.

  2. Pad every group to 4 digits

    21a → 021a.

  3. Result

    fe80:0000:0000:0000:021a:2bff:fe3c:4d5e.

Sample task 3. EUI-64: MAC → interface identifier

Given: MAC 00:1A:2B:3C:4D:5E (48 bits). Needed: a 64-bit identifier and the link-local address.

  1. Split the MAC in the middle and insert fffe

    00:1A:2B | FF:FE | 3C:4D:5E → 001A:2BFF:FE3C:4D5E.

  2. Flip the 7th bit of the first byte (the U/L bit)

    00 = 00000000 → 00000010 = 02. In Python: 0x00 ^ 0x02.

  3. Identifier

    021a:2bff:fe3c:4d5e.

  4. Link-local address

    fe80:: + identifier → fe80::21a:2bff:fe3c:4d5e.

Did you know?

An EUI-64 address “gives away” the device’s MAC address — handy for tracking. That is why systems such as Windows, Android and iOS usually generate the interface identifier randomly (privacy extensions). The fe80::4d2a:91c3:7b1e:2f10 from ipconfig above is like that too — it has no ff:fe.

Simulator: the “::” shortener

Enter an address (full or partially shortened) and press “Next step” to watch how the rules are applied. Then, in Practice mode, shorten a random address yourself — the widget checks your answer.

:ik-asbob: IPv6 shortener

Short (compressed)—
Type—

Shorten this address:

IPv6 on your computer

cmd.exe
C:\Users\Talaba> ipconfig

Wireless LAN adapter Wi-Fi:
   IPv6 Address. . . . . . . . . . . : 2a02:e98:20:1a5::3c
   Temporary IPv6 Address. . . . . . : 2a02:e98:20:1a5:c1d0:5e2:9a7b:11f4
   Link-local IPv6 Address . . . . . : fe80::4d2a:91c3:7b1e:2f10%12
   IPv4 Address. . . . . . . . . . . : 192.168.1.105

C:\Users\Talaba> ping ::1

Pinging ::1 with 32 bytes of data:
Reply from ::1: time<1ms
Reply from ::1: time<1ms

Reading it: A global address (starting with 2…) appears if your provider supports IPv6; some home networks have only a link-local address. %12 is the zone index: it shows which interface the link-local address belongs to (every interface has fe80::, so it must be specified). “Temporary” is a temporary random address for privacy. The addresses are samples (yours will be different).

Independent tasks

7 tasks. You may use import ipaddress. The output text must match the sample.

Common mistakes

ErrorWhy it is wrongCorrect answer
2001:db8::1::2“::” twice — the number of zeros is ambiguousonly one “::”
2001:db8:0:0:0:0:0:1 → 2001:db8:0::1the longest chain was not fully shortened2001:db8::1
2001:0db8 → 2001:db80dropping a trailing zero changes the value!only leading zeros are dropped: db8
Counting one group as 8 bitsConfusing it with an IPv4 octetgroup = 4 hex = 16 bits
In EUI-64, inserting fffe but not flipping the 7th bitthe identifier is wrongin the first byte, ^ 0x02
“IPv6 has broadcast too”IPv6 has no broadcastmulticast, e.g. ff02::1 — all nodes on the segment

Boss level

Boss level: IPv6 passport

Input: address/prefix (for example, 2001:0DB8:ABCD:0012:0000:0000:0000:0001/64). Print exactly 5 lines in this format:

Qisqa: 2001:db8:abcd:12::1
To‘liq: 2001:0db8:abcd:0012:0000:0000:0000:0001
Turi: Global unicast
Tarmoq: 2001:db8:abcd:12::/64
Subnetlar soni (/64): 1

Turi — the names from task 5. Subnetlar soni (/64) — how many /64 networks fit inside the given prefix: 264 − prefix (0 if the prefix is greater than 64). For example, if a provider gives a home a /56, that is 256 /64 networks. +50 XP

Reinforcement

Review questions

Why did the move to IPv6 become necessary?

IPv4’s ≈4.3 billion addresses were no longer enough for the number of devices connected to the Internet; NAT is a temporary workaround. With 128 bits, IPv6 provides practically unlimited addresses.

How is an IPv6 address structured and written?

128 bits; 8 groups of 16 bits, each written as 4 hexadecimal digits, separated by colons.

State the rules for shortening an IPv6 address.

Leading zeros are dropped; the longest run of 2 or more consecutive zero groups (the leftmost if they are equal) is replaced once with “::”; letters are lowercase.

Why can “::” not be used twice?

It becomes unknown how many zero groups each “::” hides — the address cannot be restored unambiguously.

What are the main IPv6 address types and their prefixes?

Global unicast 2000::/3, link-local fe80::/10, ULA fc00::/7, multicast ff00::/8, loopback ::1, unspecified ::.

What does the /64 prefix mean?

The first 64 bits are the network (global prefix + subnet ID), the last 64 bits are the interface identifier. It is the standard for LAN segments.

How is EUI-64 built?

The 48-bit MAC is split in two, FFFE is inserted in the middle, and the 7th bit (U/L) of the first byte is flipped.

Give 4 main differences between IPv4 and IPv6.

Length (32/128 bits), notation (decimal/hexadecimal), broadcast (yes/no), autoconfiguration (DHCP / SLAAC), need for NAT.

Independent work

Independent-study topic in the course program: “The role of DHCP, ICMP, NAT and IPv6 technologies in the network” (6 hours). The part related to this class is IPv6 addressing.

  1. Shorten (or write out in full) every address in your variant by hand, determine its type, and write down its /64 network.
  2. For the MAC address, calculate the EUI-64 link-local address by hand (with all the steps).
  3. Check the results with your “IPv6 passport” program and attach a screenshot.
  4. Run ipconfig on your own computer and analyze your IPv6 addresses (if any): which is link-local, which is global, is there a temporary address?
Assessment criteria (individual assignment)
CriterionPoints
Shortening/expansion rules applied correctly2
Address types and /64 networks identified correctly1
EUI-64 steps shown in full1
Checked with the program; ipconfig analysis included1

Summary

128 bits8 groups × 16 bits, hexadecimal notation.
ShorteningLeading zeros are dropped; the longest zero chain becomes “::” once.
Equal chainsThe leftmost is shortened; a lone 0 stays.
Types2000::/3 global, fe80::/10 link-local, fc00::/7 ULA, ff00::/8 multicast, ::1 loopback.
/64Network prefix + a 64-bit interface identifier.
EUI-64MAC + FFFE, the 7th bit flips; modern operating systems prefer a random ID.
No broadcastMulticast takes its place.
ipaddresscompressed, exploded, ip_interface().network — for checking manual calculations.

Your lesson results

Your results are saved in this browser. Read all the sections and complete the exercises and assignments.

My personal notes