What is a CNAME Record and When Should You Actually Use One
If you have ever set up a subdomain or connected a third-party service to your domain, you have almost certainly created a CNAME record. They are one of the most commonly used DNS record types, and also one of the most frequently misunderstood. Here is the full picture.
What a CNAME Record Actually Does
A CNAME (Canonical Name) record maps one hostname to another hostname — not to an IP address. When a resolver looks up a hostname with a CNAME, it follows the chain to the target and resolves that target to an IP. Two lookups happen, but the result is one IP.
Why This Is Useful
CNAMEs decouple your hostnames from IP addresses. If your origin server moves and its IP changes, you only update the A record for the canonical name — every CNAME pointing to it gets the new IP automatically. This is also why third-party services like Shopify or your CDN ask for a CNAME rather than an A record. Their infrastructure can change IPs at any time, so they control IP resolution on their end while you just point your hostname at theirs.
Common CNAME Use Cases
- www subdomain:
www.example.com CNAME example.com— the www version follows wherever the apex goes - Third-party services:
shop.example.com CNAME stores.shopify.com— your subdomain points to Shopify infrastructure - CDN:
cdn.example.com CNAME example.cdn-provider.net— routes asset requests to a CDN edge - Email tracking:
click.example.com CNAME tracking.mailprovider.com— branded tracking links
The Zone Apex Restriction
You cannot put a CNAME at the root of your domain. example.com cannot be a CNAME because the apex must have SOA and NS records, and those cannot coexist with a CNAME at the same name. This is why you cannot CNAME your root domain to Netlify or Shopify. The workaround is CNAME flattening (sometimes called ALIAS or ANAME records), which some DNS providers like Cloudflare support — they resolve the CNAME chain at the authoritative level and return an A record to the client.
CNAME Chains
You can chain CNAMEs — A points to B which points to C which has an A record. This works but each hop is an extra DNS lookup. Most resolvers cap chain depth at 8–10 hops to prevent loops. In practice, chains longer than two are a sign of messy DNS management rather than a real need.
What Cannot Coexist With a CNAME
When a name has a CNAME record, that is all it can have. No MX, no TXT, no other records at that same hostname. This is a hard DNS rule. If you need an MX record for mail.example.com, you cannot also have a CNAME there. Plan your subdomain structure with this constraint in mind before adding CNAMEs.
CNAME vs. A Record: The Simple Rule
Use an A record when you know and control the IP and it is stable. Use a CNAME when pointing at a hostname you do not control and whose IP might change. If a third-party service gives you a hostname to point at, CNAME is almost always the right choice.