IPv4 vs IPv6

RoadmapsCore CS

Scenario

We ran out of standard phone numbers, so we had to invent area codes. The internet faced the exact same problem: IPv4 only had 4.3 billion addresses, which wasn't enough for a world where every person owns a phone, laptop, and smart fridge.

Overview

IPv4 and IPv6 are the two protocols that provide unique addresses for devices on the internet.

IPv4 addresses have run out. IPv6 was designed with a vastly larger address space to accommodate all future devices.

Where used: Networking, System Administration, IoT

Why learn this

Mental model

IPv4 is like a 4-digit license plate system that ran out of combinations. IPv6 is a new 32-character alphanumeric plate that has enough combinations to assign one to every grain of sand on Earth.

IPv4 addresses use 32 bits, limiting the internet to about 4.3 billion unique public addresses. We exhausted that limit years ago. IPv6 was designed as the successor, using 128 bits. It fundamentally changes the scale of the internet, completely eliminating the need for address-sharing hacks like NAT.

Explanation

IPv4 is the fourth version of the Internet Protocol and the foundational technology that built the modern internet. It uses a 32-bit address space, usually written in decimal form as four numbers separated by dots (e.g., 192.168.1.1). Because 2 to the 32nd power is roughly 4.3 billion, that is the absolute maximum number of unique public IPv4 addresses possible. When the protocol was designed in the 1980s, 4.3 billion seemed effectively infinite. Today, with billions of humans each owning multiple internet-connected devices, we have completely run out of IPv4 space.

To keep the internet functioning despite this shortage, engineers invented workarounds. The most famous is NAT (Network Address Translation), which allows an entire household or office full of devices to share a single public IPv4 address. While NAT saved the internet from immediate collapse, it added complexity, slowed down routing, and broke the original 'end-to-end' principle of the internet where every device could communicate directly with any other device.

IPv6 was developed to solve this address exhaustion permanently. It uses a massive 128-bit address space. To grasp the scale, 2 to the 128th power provides roughly 340 undecillion addresses (that's 340 followed by 36 zeros). With IPv6, every device on the planet—down to individual sensors in a factory or lightbulbs in a house—can have its own unique, globally routable public IP address. NAT is no longer needed.

Because IPv6 addresses are so long, they are written in hexadecimal format, separated by colons into eight groups of four characters (e.g., 2001:0db8:85a3:0000:0000:8a2e:0370:7334). To make them readable, leading zeros can be omitted, and consecutive groups of zeros can be replaced with a double colon (::) once per address.

Beyond just having more addresses, IPv6 brings technical improvements. Its packet header is much simpler, allowing routers to process packets faster because they no longer have to calculate checksums at every hop or worry about packet fragmentation in transit. It also has built-in support for IPsec (Internet Protocol Security), meaning encryption and authentication are baked into the protocol by default, rather than bolted on as an afterthought like in IPv4.

Key points

Common mistakes

Glossary

dual-stack
A network configuration where a device or router runs both the older IPv4 and the newer IPv6 systems at the same time to ensure compatibility.
NAT
A clever networking trick that allows an entire household or office of devices to share a single public IP address by hiding their internal private addresses.
IPv4
The classic, older format for internet addresses made up of four numbers separated by periods, which eventually ran out because there weren't enough combinations.

Recall questions

Questions & answers

Which of the following is a valid abbreviation for the IPv6 address `2001:0db8:0000:0000:0000:ff00:0042:8329`?

`2001:db8::ff00:42:8329`

Approach: First, drop leading zeros in each block: `2001:db8:0:0:0:ff00:42:8329`. Next, replace the longest contiguous sequence of zero blocks with a double colon `::`. This gives `2001:db8::ff00:42:8329`.

An interviewer asks: 'If IPv6 is so much better and we ran out of IPv4 addresses a decade ago, why isn't the entire internet exclusively on IPv6 today?'

IPv4 and IPv6 are not inherently interoperable. Devices only speaking IPv4 cannot talk directly to devices only speaking IPv6.

Approach: Explain that the transition requires upgrading hardware, software, and ISPs worldwide to support 'Dual Stack' (running both protocols simultaneously) or implementing complex translation mechanisms. NAT also successfully delayed the urgency of the IPv4 shortage.

Continue learning

Previous: IP Addressing & Classes

Return to Core CS Roadmap