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
220.127.116.11--------------------------------------------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
Where would I first interact with these as a beginning coder?
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).
What does the IPv stand for in IPv4 and IPv6?
Internet Protocol Version.
What happened to IPv1, IPv2, IPv3 and IPv5?
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.
Zeros and ones
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:
Each of these sections is made up of 8 bits.
What’s a bit?
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.)
What is binary?
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
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:
The above IPv4 address (
18.104.22.168) could be written in binary as follows:
How does 01101000 represent the number 104?
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.
The anatomy of an IPv6 address
IPv6 addresses look a lot different. For example:
IPv6 addresses use the hexadecimal numeral system.
What are hexadecimal numbers?
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.)
But the IPv6 address listed above looks like it only has 4 (or 5?) sections. What’s going on?
This is something that has confused me for awhile. So to provide some context, another way to write this IPv6 address would be:
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.
How would you write an IPv6 address in bits?
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
How many possible IPv4 and IPv6 addresses are there?
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 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