A record vs CNAME: what's the difference and which to use
Kofi Agyem, Founder and CEO, CloudzyroPublished · 6 min read
On this page
An A record points a name to an IP address; a CNAME points it to another name. When to use each, the rules that trip people up, and how to check yours.
1. The short answer
An A record points a name directly to an IP address. A CNAME record points a name to another name, which then gets looked up in turn. Use an A record when your host gives you an IP address; use a CNAME when it gives you a host name, which is usually the case for www and subdomains. A CNAME can't sit on the bare domain or share its name with any other record.
Both are DNS records: entries that tell the world where your domain goes. If DNS is new to you, read What is DNS? first.
2. What an A record does
An A (address) record maps a name to an IPv4 address. Its twin, the AAAA record, does the same for IPv6.
example.com. 3600 IN A 203.0.113.10
example.com. 3600 IN AAAA 2001:db8::10Ask for example.com and DNS answers 203.0.113.10. Simple and final. The catch: if your host moves your site to a new server, you have to update the record yourself.
A name can have several A records. Resolvers return them all, and browsers try them in turn, which spreads load and gives a fallback.
3. What a CNAME record does
A CNAME (canonical name) record says "this name is another name". Looking it up means following it to the target, then finding the target's address.
www.example.com. 3600 IN CNAME sites.examplehost.net.
sites.examplehost.net. 300 IN A 198.51.100.7Ask for www.example.com and DNS follows the alias to sites.examplehost.net, whose A record gives the address. If the host moves its servers, it changes its own record, and yours keeps working untouched. That's why hosts and CDNs prefer you to use a CNAME.
4. Side by side
- Points to: A, an IPv4 address. CNAME, another domain name.
- On the bare domain (`example.com`): A, yes. CNAME, not allowed in standard DNS.
- Other records on the same name: A, yes (MX, TXT and more). CNAME, none at all.
- When the host changes servers: A, you update it. CNAME, nothing to do.
- Lookups: A, one. CNAME, one more to follow the alias (usually cached, so rarely noticeable).
- Typical use: A for the bare domain or a fixed server. CNAME for
www, subdomains, and anything on a host or CDN.
5. Which one should you use?
- Your host gives you a host name (like
something.hostname.net): use a CNAME, onwwwor a subdomain. - Your host gives you an IP address: use an A record (and AAAA if it also gives an IPv6 address).
- It's the bare domain: use an A record, or an ALIAS, ANAME or flattened record if your host gives a host name and your DNS provider supports it (see below).
- The name also needs MX or TXT records: it can't be a CNAME. Use an A record.
- You're verifying a service and it asks for a CNAME on a long random name: add exactly what it says. These names have nothing else on them, so a CNAME is fine.
6. The rules that trip people up
- A CNAME can't share its name with anything. Not an A record, not MX, not TXT. That's from the original DNS standard (RFC 1034). It's the most common reason a provider refuses to save a CNAME: there's an old A record or parking record on the same name. Delete it first.
- So no CNAME on the bare domain. The bare domain always has NS and SOA records, so a CNAME there breaks the rule above, and would take your email records with it.
- A CNAME can't point to an IP address. The target is always a name.
- MX and NS records mustn't point to a CNAME (RFC 2181). Point them at a name with A records.
- Avoid long chains. A CNAME to a CNAME to a CNAME works, but each hop is another lookup and another thing that can break.
7. ALIAS, ANAME and CNAME flattening
Because the bare domain can't have a CNAME, many DNS providers offer a workaround under different names: ALIAS, ANAME, or CNAME flattening (Cloudflare's term). You enter a host name, and the provider looks it up behind the scenes and answers with plain A and AAAA records. To the rest of the internet it looks like an A record, so it's allowed on the bare domain.
Cloudflare, Namecheap, Porkbun, Squarespace Domains, DNSimple, DNS Made Easy, easyDNS, Gandi and DreamHost support it. Some others don't. If yours doesn't, use www as your main address and forward the bare domain to it. See www vs non-www.
8. A worked example
Here's how a domain is set up for a site on Cloudzyro Sites & Apps. It uses both record types, each where it fits:
Type Name Value
CNAME www domains.cloudzyro.app
A @ 173.234.137.167www is a CNAME, so we can change servers without you touching your records. The bare domain (@) can't be a CNAME, so it's an A record to a server that sends visitors to https://www.yourdomain.com, keeping the rest of the address. Your MX and TXT records for email stay on @ alongside the A record, which is allowed.
If your provider supports flattening, you can instead put a flattened CNAME on the bare domain pointing to domains.cloudzyro.app and use the bare domain as your main address. Step by step: How to point your domain at your site, or the docs' Connect a custom domain. Domains bought in Cloudzyro Domains get these records set for you.
9. How to check yours
# Show the CNAME, if there is one
dig +short CNAME www.example.com
# Show the A records
dig +short A example.com
# Show the whole answer, including the chain
dig www.example.com
# Windows
nslookup -type=CNAME www.example.com
nslookup -type=A example.comA plain dig +short www.example.com follows any CNAME and prints both the alias target and the final address, one per line.
If the answer is still an old value after you've changed it, the old record is cached until its TTL runs out. If it's empty, check the domain's nameservers (dig +short NS example.com) and make sure you edited the records there. For a domain on a Cloudzyro site, see Domain not working.