The Anatomy of IPv4 and IPv6 Addresses

A tale of decimals, hexadecimals, zero suppression and compression

Joe Cardillo
Apr 28, 2019 · 6 min read
Image for post
Image for post
Photo of drill bits by Matt Artz on Unsplash — not a digital bit, but I digress.

In the Spring of 2018 I attended a three month Web Development Intensive course. I learned a lot, though in many ways it didn’t prepare me for entering the world of Linux, in which I now spend my days as a Customer Support Specialist at a cloud hosting company.

The on the job experience has been great, though I find it helpful to step back occasionally and dig into things that confuse me. One of those things is the difference between IPv4 and IPv6 addresses.

Where did they come from? What happened to IPv1, IPv2, IPv3 and IPv5? Why are there letters in IPv6 addresses? Why are they different lengths from one another? On and on the questions go.

This article is intended to be a beginner’s guide to the anatomy of IPv4 and IPv6 addresses.

I’ll try to break things down in byte size pieces. (Pun intended.) But first:

dig +short medium.com
104.16.120.127
104.16.122.127
104.16.123.127
104.16.121.127
104.16.124.127
--------------------------------------------dig -tAAAA medium.com | grep medium
; <<>> DiG 9.10.6 <<>> -tAAAA medium.com
;medium.com. IN AAAA
medium.com. 255 IN AAAA 2606:4700::6810:787f
medium.com. 255 IN AAAA 2606:4700::6810:7c7f
medium.com. 255 IN AAAA 2606:4700::6810:7a7f
medium.com. 255 IN AAAA 2606:4700::6810:7b7f
medium.com. 255 IN AAAA 2606:4700::6810:797f

You made your first web application. Now what? You’ll want to host it somewhere so it can be available for others to see! (Maybe even your prospective employers.) You’ll likely purchase your own domain name to give it a little extra splash. Depending on where you purchased your domain from, you’ll need to point your registrar to your newly purchased web server’s IPv4 address (A record), and your Cloud hosting provider’s nameservers (NS records).

Internet Protocol Version.

In a time (1977) when the Internet was referred to as the “Internetwork” ❤, a discussion began regarding Internet Protocol:

We are screwing up in our design of internet protocols by violating the principle of layering. Specifically we are trying to use TCP to do two things: serve as a host level end to end protocol, and to serve as an internet packaging and routing protocol. These two things should be provided in a layered and modular way. I suggest that a new distinct internetwork protocol is needed, and that TCP be used strictly as a host level end to end protocol.Source: https://www.rfc-editor.org/ien/ien2.txt

In other words, TCP — or Transmission Control Protocol — wasn’t cutting the cake, and something new was needed. Something that made the distinction between network-to-network (or “internetwork”) vs. host level protocols.

The reason we don’t hear about IPv1, IPv2 and IPv3 is because IPv4 was the first stable version of Internet Protocol. It transmitted datagrams with grace and poise, not to mention security and efficiency.

As for IPv5, it was an experimental real-time streaming protocol. But due to the increase in IPv4 bandwidth over time, IPv5 became unnecessary.

You’ve probably heard it said that everything in a computer — all the videos you stream on YouTube, every key, every ‘like’ you click — ultimately boils down to zeros and ones. The same thing could be said for IP addresses.

An IPv4 address has four sections, separated by dots:

104.16.120.127

Each of these sections is made up of 8 bits.

A bit is a zero or one. The building block of computer language. So the numbers you see in the IPv4 address above (for example: 104), could be written in binary.

(For some fun facts regarding binary and how bits flow through computer chips, check out Making Sense of Zeros and Ones.)

Binary means communicating in zeros and ones (or bits). Binary is a “base-2” numeral system. This means it uses two digits: 0 or 1. A bit is either off or on, 0 or 1. (For context, decimal is a base-10 numeral system, and hexadecimal… well, we’ll get to that.)

IPv4 addresses range from 0.0.0.0 to 255.255.255.255.

Why?

As mentioned earlier, each section is made up of 8 bits. Or eight zeros and ones. Eight bits is equal to 1 byte, or could be referred to as an octet.

For example, this is an 8-bit number:

01101000

The above IPv4 address (104.16.120.127) could be written in binary as follows:

01101000.00010000.01111000.01111111

Each bit is weighted, from right to left, starting at 1 and increasing by a factor of 2. For example:

Bits:     0   1   1   0   1   0   0   0
Weight: 128 64 32 16 8 4 2 1
// To get 104, you'd only add up the weights that were switched "on", or that had the number 1 in their place:01101000
64 + 32 + 8 = 104

So when you hear someone say an IPv4 address is 32 bits in length, just think: 8 bits * 4 sections = 32 bits.

IPv6 addresses look a lot different. For example:

2606:4700::6810:787f

IPv6 addresses use the hexadecimal numeral system.

The hexadecimal numeral system is base-16. The doesn’t mean it goes 0-16. Instead, it goes 0–9, then A-F (A: 10, B: 11, and so on).

As mentioned earlier, an IPv4 address contains four, 8-bit sections. (Making it 32 bits in length.) An IPv6 address, however, contains eight, 16-bit sections. (For a grand total of 128 bits.)

This is something that has confused me for awhile. So to provide some context, another way to write this IPv6 address would be:

2606:4700:0000:0000:6810:787f

The reason you don’t include those additional zeros is because IPv6 addresses use something called zero compression (and zero suppression).

So if one (or more) of those sections contained all zeros, you could replace them with a colon. This is called zero compression. (Even if there were multiple sections of zeros — such as 0000:0000:0000:0000 — you’d still only use a double colon to represent all of the compressed zeros.

If one of those sections started with a zero — like 087f rather than 787f — you would remove the zero from the beginning, leaving you with 87f. This is called zero suppression.

As previously mentioned, there are eight, 16-bit sections in an IPv6 address. Each 16-bit section is made up of four, 4-bit sections.

Let’s break this down by taking the first 4-bit section of the address above:

// The complete address:2606:4700:0000:0000:6810:787f// The first section:2606// While IPv6 addresses are written using hexadecimal, each hexadecimal number is made up of 4 bits.// In a 4-bit section, the number 2 would be written like this:0010Bits:   0   0   1   0
Weight: 8 4 2 1
// Therefore, the number 2606 in a 4-bit system would look like:0010.0110.0000.0110

As you’ve probably heard, one of the reasons for moving to IPv6 is due to the near exhaustion of IPv4 addresses.

The total number of IPv4 addresses is 2³²:

4,294,967,296. (Just over four billion.)

For IPv6, it would be 2¹²⁸:

340,282,366,920,938,463,463,374,607,431,768,211,456.

(340 undecillion? Beuller?)

This is only a brief foray into the deep world of Internet Protocol. For further nerd reading:

The 1981 Internet Protocol written for DARPA (Defense Advanced Research Projects Agency):https://tools.ietf.org/html/rfc791The Draft Internetwork Protocol Specification Protocol - Version 2 (IPv2):https://www.rfc-editor.org/ien/ien28.pdf

Coding in Simple English

Coding. Simply.

Sign up for Coding in Simple English

By Coding in Simple English

Monthly Updates from Coding in Simple English Take a look

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Joe Cardillo

Written by

Pianist and composer. Writing about the creative process, music, books and technology. @vontmer

Coding in Simple English

Coding. Simply.

Joe Cardillo

Written by

Pianist and composer. Writing about the creative process, music, books and technology. @vontmer

Coding in Simple English

Coding. Simply.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store