Kestrel Exams kestrel logo KESTREL EXAMSPRACTICE TO PASS
Networking13 min read

IPv6 and Tunneling: The 40-Byte Header, Address Notation and Moving Off IPv4

IPv4 ran out of addresses, so the Internet is moving to IPv6: 128-bit addresses and a simpler, fixed-size header. The move cannot happen on one day, so for years IPv6 packets have to cross parts of the network that only speak IPv4. That is what tunneling is for.

Practice this topic in the free app →All Networking guides

Chapter 4 · IPv6
Built from

Kurose and Ross, Computer Networking: A Top-Down Approach, section 4.3 (IPv6 and the transition from IPv4). Cross-checked against RFC 8200 (Internet Protocol, Version 6 (IPv6) Specification), RFC 4291 (IP Version 6 Addressing Architecture), RFC 5952 (A Recommendation for IPv6 Address Text Representation) and RFC 4213 (Basic Transition Mechanisms for IPv6 Hosts and Routers). Every size, count and shortened address was recomputed in code before publishing.

How to use it

Learn the eight header fields as a list, then learn the three things IPv6 took away from IPv4. Practice address shortening until you can do it without thinking: it is the easiest marks on the topic. Finish by drawing one tunnel, with the outer IPv4 header wrapped around the IPv6 datagram.

The picture: new phone numbers and a letter inside a letter#

Imagine a country whose phone numbers have only seven digits. Every number gets taken, so the country moves to much longer numbers. But nobody can replace every phone overnight, so for years some phones understand the new numbers and some only the old ones.

That is the Internet today. The old system is IPv4, with 32-bit addresses. The new one is IPv6, with 128-bit addresses.

Now picture sending a letter through a town whose post office only reads old-style addresses. You put it inside a second envelope with an old-style address: the office at the far side of town. The town carries the outer envelope without opening it, and at the far side someone unwraps your letter and sends it on. That second envelope is a tunnel.

Vocabulary, before anything uses it#

TermWhat it means
IPv4Internet Protocol version 4. The original network-layer protocol, with 32-bit addresses and a header of 20 bytes or more.
IPv6Internet Protocol version 6. Its replacement, with 128-bit addresses and a fixed 40-byte header.
DatagramA network-layer packet: a header followed by its payload, the data it carries (usually a TCP or UDP segment).
Hexadecimal (hex)Base 16: the digits 0 to 9, then a to f for ten to fifteen. One hex digit stands for exactly 4 bits.
Extension headerAn optional extra IPv6 header between the main header and the payload. It replaces IPv4’s options.
MTUMaximum transmission unit: the largest datagram a link can carry in one frame. 1,500 bytes on Ethernet.
Dual stackA host or router that runs both IPv4 and IPv6, and can send and receive either one.
TunnelingCarrying a whole IPv6 datagram as the payload of an IPv4 datagram, so it can cross routers that only understand IPv4.
Encapsulate / decapsulateTo wrap a packet inside another header / to unwrap it again.

Why IPv6 exists#

The main reason: IPv4 ran out of addresses. A 32-bit address allows 232 = 4,294,967,296 addresses, about 4.3 billion. That is fewer than one per person alive, and the regional registries that hand out IPv4 blocks have run out of free ones, or nearly so. Network address translation (NAT) bought time by letting a whole home share one public address, but it breaks direct reachability. IPv6 fixes the shortage at the root.

A 128-bit address allows 2128 addresses. That is about 3.4 × 1038, or 340 followed by 36 more digits. It is 296 (about 7.9 × 1028) times as many as IPv4. Running out is not a realistic worry.

The designers also made the header faster to process. Every field a router no longer has to check or change saves work on billions of datagrams. So IPv6 is not just “IPv4 with longer addresses”.

The fixed 40-byte header, field by field#

Every IPv6 header is exactly 40 bytes, so it needs no “header length” field. Its eight fields, in order:

