Protocols Reference

DNS A and AAAA Records

An A record returns a 32-bit IPv4 address and an AAAA record returns a 128-bit IPv6 address; both may exist for one name, and DNS expresses no preference, so the client chooses by address-selection and connection policy.

The short answer

An A record maps a domain name to a 32-bit IPv4 address in 4 octets of RDATA. An AAAA record maps the same kind of name to a 128-bit IPv6 address in 16 octets. A name may have zero, one, or many records of either type. DNS does not rank the two families: an authoritative server returns the records that exist, and a resolver passes along what it receives.

Which address a client uses is a separate decision, governed by its address-selection policy and connection logic, not by record type alone. The common claim that AAAA is always preferred because it is newer is not a DNS rule.

Record format

Type Number RDATA Wire length Presentation example
A 1 IPv4 address 4 octets 192.0.2.10
AAAA 28 IPv6 address 16 octets 2001:db8::10

The type numbers and A format come from RFC 1035. AAAA is defined in RFC 3596, which reuses the address-record shape for 128-bit addresses. The name "quad A" reflects that 128 bits is four times 32 bits.

A minimal example

dig example.com A +short
dig example.com AAAA +short

A dual-stack name can return both:

192.0.2.10
2001:db8::10

A program should ask for both families in one call rather than issuing two queries:

import socket

for info in socket.getaddrinfo("example.com", 443, type=socket.SOCK_STREAM):
    print(info[0], info[4][0])

With AF_UNSPEC, the resolver returns both families and the platform applies its ordering policy. An IPv4-only client asks for A, an IPv6-only client asks for AAAA, and a dual-stack client usually asks for both.

Why two record types exist

IPv4 and IPv6 are different address families with different address spaces and header formats. A dual-stack host needs both an IPv4 and an IPv6 address, and DNS needs a record type for each. RFC 3596 defined AAAA by analogy with A, keeping the same query and response structure but widening the address field.

The types are independent: A does not imply AAAA, or the reverse. A host can be IPv4-only, IPv6-only, or dual-stack, and a name can publish only the family its service supports.

When one is preferred

Three layers decide, and only the last one is visible to users:

  1. The DNS answer contains both types when both exist. No preference is encoded in the response.
  2. The resolver and operating system may sort addresses, for example by destination address selection rules that consider scope and prefix policy.
  3. The application's connection logic may race or stagger attempts across families, as Happy Eyeballs does, so a broken IPv6 path falls back to IPv4 quickly.

Prefer what works. Do not resolve only A because IPv6 is assumed slow, or require AAAA because IPv6 is assumed faster. Publish both records when the service is dual-stack and keep the addresses reachable.

Edge cases

A query that returns NOERROR with an empty answer for AAAA is NODATA, not NXDOMAIN: the name exists but has no record of that type. If the name is a CNAME, the query follows the alias and the address records live at the canonical name. Multiple addresses may be returned in unstable order, and round-robin is common, so the first address is not a primary.

Negative answers are cached according to their TTL, so a recently added AAAA record may not appear immediately. Publishing AAAA for a service that listens only on IPv4 causes failed connection attempts; Happy Eyeballs reduces the delay but does not fix the missing listener.

Practical checks

dig +short example.com A
dig +short example.com AAAA
curl -4 -sS -o /dev/null -w '%{http_code} %{remote_ip}\n' https://example.com
curl -6 -sS -o /dev/null -w '%{http_code} %{remote_ip}\n' https://example.com

If both record types exist but the IPv6 request fails, the DNS data is not the problem; check the listener, firewall, and route. If a connection succeeds but the response is not what you expect, that is a later layer: Why Does an HTTP 304 Response Have No Body? covers one common response-framing surprise.

Sources

Revision history

Published
Updated
— Initial publication.