IPv4 vs IPv6: Address Length, Header, Address Configuration, NAT and IPsec

IPv4 and IPv6 are both network-layer protocols for delivering packets to their destination. IPv4 addresses are 32 bits, giving only about 4.3 billion addresses, so it became common for many devices to share one global address using private addresses and NAT. IPv6 extends addresses to 128 bits, simplifies the header to a fixed 40 bytes and removes packet splitting (fragmentation) by routers along the path. The two are not compatible, however: an IPv4-only device and an IPv6-only device cannot talk to each other directly. The transition therefore combines dual stack (running both at once), tunneling (carrying packets of one inside packets of the other) and address translation such as NAT64.

AspectIPv4IPv6
Address length and count32 bits: 2 to the 32nd power (about 4.3 billion) addresses128 bits: 2 to the 128th power (about 3.4×10^38) addresses
NotationFour 8-bit decimal numbers separated by dots (e.g. 192.0.2.1)Eight 16-bit hexadecimal groups separated by colons; leading zeros in each group, and one run of zero groups as ::, can be omitted (e.g. 2001:db8::1)
HeaderVariable length, 20 to 60 bytes, with options and a header checksumFixed 40 bytes with no checksum; options are chained after it as extension headers; the TTL equivalent is the hop limit
FragmentationRouters along the path, not just the source, can split packets (unless the DF bit is set)Routers do not fragment; only the source splits packets, using an extension header; link MTU is at least 1280 bytes
Automatic address configurationAssigned by DHCP (or set manually)SLAAC, where the host builds its own address from router advertisement (RA) information, or DHCPv6; a link-local address is always created automatically
MAC address resolutionARP, which queries by broadcastICMPv6 Neighbor Discovery (NDP), which queries by multicast
NATTo make up for the address shortage, sharing one global address via private addresses and NAPT is commonDesigned so every device gets a global address and communicates end to end with the same address, since addresses are plentiful; NAT is generally not used
Destination typesUnicast, broadcast, multicastUnicast, multicast, anycast; there is no broadcast, and multicast takes its place
IPsecOptional, added when neededEarly requirements made implementation mandatory; current requirements (RFC 8504) make it recommended. Whether it is actually used depends on configuration for both

Figures are typical orders of magnitude and vary by process generation and product.

When to use which

IPv4
Still used on many networks and services, so nearly every device will need to support it for the foreseeable future. Because addresses are scarce, it is used together with private addresses and NAT.
IPv6
When you want to give many devices global addresses without going through NAT, or when building a new network. In practice it is usually deployed as dual stack alongside IPv4.

FAQ

Can an IPv6 device talk directly to an IPv4 device?

No. The header format and the address length differ, and the two are not compatible. Many networks use dual stack, giving devices both IPv4 and IPv6 addresses and using whichever suits the other side. For an IPv6-only device to reach an IPv4-only server, translation mechanisms such as NAT64 and DNS64 are used. To carry IPv6 packets across an IPv4 network, tunneling wraps them inside IPv4 packets.

Is NAT not used with IPv6?

It can be used, but it is generally not needed. The main reason NAT spread with IPv4 was the shortage of addresses, while IPv6 can give every device plenty of global addresses. Restricting connections that start from outside is the job of a firewall, not of NAT. NAT does not encrypt traffic, and on its own it does not protect against attacks from outside.

How does DNS change with IPv6?

A records map a name to an IPv4 address, and AAAA records map it to an IPv6 address. Dual-stack devices usually query both and use IPv6 if they can connect over it, falling back to IPv4 otherwise.

Why are IPv6 addresses written in hexadecimal?

Because 128 bits written in decimal would be very long. The address is split into eight 16-bit groups, each written as four hexadecimal digits. Leading zeros in each group can be dropped, and one run of all-zero groups can be shortened to ::. For example, 2001:0db8:0000:0000:0000:0000:0000:0001 can be written as 2001:db8::1.

Check your understanding

