LearnPart 2 of 8
Subdomains, hostnames and the root domain
A subdomain is a name you create under a domain you already have, like shop.example.com under example.com. It is free, it takes one DNS record, and it can point anywhere you like, independent of the main site.
In 30 seconds
- A subdomain is a name you make under your own domain, like shop.example.com.
- It is free, takes one DNS record, and can point anywhere, separate from your main site.
- www is just a subdomain. Pick www or the bare domain as your main address and redirect the other.
- Delete records for services you stop using, so nobody else can claim them.
Words with a dotted underline explain themselves: tap or hover them.
What a subdomain is
When you register example.com, you get everything underneath it too. Put any label in front, add a for it, and the new name works: blog.example.com, app.example.com, status.example.com, even eu.app.example.com.
Nobody else is involved. The registry and registrar only know about example.com; your subdomains live entirely in your own DNS records. That is why they cost nothing and appear the moment the record is saved, apart from caching.
Everything happens in your browser; nothing you type is sent or saved.
eu.app.example.com is a subdomain of example.com. Whoever registered example.com can create it for free.
| Registered domain | example.com |
|---|---|
| Subdomain | eu.app |
| Hostname | eu.app.example.com |
| Extension | .com |
| Levels | One-level extension |
| Type | Generic (gTLD) |
| Run by | Verisign |
The root domain (apex)
The domain itself, with nothing in front, is called the root domain, the apex, or the naked or bare domain. In DNS settings it is usually written as @.
The apex has one quirk worth knowing. It must hold the domain's SOA and NS records, and a CNAME record can't sit next to other records, so the apex can't be a CNAME. If a host asks you to CNAME your root domain to them, use an A record with the IP address they give you, or your DNS host's ALIAS, ANAME or CNAME flattening feature, which does the same job (see ALIAS records).
Is www a subdomain?
Yes. www is a subdomain like any other, kept by convention from the early web, when one organisation's domain had separate machines for the web (www), file transfers (ftp) and mail.
Today the choice is about taste. Pick one address as the real one, point both at your website, and redirect the other to it, so links, bookmarks and search engines all agree. Make sure your HTTPS certificate covers both names, or visitors to the other one see a warning.
Subdomain vs hostname
A hostname is any full name that points at a machine or service: www.example.com, mail.example.com, or example.com itself. Subdomain describes a relationship: shop.example.com is a subdomain of example.com. So www.example.com is both a hostname and a subdomain, while example.com is a hostname and a registered domain.
Second-level, third-level: counting levels
People sometimes count levels from the right. In www.example.com, .com is the top level, example is the second level and www is the third level. That is where the terms second-level domain and third-level domain come from.
Counting gets confusing with two-level extensions. In shop.example.co.uk, the registered domain example.co.uk is already at the third level and shop is at the fourth. It is clearer to talk about the extension, the registered domain and its subdomains, which is what the rest of this guide does. More on two-level extensions.
Subdomain or folder?
You can put a blog at blog.example.com or at example.com/blog. Both work. The difference is mostly practical:
| Subdomain: blog.example.com | Folder: example.com/blog | |
|---|---|---|
| Hosting | Can run on a completely different service. | Served by the main site or a reverse proxy in front of it. |
| Setup | One DNS record. | Configuration on the web server. |
| Search engines | Treated as its own section of the site, and listed separately in search tools. | Clearly part of the main site. |
| Cookies and logins | Kept separate unless set for the whole domain. | Shared with the main site. |
| Good for | Apps, docs, status pages, regional sites. | Content that belongs with the main site, like a blog or help pages. |
Wildcard subdomains
A wildcard record, *.example.com, answers for any subdomain that doesn't have its own record. Apps that give each customer an address like customer.example.com use it so they don't have to add a record per customer.
A wildcard covers one level only: *.example.com matches shop.example.com but not eu.shop.example.com. Wildcard HTTPS certificates follow the same one-level rule.
Keeping subdomains safe
Delete DNS records for services you stop using. A subdomain that still points at a deleted app or bucket can be claimed by someone else on that service, who then controls what appears on your subdomain.
This is called a subdomain takeover, and it is entirely avoidable: when you close an account somewhere, remove the CNAME that pointed at it. To see which subdomains of a domain are publicly known, run a domain report; it lists names found in public certificate logs.
Questions people ask
Do subdomains cost money?
No. Once you have registered a domain, you can create subdomains under it for free by adding DNS records at your DNS host. Some hosting services charge for the things you point a subdomain at, but the subdomain itself is free.
How many subdomains can I have?
As many as you need. DNS itself has no practical limit; some DNS hosts cap the number of records per domain on their plans.
Is www.example.com the same as example.com?
They are two different hostnames. Most sites point both at the same website and redirect one to the other, so visitors and search engines see a single address.
Does a subdomain need its own HTTPS certificate?
It needs a certificate that covers its name. That can be a certificate just for that subdomain, one listing several names, or a wildcard certificate for *.example.com. Most hosts issue these automatically.
Can a subdomain point to a different host than the main site?
Yes. Each subdomain has its own DNS records, so shop.example.com can point at a store platform while www.example.com points at your website host and mail goes somewhere else again.
Can someone else create a subdomain of my domain?
Only someone who can edit your domain's DNS records. The one exception is a forgotten record that still points at a service you stopped using, which someone else could claim there. Remove records you no longer need.