Network Bytes · Episode 27 · CCNA 1.8
How to shorten an IPv6 address
A full IPv6 address is 39 characters long. Two rules, dropping leading zeros and swapping one run of zero groups for a double colon, turn 2001:0db8:0000:0000:0000:0000:0000:0010 into 2001:db8::10.
The full address
An IPv6 address is 128 bits, written as eight groups of four hexadecimal digits separated by colons. Each group (sometimes called a hextet) holds 16 bits. Written out in full, an address looks like this:
2001:0db8:0000:0000:0000:0000:0000:0010
That's 39 characters, and a lot of them are zeros. Nobody wants to type that, so the standards allow two shortcuts.
Rule 1: drop the leading zeros
In each group, you can leave out the zeros at the front. The value doesn't change, the same way 007 is just 7.
0db8becomesdb80000becomes0(a group always keeps at least one digit)0010becomes10
Only leading zeros go. Trailing zeros stay: 0010 is 10, never 1. After rule 1, our address is 2001:db8:0:0:0:0:0:10.
Rule 2: one run of zero groups becomes ::
Next, find a run of consecutive all-zero groups and replace the whole run with a double colon (::). Our address has five zero groups in a row, so they vanish in one move:
2001:db8:0:0:0:0:0:10 becomes 2001:db8::10
That's 12 characters instead of 39. To expand it again, count the groups you can see (three here) and fill the :: with enough zero groups to make eight (five).
Only one double colon
You can use :: once per address. With two, there's no way to tell how many zero groups each one stands for. 2001::1::10 could mean 2001:0:1:0:0:0:0:10 or 2001:0:0:0:0:1:0:10, so it isn't a valid address.
When an address has more than one run of zeros, RFC 5952 says to compress the longest run, and if two runs tie, the first one. Write the hex digits in lowercase, and don't use :: for a single zero group.
Try it yourself
On a computer with IPv6, look at your own addresses:
- Windows: run
ipconfigand look for "IPv6 Address" or "Link-local IPv6 Address". - Mac or Linux: run
ifconfigorip -6 addr.
Most will start with fe80::, a link-local address that's already been shortened with ::. Try expanding one back to eight full groups.
Good to know
- Only leading zeros can be dropped; trailing zeros stay (
0010→10, never1). - RFC 5952 recommends lowercase hex and compressing the longest run of zero groups (the first one if two runs tie), and not using
::for a single zero group. 2001:0db8:0000:0000:0000:0000:0000:0010(39 characters) →2001:db8::10(12 characters).
For CCNA learners
This lines up with CCNA 200-301 exam topic 1.8, configure and verify IPv6 addressing and prefix: be ready to shorten a full IPv6 address, expand a shortened one back to eight groups, and spot an invalid address with two ::.
Answer to the comment question
2001:db8:1::1 hides four all-zero groups. An IPv6 address always has eight groups, and four are written out (2001, db8, 1 and 1), so the :: stands for the other four. In full it's 2001:0db8:0001:0000:0000:0000:0000:0001.
Test your knowledge
Quick quiz: How to shorten an IPv6 address
4 multiple-choice questions. Pick one answer for each, then check how you did.
Sources
- IETF, "RFC 5952, A Recommendation for IPv6 Address Text Representation": suppress leading zeros, use :: for the longest run of zero groups only once, lowercase hex
- IETF, "RFC 4291, IP Version 6 Addressing Architecture": section 2.2, text forms of IPv6 addresses; :: may appear only once
- IBM Documentation, "Textual representation of IPv6 addresses": dropping leading zeros and using the double colon
- Cisco, CCNA 200-301 v1.1 exam topics: 1.8 configure and verify IPv6 addressing and prefix
Video transcript
How do you squeeze a 39-character IPv6 address down to 12?
Here's a full IPv6 address. Eight groups of four hex digits, and a lot of zeros. Way too long to type.
Rule one: drop the leading zeros in each group. 0db8 becomes db8. Four zeros become just one zero. 0010 becomes 10.
Rule two: swap one run of all-zero groups for a double colon. Five zero groups vanish at once, in one move.
You get 2001:db8::10. Twelve characters. Just one double colon per address, or nobody could tell how many zeros went where.
Try this one: 2001:db8:1::1. How many all-zero groups is that double colon hiding? Comment your answer below!
That's your byte.
More from Network Bytes
- EP22Subnetting trick: the magic number
- EP23Network, broadcast and usable hosts
- EP24Default gateway
- EP25IPv6 in 60 seconds