Which correctly shortens the IPv6 address 2001:0db8:0000:0000:0000:0000:0000:0001 according to the abbreviation rules?

  1. A2001:db8:1
  2. B2001:db8::1
  3. C2001:db8::0::1
Show answer and explanation

Answer: B. 2001:db8::1

An IPv6 address is 128 bits long (IPv4 is 32 bits), divided into eight 16-bit groups, each written as four hexadecimal digits. There are two abbreviation rules: leading zeros in each group can be dropped (0db8→db8, 0001→1), and one run of consecutive all-zero groups can be replaced with "::" once. Here the five zero groups from the third to the seventh collapse to give 2001:db8::1. Using "::" twice is not allowed because it would be ambiguous how many zero groups each one stands for. "2001:db8:1" has only three groups and lacks the "::" that marks omitted zero groups, so it is not a valid form of this address.

Which of the following IPv4 addresses falls within a private address range?

  1. A172.32.0.1
  2. B192.168.100.1
  3. C11.1.1.1
Show answer and explanation

Answer: B. 192.168.100.1

The private address ranges defined in RFC 1918 are 10.0.0.0/8, 172.16.0.0/12 (172.16.0.0 to 172.31.255.255) and 192.168.0.0/16. They can be used freely inside organizations and homes, and because no routes for them are advertised on the internet, many organizations can reuse the same addresses. To communicate with the internet, a router's NAT translates them to global addresses. 172.32.0.1 has a second octet outside 16–31, so it is not in 172.16.0.0/12, and 11.1.1.1 is outside 10.0.0.0/8.

Home broadband routers perform NAPT (IP masquerading), a form of NAT (Network Address Translation). What does NAPT make possible?

  1. ASeveral devices in the home can share one global IP address simultaneously to communicate with the internet, distinguished by port number
  2. BTraffic between home devices and the internet is encrypted so it cannot be eavesdropped on the way
  3. CEach device in the home is automatically assigned its own separate global IP address
Show answer and explanation

Answer: A. Several devices in the home can share one global IP address simultaneously to communicate with the internet, distinguished by port number

NAT (Network Address Translation) rewrites the source or destination IP addresses of packets passing through a router. NAPT rewrites port numbers as well as IP addresses and records the mapping between "inside address and port" and "outside port" in a translation table. This lets several devices using private addresses share the router's single global address at the same time. Returning packets are delivered to the right device by looking up the table. It only rewrites addresses and does not encrypt anything. Also, connections started from outside have no entry in the table, so they do not reach inside devices by default; hosting a server inside requires settings such as port forwarding.

  1. Which correctly describes the role of ARP?
  2. What is the role of the TTL (Time To Live) field in the IPv4 header?
  3. When a device obtains an IP address with DHCP, what is the correct order of messages?

Practice Computer Networking Basics questions

Key terms explained

CIDR
Classless Inter-Domain Routing. The scheme of freely setting the length of the network part of an IP address as a number of bits (the prefix length) after a slash, as in 192.168.1.0/24, and that notation.
Subnet mask
A 32-bit value that shows how many upper bits of an IP address represent the network (the network part). Written like 255.255.255.0, which means the same as /24 in CIDR notation.
NAT (Network Address Translation)
A technique that rewrites the IP addresses of packets passing through a router. The variant that also rewrites port numbers so many devices can share one global address is called NAPT (IP masquerading).
DHCP
Dynamic Host Configuration Protocol. A protocol that automatically assigns devices joining a network an IP address, subnet mask, default gateway, DNS servers and other settings for a limited time.
ARP
Address Resolution Protocol. A protocol that finds the MAC address of a device on the same network from its IP address. The request is broadcast, and the matching device replies.
MAC address
The 48-bit address used in Ethernet and wireless LAN to identify devices within the same network. The upper 24 bits identify the manufacturer, and it is assigned to each interface at manufacture.
DNS (Domain Name System)
A system, managed in a distributed way by servers around the world, that maps domain names such as www.example.com to the IP addresses used for communication.

Related comparisons