FieldSizeWhat it does
Version4 bitsAlways 6.
Traffic class8 bitsPriority marking, like IPv4’s type of service (the same 6-bit Differentiated Services Code Point, DSCP, and 2-bit Explicit Congestion Notification, ECN).
Flow label20 bitsTags datagrams of one flow (one stream, such as a video call) so routers can treat them alike. 220 = 1,048,576 labels.
Payload length16 bitsHow many bytes follow the 40-byte header. Up to 65,535. The header itself is not counted.
Next header8 bitsWhat follows: TCP (6), UDP (17) or an extension header. Same numbers as IPv4’s protocol field.
Hop limit8 bitsIPv4’s TTL (time to live), renamed. Each router subtracts 1; at 0 the datagram is dropped.
Source address128 bitsThe sender’s IPv6 address.
Destination address128 bitsThe receiver’s IPv6 address.

Check the size: 4 + 8 + 20 + 16 + 8 + 8 + 128 + 128 = 320 bits, and 320 ÷ 8 = 40 bytes. The two addresses take 32 of those 40 bytes.

What IPv6 took away from IPv4

  • No fragmentation at routers. A router facing a datagram too big for the next link drops it. It sends an ICMPv6 (Internet Control Message Protocol for IPv6) “Packet Too Big” message back, so the sender sends smaller ones. Only the source may fragment, using an extension header. (Every IPv6 link must carry at least 1,280 bytes.)
  • No header checksum. The link layer and TCP or UDP already check for errors, and IPv4 routers had to recompute the checksum at every hop because the TTL changes.
  • No options in the main header. They moved into extension headers, chained by the next header field.
Worked example

A 1,000-byte TCP segment travels over IPv6 with no extension headers. The payload length field says 1,000; the datagram is 40 + 1,000 = 1,040 bytes. Over IPv4 it would be 1,020 bytes. With a minimum TCP header, header overhead is 20 + 20 = 40 bytes over IPv4 but 40 + 20 = 60 bytes over IPv6.

Do not confuse these
IPv6 payload length does not include the header. IPv4 total length does. An IPv4 datagram with total length 1,040 carries 1,020 bytes after a 20-byte header. An IPv6 datagram with payload length 1,040 is really 1,080 bytes long.

Writing an IPv6 address#

IPv6 writes an address as eight groups of four hex digits, separated by colons. Each group is 4 × 4 = 16 bits, and 8 × 16 = 128. The full form looks like this:

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

(The block 2001:db8::/32 is reserved for documentation, so it never clashes with a real network.) Two rules shorten it, and RFC 5952 fixes the standard form.

  1. Drop leading zeros in each group. 0db8 becomes db8, 0042 becomes 42, and 0000 becomes 0. You never drop trailing zeros: ff00 stays ff00.
  2. Replace one run of all-zero groups with a double colon ::. You may do this only once in an address. Otherwise nobody could tell how many zero groups each :: stood for.
  • Write hex letters in lowercase: 2001:DB8::1 is written 2001:db8::1.
  • Never use :: for a single zero group.

Applying both rules:

2001:db8::ff00:42:8329

Full formShortest standard formWhat happened
fe80:0000:0000:0000:0202:b3ff:fe1e:8329fe80::202:b3ff:fe1e:8329Three zero groups became ::; 0202 became 202.
2001:0db8:00a0:0000:0000:0000:0000:0bad2001:db8:a0::badFour zero groups became ::. 00a0 became a0, not a.
2001:0db8:0000:0000:0001:0000:0000:00012001:db8::1:0:0:1Two runs of two zero groups. Only the first one gets ::; the second is written 0:0.
0000:0000:0000:0000:0000:0000:0000:0001::1The loopback address, IPv6’s version of 127.0.0.1.

To expand an address, count the visible groups: :: fills in enough zero groups to make eight. Then pad each group to four digits.

Worked example

Expand 2001:db8:5::c1. Four groups are visible: 2001, db8, 5 and c1. So :: stands for 8 − 4 = 4 groups of zeros. Padding every group to four digits gives 2001:0db8:0005:0000:0000:0000:0000:00c1.

