100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Python

IPv4 vs IPv6

Compare the two IP versions across address size, notation, and how IPv6 changes the need for NAT.

Network LayerIntermediate10 min readJul 8, 2026
Analogies

Introduction

IPv4 and IPv6 are the two versions of the Internet Protocol used to address and route traffic at the network layer. IPv4 uses 32-bit addresses, giving roughly 4.3 billion possible addresses, a number that has proven insufficient for the modern internet. IPv6 was designed to solve this scarcity by using 128-bit addresses, providing an astronomically larger address space.

🏏

Cricket analogy: Just as a small stadium with 4.3 billion imaginary seat numbers eventually runs out of unique seats for a growing fan base, IPv4's 32-bit space ran short, while IPv6's 128-bit space is like an effectively limitless stadium.

Explanation

IPv4 addresses are written in dotted-decimal notation, four octets separated by dots, e.g., 192.168.1.5, offering 2^32 (about 4,294,967,296) unique addresses. IPv6 addresses are written in colon-hexadecimal notation, eight groups of four hex digits separated by colons, e.g., 2001:0db8:0000:0000:0000:ff00:0042:8329, offering 2^128 addresses, an effectively inexhaustible number. To make IPv6 addresses easier to write, leading zeros in each group can be dropped and one contiguous run of all-zero groups can be compressed once per address using a double colon (::); the example above compresses to 2001:db8::ff00:42:8329. Because IPv6 provides enough public addresses for every device to have its own globally unique address, Network Address Translation (NAT), which IPv4 networks rely on heavily to share a small pool of public addresses among many private hosts, is far less necessary in IPv6 — most IPv6 deployments favor direct end-to-end addressing (though firewalls are still used for security).

🏏

Cricket analogy: An IPv4 address like 192.168.1.5 is as compact as a scorecard's four-digit over-and-run tally, while an IPv6 address like 2001:db8::ff00:42:8329 is like a detailed player database ID with room for every player ever registered.

Example

python
# Comparing address space size
ipv4_bits = 32
ipv6_bits = 128

ipv4_addresses = 2 ** ipv4_bits
ipv6_addresses = 2 ** ipv6_bits

print(f"IPv4: {ipv4_bits}-bit -> {ipv4_addresses:,} addresses")
print(f"IPv6: {ipv6_bits}-bit -> {ipv6_addresses:,} addresses")

# IPv6 compression example
full = "2001:0db8:0000:0000:0000:ff00:0042:8329"
compressed = "2001:db8::ff00:42:8329"
print(full, "->", compressed)

Analysis

The scale difference matters practically: IPv4's ~4.3 billion addresses were exhausted at the regional registry level years ago, forcing widespread use of NAT and private address ranges (like 192.168.0.0/16) just to keep the internet functioning as devices multiplied. IPv6's 2^128 address space (about 340 undecillion addresses) is large enough that every device — phones, sensors, appliances — can hold a unique, globally routable address without sharing, which restores true end-to-end connectivity and simplifies peer-to-peer applications. The double-colon compression can only be used once in an address (to avoid ambiguity about how many zero groups it represents), and leading zeros within each remaining group are still droppable independently.

🏏

Cricket analogy: When domestic leagues ran out of unique player registration numbers, boards had to share numbers via lookups, like IPv4's NAT sharing scarce addresses, while IPv6 gives every registered cricketer worldwide their own unique ID.

Key Takeaways

  • IPv4 is 32-bit (~4.3 billion addresses); IPv6 is 128-bit (a vastly larger address space).
  • IPv4 uses dotted-decimal notation; IPv6 uses colon-hexadecimal notation with :: for zero-run compression.
  • The :: compression can be used only once per IPv6 address.
  • IPv6's abundant address space reduces the need for NAT compared to IPv4.

Practice what you learned

Was this page helpful?

Topics covered

#Python#ComputerNetworksStudyNotes#ComputerNetworks#IPv4VsIPv6#IPv4#IPv6#Explanation#Example#StudyNotes#SkillVeris