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.
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)
- 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.
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
| № | Rule | Example |
|---|---|---|
| 1 | Leading zeros in each group are dropped (at least one digit remains) | 0db8 → db8, 0042 → 42, 0000 → 0 |
| 2 | Two 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 chosen | 2001:0:0:1:0:0:0:1 → 2001:0:0:1::1 |
| 4 | If the lengths are equal, the first (leftmost) chain is shortened | 2001:db8:0:0:1:0:0:1 → 2001:db8::1:0:0:1 |
| 5 | A single lone zero group is not shortened with :: | 2001:db8:0:1:1:1:1:1 stays unchanged |
| 6 | Letters are written in lowercase | 2001:DB8::FF → 2001:db8::ff |
| Type | Prefix | Starts with | IPv4 equivalent |
|---|---|---|---|
| Global unicast | 2000::/3 | 2… or 3… | public address |
| Link-local | fe80::/10 | fe80:… | 169.254.x.x (APIPA) |
| Unique local (ULA) | fc00::/7 | fc… or fd… | 10.x, 172.16–31.x, 192.168.x |
| Multicast | ff00::/8 | ff… | 224.0.0.0/4 (class D) |
| Loopback | ::1/128 | ::1 | 127.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.
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
| Feature | IPv4 | IPv6 |
|---|---|---|
| Length | 32 bits | 128 bits |
| Entry | dotted decimal | hexadecimal with colons |
| Number of addresses | ≈ 4,3·109 | ≈ 3,4·1038 |
| Broadcast | yes | no (multicast) |
| Autoconfiguration | DHCP (or manual) | SLAAC (self-configured), DHCPv6 |
| Need for NAT | widely used | usually 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
- Drop the leading zeros
2001:db8:0:0:0:ff00:42:8329— at least one digit remains in every group. - Find the longest chain of zero groups
Groups 3, 4 and 5:
0:0:0— length 3. - Replace the chain with “::”
2001:db8::ff00:42:8329. - 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
- Count the visible groups
fe80, 21a, 2bff, fe3c, 4d5e — 5 of them. So “::” stands for 8 − 5 = 3 groups of
0000. - Pad every group to 4 digits
21a→021a. - 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.
- Split the MAC in the middle and insert fffe
00:1A:2B|FF:FE|3C:4D:5E→001A:2BFF:FE3C:4D5E. - Flip the 7th bit of the first byte (the U/L bit)
00=00000000→00000010=02. In Python:0x00 ^ 0x02. - Identifier
021a:2bff:fe3c:4d5e. - Link-local address
fe80::+ identifier →fe80::21a:2bff:fe3c:4d5e.
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
Shorten this address:
IPv6 on your computer
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
| Error | Why it is wrong | Correct answer |
|---|---|---|
2001:db8::1::2 | “::” twice — the number of zeros is ambiguous | only one “::” |
2001:db8:0:0:0:0:0:1 → 2001:db8:0::1 | the longest chain was not fully shortened | 2001:db8::1 |
2001:0db8 → 2001:db80 | dropping a trailing zero changes the value! | only leading zeros are dropped: db8 |
| Counting one group as 8 bits | Confusing it with an IPv4 octet | group = 4 hex = 16 bits |
| In EUI-64, inserting fffe but not flipping the 7th bit | the identifier is wrong | in the first byte, ^ 0x02 |
| “IPv6 has broadcast too” | IPv6 has no broadcast | multicast, 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.
- Shorten (or write out in full) every address in your variant by hand, determine its type, and write down its /64 network.
- For the MAC address, calculate the EUI-64 link-local address by hand (with all the steps).
- Check the results with your “IPv6 passport” program and attach a screenshot.
- Run
ipconfigon your own computer and analyze your IPv6 addresses (if any): which is link-local, which is global, is there a temporary address?
| Criterion | Points |
|---|---|
| Shortening/expansion rules applied correctly | 2 |
| Address types and /64 networks identified correctly | 1 |
| EUI-64 steps shown in full | 1 |
| Checked with the program; ipconfig analysis included | 1 |
Summary
Your lesson results
Your results are saved in this browser. Read all the sections and complete the exercises and assignments.