Prefixes work as in IPv4’s CIDR (classless interdomain routing): 2001:db8:5::/48 means the first 48 bits are the network part. A single LAN (local area network) normally gets a /64, leaving 264 (about 1.8 × 1019) addresses for its hosts.

Moving off IPv4: dual stack and tunneling#

Nobody can switch every router on the Internet to IPv6 on the same day, so the two protocols must live side by side. Two techniques make that work.

Dual stack

A dual-stack device runs IPv4 and IPv6 together, with an address of each kind. It talks IPv6 to IPv6 neighbors and IPv4 to IPv4 neighbors. Most modern phones, laptops and servers are dual stack. On its own, dual stack cannot get an IPv6 datagram across an IPv4-only router. (Older textbook editions describe converting the datagram to IPv4 at that point, which loses IPv6-only fields such as the flow label. If your textbook does, know that version for the exam.)

Tunneling

Tunneling avoids that loss. At the start of an IPv4-only stretch, a dual-stack router encapsulates the whole IPv6 datagram as the payload of a new IPv4 datagram. It sets the IPv4 protocol field to 41 (“IPv6 inside”) and addresses it to the dual-stack router at the far end. The IPv4 routers forward it like any other datagram. The exit router sees protocol 41, decapsulates the IPv6 datagram and forwards it as IPv6.

Device on the pathSpeaksWhat it does to the datagram
Host P (sender)IPv6Sends an IPv6 datagram to Q, hop limit 64.
Router R1 (tunnel entrance)Dual stackHop limit 64 → 63, then wraps it in an IPv4 header: protocol 41, source R1, destination R4.
Router R2IPv4 onlySees an ordinary IPv4 datagram; lowers the outer TTL by 1.
Router R3IPv4 onlyThe same as R2.
Router R4 (tunnel exit)Dual stackRemoves the IPv4 header; hop limit 63 → 62.
Host Q (receiver)IPv6Receives the original datagram, hop limit 62.

To IPv6, the whole tunnel is one hop (RFC 4213). R2 and R3 change only the outer TTL, so the hop limit drops by just 2: at R1 and at R4.

Worked example

An IPv6 datagram with payload length 1,000 is 1,040 bytes long. R1 adds a 20-byte IPv4 header: protocol 41, total length 20 + 1,040 = 1,060 bytes. On a 1,500-byte MTU link, the biggest IPv6 datagram that fits through this tunnel is 1,500 − 20 = 1,480 bytes.

Do not confuse these
Dual stack chooses; tunneling wraps. A dual-stack device picks IPv4 or IPv6 for each conversation. A tunnel keeps the IPv6 datagram whole inside an IPv4 one.
One sentence to carry into the exam

IPv6 gives every interface a 128-bit address and a fixed 40-byte header with no checksum, no router fragmentation and no options; until every router speaks it, dual-stack routers carry IPv6 datagrams across IPv4-only stretches by tunneling them inside IPv4 datagrams marked protocol 41.

Practice#

Write every address in groups of four hex digits before you start counting. Most mistakes come from miscounting groups.

  1. Shorten 2001:0db8:0000:0042:0000:0000:0000:0007 to its standard shortest form.
  2. Expand 2001:db8:a::7 to its full 32-hex-digit form.
  3. Which of these are valid IPv6 addresses? (a) 2001:db8::1::2 (b) 2001:db8:0:0:0:0:0:g1 (c) 2001:db8:12345::1 (d) 2001:db8::cafe:0:0
  4. Add up the IPv6 header fields to show that the header is 40 bytes. How many of those bytes are addresses?
  5. A host sends a 1,200-byte UDP segment over IPv6 with no extension headers. The datagram then enters a tunnel. Give the IPv6 payload length, the IPv4 total length, and the value of the IPv4 protocol field.
  6. An IPv6 datagram of 1,600 bytes reaches a router whose next link has a 1,500-byte MTU. What does the router do? What would an IPv4 router have done instead (if the “don’t fragment” flag were not set)?
  7. Give two reasons IPv6 dropped the header checksum.
  8. Host P sends an IPv6 datagram with hop limit 128. It passes dual-stack router R1, then three IPv4-only routers, then dual-stack router R5, then IPv6 router R6, then reaches host Q. R1 to R5 is a tunnel. What hop limit does Q see?

