CNAME vs A record: when to point at an address and when to alias a name

By TechCompare · Updated · How we check

Pick A or AAAA records for addresses you control and a CNAME for names a provider controls. A CNAME can't share its name with any other record, so it can't sit on the root domain.

An A record maps a name straight to an IPv4 address, and an AAAA record does the same for IPv6. A CNAME works differently: it says this name is an alias, so go and look up that other name instead. Use an A record when you control the address. Use a CNAME when a service like a CDN or a hosted shop owns the address and may change it.

Topic
CNAME vs A record
Aliases and addresses
Category
Record types
What each record does

How this is calculated

A CNAME takes over its whole name. RFC 1034 says a name with a CNAME can't have any other records, which is why you can't put one on example.com itself: the root of a zone always needs its NS and SOA records. You also can't add a TXT or MX record next to a CNAME on the same name. That catches people out when a service asks for a verification record on www.

Many DNS hosts work around the root problem with a flattened CNAME, also sold as an ALIAS or ANAME record. The host looks up the target itself and answers with plain A and AAAA records, so resolvers never see an alias.

The cost of a CNAME is small. A resolver follows the alias and usually returns the whole chain in one answer. Long chains add a little time on a cold cache and more places for something to break, so keep them short.

The DNS Lookup shows the alias path above each record type, like www.example.com pointing to example.net, so you can see where a CNAME leads and which addresses each resolver ends up at.

Verdict

Use A and AAAA records for servers with fixed addresses you manage. Use a CNAME for www and other subdomains that point at a hosted service, so the provider can change addresses without asking you. For the root domain, use your DNS host's ALIAS or flattening option, or the A records the provider publishes.

More DNS scenarios

TXT records
The free text record that holds verification codes, SPF, DKIM keys and DMARC policies.
View details
SPF vs DKIM vs DMARC
SPF checks the sending server, DKIM checks the message, and DMARC ties both to the From address.
View details
MX records
How senders find your mail servers, what the priority number does, and the null MX for domains that take no mail.
View details

Frequently asked questions

Can I put a CNAME on my root domain?
Not as a real CNAME. The root needs NS and SOA records, and a CNAME can't share its name with any other record. Use your DNS host's flattening, ALIAS or ANAME option, which answers with A and AAAA records, or enter the A records your provider lists.
Is a CNAME slower than an A record?
Barely. The resolver has to follow the alias, but it usually gets the whole chain in one reply, and both steps are cached afterward. The difference only shows on the first lookup after the cache runs out.
Can a CNAME point to an IP address?
No. A CNAME's target is always a name. To point a name at an address, use an A record for IPv4 or an AAAA record for IPv6.