Dual stack
A stack is the software that sends one kind of packet. Your laptop runs two: IPv4 with 192.168.1.10 and IPv6 with 2001:db8:1::10. Running both at once is called dual stack, and most networks work this way.
To open www.example.com the laptop asks its DNS resolver (the server that looks up names) two questions together: AAAA for the IPv6 address and A for the IPv4 address. The AAAA question goes first.
The resolver returns both records: AAAA 2001:db8:10::10 and A 203.0.113.10. The site is dual stack too, so there are now two roads to the same server.
Happy Eyeballs
Happy Eyeballs (RFC 8305) tries IPv6 first, because the default rules prefer it. A TCP SYN (the "let's connect" message) leaves for [2001:db8:10::10]:443. Today the IPv6 road is broken, so nothing comes back.
The laptop does not wait for a timeout, which can take many seconds. After 250 ms with no answer it starts a second attempt over IPv4. The IPv6 attempt stays open, in case it is only slow.
A second SYN leaves for 203.0.113.10:443 over IPv4. Now two connection attempts race to the same server, one on each road.
The SYN-ACK (the server's "yes, let's connect") arrives over IPv4 first, so the laptop keeps that connection and cancels the IPv6 attempt. The page loads only a quarter second late. When IPv6 works, it wins and IPv4 is never tried.
IPv6-only: NAT64 + DNS64
Now the laptop joins an IPv6-only network, as many mobile networks are, so it has no IPv4 address. It asks for legacy.example.net, a site that has only an IPv4 address.
The resolver runs DNS64 (RFC 6147). It finds only the A record 198.51.100.20, so it builds an AAAA record: the NAT64 prefix 2001:db8:64::/96 with those 32 bits at the end, 2001:db8:64::c633:6414.
The laptop sends an ordinary IPv6 packet to that address. The network routes the whole 2001:db8:64::/96 prefix to the NAT64 gateway, which reads the last 32 bits back out: 198.51.100.20.
The gateway (RFC 6146) rebuilds the packet as IPv4 from its own address 192.0.2.64, and remembers the mapping like a home NAT. Replies come back the same way and are turned into IPv6 for the laptop.
The packets, field by field
;; step 1/11 · two-stacks · stack ;; at your laptop laptop, both stacks up: IPv4 192.168.1.10/24 (home LAN, RFC 1918) IPv6 2001:db8:1::10/64 (global, 2001:db8:1::/64) IPv4 addresses are 32 bits, IPv6 addresses 128 bits (RFC 8200) each stack has its own address, routes and default gateway
Happy Eyeballs (RFC 8305) recommends a 250 ms Connection Attempt Delay and a 50 ms Resolution Delay; browsers and operating systems tune these. The NAT64 prefix 2001:db8:64::/96 is a network-specific prefix (RFC 6052). Many real networks use the well-known prefix 64:ff9b::/96, which must not carry documentation addresses like 198.51.100.20. Tunnels are the other transition tool: 6in4 (RFC 4213) wraps a whole IPv6 packet inside IPv4, protocol number 41, to cross an IPv4-only network. A tunnel carries the packet unchanged; NAT64 translates it.