Skip to content
Tutorials Center
My learning

Topics

Lesson 23 of 79 ยท The Network Layer: IP

IPv6

Understand IPv6: 128-bit addresses and compression, address types, the simplified 40-byte header, SLAAC autoconfiguration, and dual stack, tunnels and NAT64.

IPv4 has about 4.3 billion addresses, and the world ran out of unassigned blocks years ago. NAT stretched the supply, but at a price: it breaks the original idea that any host can talk directly to any other. IPv6 is the permanent fix. It uses 128-bit addresses, which gives roughly 3.4 x 10^38 of them, and it cleans up the packet format at the same time.

IPv6 is not "IPv4 with longer addresses". The header is simpler, hosts can configure themselves without a server, broadcast is gone, and routers no longer fragment packets. This lesson covers how to read and write addresses, the kinds of address you will meet, the header, autoconfiguration, and how IPv4 and IPv6 live side by side during the long transition.

Writing IPv6 addresses

An IPv6 address is 128 bits, written as eight groups of four hexadecimal digits separated by colons:

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

Two rules shorten this:

  1. Drop leading zeros in each group: 0db8 becomes db8, 0000 becomes 0, 0042 becomes 42.
  2. Replace one run of all-zero groups with ::. It may be used only once, because otherwise the number of zero groups hidden by each :: would be ambiguous. If there are two runs, compress the longer one (the leftmost if they tie).

So the address above becomes 2001:db8::ff00:42:8329. The loopback address is ::1 and the "unspecified" address is ::.

An address plus a prefix length works as in CIDR: 2001:db8:1234::/48 means the first 48 bits are the network. Because a URL already uses a colon before the port, IPv6 literals go in square brackets: http://[2001:db8::1]:8080/.

The standard size for a LAN is a /64: the first 64 bits identify the subnet and the last 64 bits identify the interface. An ISP typically gives a home customer a /56 or /48, which holds 256 or 65,536 separate /64 subnets. Nobody counts hosts in IPv6; there is no shortage to ration.

Python IPv6 notation with the ipaddress module

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Address types

IPv6 has no broadcast address. Instead it uses three kinds of delivery:

  • Unicast: one sender to one interface.
  • Multicast: one sender to a group. It does the jobs that broadcast did in IPv4, such as "all nodes on this link" (ff02::1).
  • Anycast: one sender to the nearest of several interfaces that share an address. Root DNS servers and CDNs use this idea.

The prefix tells you what kind of address you have:

Prefix Type Notes
::1/128 Loopback Like 127.0.0.1.
::/128 Unspecified "No address yet", used as a source during startup.
fe80::/10 Link-local Valid on one link only, never routed. Every interface has one.
fc00::/7 Unique local (ULA) Private addresses, in practice fd00::/8. Not routed on the Internet.
2000::/3 Global unicast The public Internet.
ff00::/8 Multicast The scope is encoded in the address.
2001:db8::/32 Documentation Reserved for examples such as this lesson.
::ffff:0:0/96 IPv4-mapped An IPv4 address inside an IPv6 socket API, such as ::ffff:192.0.2.1.

Link-local addresses are a big part of how IPv6 works. A host needs no configuration to talk to its neighbors, and routers use their link-local address as the next hop in routing tables. You often see them written with a zone ID such as fe80::1%eth0, because the same fe80:: address can exist on several links and the system must know which one you mean.

Python Classify IPv6 addresses

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The IPv6 header

The base IPv6 header is exactly 40 bytes, always. Compared with IPv4 it dropped everything that was rarely needed or costly for routers.

flowchart TB
    subgraph H["IPv6 base header (40 bytes)"]
      A["Version (4) | Traffic class (8) | Flow label (20)"]
      B["Payload length (16) | Next header (8) | Hop limit (8)"]
      C["Source address (128)"]
      D["Destination address (128)"]
      A --> B --> C --> D
    end

Eight fields, no options, no checksum, no fragmentation fields.

What changed compared with IPv4:

  • No header checksum. The link layer (CRC) and the transport layer already check for errors, so routers no longer recompute anything at every hop. UDP over IPv6 therefore requires its checksum.
  • No fragmentation fields and no IHL. The header has a fixed size. A router never fragments a packet: it drops it and sends back an ICMPv6 "Packet Too Big" message, and the sender adapts using path MTU discovery. Only the source host may fragment, using an extension header. Every link must support an MTU of at least 1,280 bytes.
  • Hop limit replaces TTL. It works the same way but has the honest name.
  • Next header replaces the protocol field. It names either the transport protocol (6 TCP, 17 UDP, 58 ICMPv6) or an extension header such as routing, fragment or authentication. Headers are chained: each says what comes next.
  • Flow label (20 bits) lets a sender mark packets that belong to one flow so routers can keep them on one path. It is rarely used in practice.

