When you point a domain at a server, you choose between an A record (“this name has this IP”) and a CNAME (“this name is an alias of that other name”). Both work for many cases, but they behave differently, and one important rule trips people up: the root domain can’t be a CNAME. Here’s how to choose.
For an overview of every record type, see DNS records explained.
How they resolve
A record, one step:
shop.example.com. A 203.0.113.10
A resolver asking for shop.example.com gets 203.0.113.10 directly. (AAAA is the same for IPv6.)
CNAME, a pointer, then another lookup:
shop.example.com. CNAME stores.platform.com.
stores.platform.com. A 198.51.100.25
The resolver learns that shop.example.com is an alias, then looks up stores.platform.com to get the IP. Whatever the target’s IP becomes, the alias follows automatically.
When to use which
| Situation | Use |
|---|---|
| Pointing a domain at your own VPS | A (and AAAA if you have IPv6) |
Root / apex domain (example.com) |
A (or the provider’s ALIAS/flattening) |
www pointing to the same server as the root |
A to the same IP, or CNAME to the root |
| Pointing at a SaaS or platform whose IPs may change (Shopify, GitHub Pages, Vercel, a CDN hostname) | CNAME to the hostname they give you |
| Many subdomains on one server | A records, or CNAMEs to one A record you can change in one place |
| Domain verification records, DKIM keys on some providers | CNAME, when the provider asks for it |
Rule of thumb: use an A record when you control the IP, and a CNAME when someone else controls it and gives you a hostname.
Why the root domain can’t be a CNAME
The DNS standard says a CNAME can’t coexist with any other record at the same name. The root domain always needs SOA and NS records, and usually MX and TXT (mail, SPF, verification) too. A CNAME at example.com would conflict with all of them, and break email in practice.
So:
example.com. A 203.0.113.10 ✓
www.example.com. CNAME example.com. ✓
example.com. CNAME something.else. ✗ (invalid, breaks MX/TXT)
CNAME flattening and ALIAS records
Some DNS providers offer a workaround: CNAME flattening (Cloudflare) or ALIAS / ANAME records (DNSimple, Route 53 “alias”, others). You configure a CNAME-like target at the apex. The provider resolves it itself and serves an ordinary A record to visitors. That lets the root domain follow a platform hostname. It’s a provider feature, not standard DNS, and depends on your DNS host.
The CNAME “no other records” rule applies to subdomains too
mail.example.com. CNAME mailhost.provider.com.
mail.example.com. TXT "…" ✗ conflict
If a name needs other records, use A/AAAA records instead of a CNAME.
Also: MX and NS records must not point to a CNAME. They must point to a name with A/AAAA records.
Performance
A CNAME adds a lookup step, which is negligible in practice, since resolvers cache both answers. Long CNAME chains (an alias of an alias of an alias) add latency and fragility. Keep it to one hop.
Typical setup for a website on a VPS
example.com. 300 A 203.0.113.10
example.com. 300 AAAA 2001:db8::10 (only if IPv6 is configured)
www.example.com. 300 CNAME example.com.
Then configure the web server for both names, and redirect one to the other. See Nginx server blocks and Nginx HTTP to HTTPS and www redirects.
Check your records
dig +short example.com A
dig +short www.example.com # shows the CNAME target, then the IP
dig www.example.com CNAME +noall +answer
See dig.
Common mistakes
- CNAME at the root in panels that allow it, which silently breaks email.
- CNAME plus other records at the same name.
- Trailing dot confusion in zone files:
example.comwithout a dot may becomeexample.com.example.com.. Web panels usually handle this for you. - Pointing a CNAME at an IP address. CNAMEs take hostnames, and A records take IPs.
- Forgetting AAAA: an AAAA record pointing to an old or unused IPv6 address breaks access for IPv6 users.
Quick reference
| A / AAAA | CNAME | |
|---|---|---|
| Value | IP address | Another hostname |
| At the root domain | Yes | No (use ALIAS/flattening) |
| With other records at the same name | Yes | No |
| Follows target IP changes | No | Yes |
| Best for | Your own servers | SaaS, CDNs, platforms |
Related: DNS propagation and MX records.