Solutions#

Best study method

Find the first line where your working split from the solution, and redo the problem from that line. Do not just read the answer and nod.

  1. 2001:db8:0:42::7. Drop leading zeros: 2001:db8:0:42:0:0:0:7. The longest zero run (three groups before 7) becomes ::; the lone 0 after db8 stays.
  2. 2001:0db8:000a:0000:0000:0000:0000:0007. Four groups are visible, so :: stands for 8 − 4 = 4 zero groups; then pad each group.
  3. Only (d). (a) uses :: twice, which is ambiguous. (b) contains g, not a hex digit. (c) has a five-digit group; a group is at most four. (d) is valid and already standard: its three-group zero run beats the two at the end.
  4. 4 + 8 + 20 + 16 + 8 + 8 + 128 + 128 = 320 bits = 40 bytes; 32 bytes are addresses. That leaves 8 bytes for the other six fields.
  5. Payload length 1,200; IPv4 total length 1,260; protocol 41. The IPv6 datagram is 40 + 1,200 = 1,240 bytes, and the tunnel adds 20.
  6. It drops it and sends ICMPv6 Packet Too Big back to the sender, which must send smaller datagrams. An IPv4 router would have fragmented it.
  7. Other layers already detect errors, and routers save work. In IPv4 the TTL changes at each router, so the checksum had to be recomputed at every hop.
  8. 125. Only R1 (128 → 127), R5 (→ 126) and R6 (→ 125) forward it as IPv6. The IPv4-only routers lower only the outer TTL.

Test-readiness checklist#

  • ☐  I can explain why IPv6 was needed, with the sizes of the IPv4 and IPv6 address spaces.
  • ☐  I can list the eight fields of the IPv6 header and their sizes, and show they add up to 40 bytes.
  • ☐  I can name the three things IPv6 removed from the IPv4 header and say why.
  • ☐  I can shorten an IPv6 address correctly, including when there are two zero runs.
  • ☐  I can expand a shortened IPv6 address to all 32 hex digits.
  • ☐  I can explain the difference between dual stack and tunneling.
  • ☐  I can trace an IPv6 datagram through a tunnel, giving the protocol number, the lengths and the hop limit.
One last rule

When you count IPv6 sizes, ask which length you are looking at. Payload length leaves out the 40-byte header. Every IPv4 length, including a tunnel’s outer header, counts its own header in.

Frequently asked questions#

Why was IPv6 created?

IPv4 has 32-bit addresses, about 4.3 billion in total, and the free pools ran out. IPv6 uses 128-bit addresses, about 3.4 times 10 to the 38th, and also simplifies the header so routers can process datagrams faster.

What did IPv6 remove from IPv4?

Three things. Routers no longer fragment: they drop a datagram that is too big and send back an ICMPv6 Packet Too Big message. The header checksum is gone. Options left the main header and moved to extension headers.

How do you shorten an IPv6 address?

Drop the leading zeros in each 16-bit group, then replace one run of consecutive all-zero groups with a double colon. The double colon may appear only once. The standard form uses it on the longest run, or the first one if two runs tie.

What is IPv6 tunneling?

A dual-stack router puts a whole IPv6 datagram inside an IPv4 datagram with protocol number 41. The IPv4-only routers carry it to another dual-stack router, which removes the IPv4 header and forwards the original IPv6 datagram.

Suggest a change

Something here not clear? A topic you wish we covered? Tell us. We read every message, and a request is the fastest way to get a guide written.

Test yourself on this topic

The free networking practice app has 10 questions on this guide and 500 across the whole course, each with an explanation for every answer. Offline, no ads, no account.

Practise this topic →