Guides /DNS
DNS

How to Add a Subdomain in DNS: A Record vs CNAME

November 22, 20256 min readHostBible Team

Creating a subdomain requires adding a DNS record in your zone file. Whether that record is an A record or a CNAME depends on what you're pointing the subdomain at. This guide covers the rules, the examples, and the common pitfalls, so you get the right record type first time.

What Makes a Subdomain

A subdomain is any hostname that precedes your domain: www.yourdomain.com, shop.yourdomain.com, staging.yourdomain.com. You don't register subdomains separately, you create them by adding a DNS record with that name in your zone. The DNS record is what makes a subdomain resolve.

There's no limit on the number of subdomains you can create. You can have as many as your DNS provider's zone allows, and they can each point to different servers, services, or IPs.

Option 1: A Record, Use When You Have an IP Address

An A record maps a subdomain directly to an IPv4 address. Use this when you're pointing the subdomain at a specific server you control and know the IP.

Example, creating shop.yourdomain.com pointing to a server:

Type: A
Name: shop
Value: 93.184.216.34
TTL: 3600

Use an A record for:

  • Subdomains pointing to your own servers (staging, dev, api, admin)
  • Mail server subdomains (mail.yourdomain.com), must use A, never CNAME
  • Any case where you know the exact IP and it's stable

Option 2: CNAME Record, Use When Pointing to Another Hostname

A CNAME maps a subdomain to another domain name rather than an IP address. When the resolver looks up a CNAME, it follows the alias to the target and resolves that target's IP. Use CNAME when a third-party service gives you a hostname to point to, rather than an IP.

Example, pointing store.yourdomain.com to a Shopify store:

Type: CNAME
Name: store
Value: shops.myshopify.com
TTL: 3600

The advantage of CNAME over A record for third-party services: when the provider changes their server IP, your subdomain automatically follows. You don't need to update your DNS, the CNAME always resolves to whatever IP the target hostname currently points to.

Use CNAME for:

  • Third-party services: Shopify, HubSpot, Zendesk, Stripe, Vercel, Netlify
  • CDN configuration where the provider gives you a hostname
  • www pointing to your bare domain
  • Any service that uses dynamic IPs and provides a hostname

The Rules You Must Follow

  • No CNAME at the bare domain (@). The root domain (yourdomain.com without any prefix) must use an A or AAAA record. The DNS spec prohibits CNAME records at a zone apex because the bare domain also needs SOA and NS records, which cannot coexist with a CNAME at the same name. Some DNS providers offer a proprietary workaround ("ALIAS", "ANAME", or "CNAME Flattening") that resolves the CNAME and publishes the result as an A record, but native CNAME is not allowed.
  • A CNAME must be the only record at that name. You cannot have a CNAME and any other record type (MX, TXT, A) for the same subdomain. This is why mail.yourdomain.com must use an A record, if it used a CNAME, you couldn't have MX records pointing to it.
  • CNAME chains should be short. A CNAME pointing to another CNAME is valid but adds an extra lookup step. Chains of 3+ hops add measurable latency. Keep chains to a maximum of two levels where possible.

Common Subdomain Setups

  • www: typically either a CNAME pointing to the bare domain, or an A record matching the bare domain's IP. Either works; CNAME is convenient since you only update the IP in one place.
  • mail: A record pointing to your mail server's IP. Never a CNAME, MX records pointing to a CNAME are explicitly invalid per RFC 2181.
  • staging / dev: A record pointing to a staging server, or CNAME to a platform hostname (e.g. for Vercel or Netlify preview environments).
  • api: A record pointing to your API server IP, or CNAME to a load balancer or API gateway hostname.
  • cdn / static / assets: CNAME pointing to your CDN provider's hostname (e.g. a CloudFront distribution hostname).
  • help / support: CNAME to your Zendesk or Freshdesk hosted help centre hostname.

Step-by-Step: Adding the Record

  1. Log in to wherever your DNS is managed: your registrar's DNS control panel, your hosting provider's zone editor (e.g. HostBible's control panel), or a third-party DNS provider like Cloudflare.
  2. Find the DNS or Zone Records section for your domain.
  3. Click Add Record (or similar).
  4. Select the record type (A or CNAME).
  5. Enter the subdomain name in the Name field. Just enter the prefix: shop, not shop.yourdomain.com (some interfaces want the full hostname, check the field label).
  6. Enter the IP address (for A record) or target hostname (for CNAME) in the Value field.
  7. Set a TTL. 3600 (1 hour) is a sensible default. Use 300 (5 minutes) if you expect to change it soon.
  8. Save the record.

Changes propagate within minutes when TTL is low, or up to the TTL duration if records were recently cached.

Verifying the Record Is Working

# Check what the subdomain resolves to
dig shop.yourdomain.com A +short

# For a CNAME, see the full chain
dig shop.yourdomain.com CNAME +short

# Query an authoritative nameserver directly
dig @ns1.hosted-server.net shop.yourdomain.com A +short

DNS zone management included with all plans

Add and edit DNS records for any domain or subdomain from your HostBible control panel. Register your domain with us and manage everything in one place.

Register a Domain