AboutAdvertiseContact
Domains & Hosting

CNAME vs A Record

Which DNS record does which job, why the root domain needs special handling, and three setups site owners actually meet.

Goomsite Desk3 min read4 sources checked
CNAME vs A Record
Photo: David Bedard / Wikimedia Commons, Public domain
On this page
  1. Records that do one job each
  2. Why the root domain is different
  3. Three practical examples

Site owners often need to decide between CNAME and A records when setting up custom domains, but which one does the job right? Here is a breakdown of the DNS records you really need, why the root domain is different, and why flattening matters.

Records that do one job each

You can think of DNS records as small instructions that point names to addresses or direct your traffic:

  • A and AAAA records are both address records. An A record points a name to an IPv4 address (like example.com to 192.0.2.1), while an AAAA record does the same for IPv6 (like 2001:db8::1).
  • CNAME records (canonical name records) are not addresses; they are aliases that point one name to another name, such as www.example.com to example.com. A CNAME is not allowed to coexist with any other data for the same name, so you cannot add an A, MX or TXT record next to it.
  • MX records (mail exchange) tell other servers which mail server accepts email for your domain. An MX record should not point to a name that is itself a CNAME.
  • TXT records store text, often used for domain verification. Google Search Console, for instance, gives you a value in the form google-site-verification=... to add as a TXT record.
  • NS records (name servers) name the DNS servers that are authoritative for your domain, usually the ones your registrar, host or DNS provider gives you.

Why the root domain is different

The root of your domain (example.com, also called the zone apex) is a special case. It sits above www.example.com and any other subdomains, and it always carries the zone's SOA and NS records. Because a CNAME cannot coexist with other data, the root domain cannot normally have a CNAME. It needs a direct address with an A or AAAA record, or a provider-specific ALIAS-style record.

That is where CNAME flattening comes in. With Cloudflare's CNAME flattening, you can use a CNAME record at the zone apex: Cloudflare finds the IP address the CNAME points to and returns that final address instead of a CNAME record. Other DNS providers offer similar features under names such as ALIAS or ANAME.

Every DNS record also has a time-to-live (TTL), measured in seconds. TTL tells resolvers how long they can cache the answer before asking again, so it controls how long an outdated record can linger after you change it. On Cloudflare, the Auto setting means 300 seconds, and proxied records always use Auto.

Three practical examples

Your DNS provider's dashboard labels may differ from the ones below, and menu names can change over time, but the record types and values work the same way.

  1. Point your domain to hosting. Your host gives you an IP address. Add an A record for example.com with that address (and an AAAA record if the host gives an IPv6 address), then a CNAME for www pointing to example.com.
  2. Point your domain to Blogger. In Blogger, the custom domain option sits under Settings, Publishing. Blogger asks for a CNAME with the name www and the destination ghs.google.com, plus a second CNAME whose name and destination are specific to your blog and Google Account. To make the naked domain redirect to www, add four A records: 216.239.32.21, 216.239.34.21, 216.239.36.21 and 216.239.38.21.
  3. Verify with TXT. To verify a Domain property in Google Search Console, add the TXT record Search Console shows you, for example google-site-verification=abc123xyz456 on example.com. Google notes it can take from a few minutes to a few days before the record is visible to it.

Whether it is CNAME, A, AAAA, MX or TXT, the right record depends on the job. Pointing a name to an IP address needs an A or AAAA record; pointing it to another name needs a CNAME; proving ownership usually needs a TXT record. The one real trap is the root domain, where a flattened CNAME or ALIAS record lets you treat it almost like any other name.

Sources checked

Keep reading