The traffic class carries the same DSCP and ECN bits as IPv4's former "type of service" byte.

Python Build and parse a 40-byte IPv6 header

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Getting an address: SLAAC and DHCPv6

IPv6 hosts can configure themselves. With SLAAC (Stateless Address Autoconfiguration):

  1. The host builds a link-local address (fe80:: plus an interface identifier).
  2. It checks that nobody else uses it, through Duplicate Address Detection.
  3. It sends a Router Solicitation, or waits for a periodic Router Advertisement (RA). The RA from the router announces the subnet prefix (a /64), the default router and flags.
  4. The host appends its own 64-bit interface identifier to the prefix and has a global address. No server keeps a list of leases.

This all runs on NDP (Neighbor Discovery Protocol), which uses ICMPv6 messages and replaces ARP. A host asks "who has this address?" by sending a Neighbor Solicitation to a solicited-node multicast address, so only the few hosts whose address ends in the same 24 bits even wake up, instead of every machine on the segment.

The interface identifier used to be built from the MAC address by the modified EUI-64 method: split the 48-bit MAC in the middle, insert ff:fe, and flip the 7th bit of the first byte (the universal/local bit). Because that identifier never changes, it lets websites track a device across networks. Modern operating systems use random, temporary identifiers (privacy extensions) for outgoing connections instead.

When a network wants central control, DHCPv6 can hand out addresses and options such as DNS servers (compare DHCP for IPv4). The RA flags tell hosts which method to use.

Python SLAAC with the EUI-64 method

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Living with both: the transition

Nobody could switch the Internet off for a weekend, so IPv6 is deployed alongside IPv4 for years. The main techniques:

  • Dual stack. Hosts and routers run both protocols. An application resolves a name, receives both A and AAAA records (DNS) and prefers IPv6, falling back to IPv4 quickly if it does not work (the "Happy Eyeballs" algorithm). This is the most common and simplest approach.
  • Tunneling. IPv6 packets are wrapped inside IPv4 packets (protocol number 41) to cross an IPv4-only part of the network. 6in4 and 6to4 are examples; the tunnel endpoints add and remove the outer header.
  • Translation (NAT64 and DNS64). An IPv6-only network can reach IPv4-only servers. DNS64 invents an AAAA answer by placing the server's IPv4 address inside the well-known prefix 64:ff9b::/96, and a NAT64 gateway translates the packets in between. Many mobile networks work this way.
flowchart LR
    C["IPv6-only client<br/>2001:db8::5"] -->|"to 64:ff9b::c000:201"| G["NAT64 gateway"]
    G -->|"IPv4 packet to 192.0.2.1"| S["IPv4-only server<br/>192.0.2.1"]

The last 32 bits of a NAT64 address are the IPv4 address of the real server.

Python NAT64 address synthesis

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Quick check on a real machine: ping -6 or curl -6 forces IPv6, and curl -4 forces IPv4. If a site is slow in one and fast in the other, that points to a path or MTU problem. See essential network tools.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which is a valid shortened form of 2001:0db8:0000:0000:0000:0000:0000:0001?

    Leading zeros are dropped and one run of zero groups becomes ::. Using :: twice (option 2) is ambiguous, and the other options have too few groups.
  2. 2. Which address is valid only on the local link and is never routed?

    fe80::/10 is link-local. fd00::/8 addresses are private but can be routed inside an organization, and ::1 is the loopback address of the host itself.
  3. 3. What replaced IPv4's broadcast in IPv6?

    IPv6 has no broadcast. Multicast addresses reach all nodes or a specific group, and NDP uses solicited-node multicast instead of ARP broadcasts.
  4. 4. Why does the IPv6 base header not contain a checksum?

    Removing it saves work in every router. Errors are caught by the CRC on each link and by the TCP/UDP checksum end to end.
  5. 5. A router receives an IPv6 packet larger than the next link's MTU. What happens?

    Routers never fragment IPv6 packets. The sender learns the path MTU from the error message and sizes its packets accordingly.

Summary

  • IPv6 addresses are 128 bits, written as eight hex groups; drop leading zeros and replace one run of zero groups with ::.
  • Address kinds: loopback ::1, link-local fe80::/10, unique local fc00::/7, global 2000::/3, multicast ff00::/8. There is no broadcast.
  • The base header is fixed at 40 bytes with no checksum and no fragmentation fields; extension headers are chained through "next header". The minimum MTU is 1,280.
  • Hosts configure themselves with SLAAC from Router Advertisements; NDP over ICMPv6 replaces ARP. DHCPv6 is available for central control.
  • Transition uses dual stack, tunnels and NAT64/DNS64.

Next, see why IPv4 survived so long: NAT and private networks.