Subdomains and wildcard DNS records explained
A subdomain is a name below your domain with its own DNS records, and a wildcard record (*.example.com) answers for names that have no explicit record at that level.
- Updated Nov 27, 2026
- Markdown
Create subdomain records, add a wildcard where it fits and predict which names it will and will not answer.
- A domain whose DNS you can edit
- dig installed
A subdomain is a name placed in front of your domain, such as app.example.com or api.example.com. It exists when a record for that name exists in your DNS zone. A wildcard record, written with an asterisk as its name, answers for names that have no record of their own. Both are ordinary records, and the choice between many explicit records and one wildcard depends on how predictable your names are.
How it works#
Names in DNS are made of labels separated by dots. In app.example.com the labels are app, example and com. A subdomain record is just a record whose name has extra labels in front of the zone name. In most provider panels you type only the part in front of the domain: entering app for a record in the example.com zone creates app.example.com.
A wildcard is a record whose leftmost label is *. When a resolver asks the authoritative server for a name that does not exist, the server checks whether a wildcard applies and, if so, answers as though the record existed under the requested name. The rules are defined in RFC 4592, and they are narrower than many people assume.
Step 1: Add a record per subdomain#
The explicit approach lists each name. For two apps on one server:
app.example.com. 300 IN A 203.0.113.10
api.example.com. 300 IN A 203.0.113.10You can also use a CNAME so the subdomain follows another name:
docs.example.com. 300 IN CNAME app.example.com.Explicit records are easy to audit, and each can point somewhere different or have its own TTL. The cost is that every new name needs an edit. See DNS record types explained for choosing A, AAAA or CNAME.
Step 2: Add a wildcard when names are open ended#
If a reverse proxy routes by hostname and you create names often, one wildcard saves edits:
*.example.com. 300 IN A 203.0.113.10Now anything.example.com, test.example.com and a typo like wwww.example.com all resolve to 203.0.113.10. That is convenient for per-customer or per-preview subdomains, and it also means every typo resolves to your server, so the server must handle unknown hostnames sensibly (return a 404 or close the connection).
Step 3: Know what a wildcard does not match#
Four points cause most confusion.
The apex is not covered. *.example.com does not answer for example.com itself. Add an explicit record (an A record, or an ALIAS where your provider supports it, see CNAME flattening and ALIAS records).
Explicit records win. If api.example.com has its own record, the wildcard is ignored for api.example.com, for every record type that explicit name holds. This also means an explicit name with only a TXT record can stop the wildcard A record from answering for it, because that name exists and has no A record. Answering “no data” is correct behavior there.
Deeper levels are not covered the way people expect. The wildcard stands in for one label at the position of the asterisk. A lookup for a.b.example.com can match *.example.com only if b.example.com does not exist as a name in the zone. If anything exists at or below b.example.com, for instance c.b.example.com, then b.example.com is an “empty non-terminal” that exists, and the wildcard no longer applies to names under it. To cover a second level you add a second wildcard such as *.b.example.com.
The wildcard matches by record type too. A wildcard A record answers A queries only. If you want IPv6, add a wildcard AAAA record next to it.
Step 4: Think about the certificate#
DNS and TLS are independent. Making every subdomain resolve does not make HTTPS work for it. A certificate must cover each name. You can request one certificate per hostname, or a single wildcard certificate for *.example.com, which has the same one-level limit as the DNS wildcard and also does not cover the apex. Wildcard certificates require the DNS-01 challenge. Read Wildcard certificates explained and How TLS certificates are issued.
Check it worked#
Query names that should and should not match:
dig +short app.example.com A
dig +short random-name.example.com A
dig +short example.com A
dig +short a.b.example.com AThe first is explicit, the second should return the wildcard target, the third should return your apex record (not the wildcard), and the fourth shows whether the deeper name is covered. Use dig @ns1.example.net to rule out caching, as described in Check DNS with dig.
Edge cases and gotchas#
- Typos resolve: with a wildcard, mistyped names reach your server, so unknown hosts need a safe default response.
- Email and wildcards: a wildcard A record does not create mail routes, and a wildcard MX can affect more names than you intended.
- CNAME wildcards: a wildcard CNAME is allowed in most providers, but chains of aliases add lookup time.
- Provider quirks: some control panels display the wildcard as
*and others as*.example.com, so check the final record in dig. - Security: a wildcard makes subdomain takeover and phishing lookalikes easier if a stray name points to something you no longer control.
- Negative caching: a name that did not exist a minute ago may be cached as missing even after you add the wildcard.
Troubleshooting#
| Symptom | Likely cause | Fix |
|---|---|---|
| example.com does not resolve but sub.example.com does | The wildcard does not cover the apex | Add an explicit apex record |
| a.b.example.com returns NXDOMAIN | b.example.com exists, so the wildcard no longer applies | Add *.b.example.com or an explicit record |
| One subdomain ignores the wildcard | It has its own record of another type | Add the missing record type to that name |
| HTTPS fails on a subdomain that resolves | The certificate does not cover that name | Issue a certificate that includes it |
| New subdomain not found for a while | Negative cache from an earlier lookup | Wait for the SOA minimum, test the authoritative server |
| Any random name opens your site | Wildcard plus a catch all virtual host | Add a default server block that returns 404 |
Quick reference#
app A 203.0.113.10 -> app.example.com
* A 203.0.113.10 -> any other name directly below example.com
@ A 203.0.113.10 -> example.com itself (apex)Related lessons#
- DNS record types explained: which record type to use for each name.
- Wildcard certificates explained: the HTTPS side of wildcards.
- CNAME flattening and ALIAS records: pointing the apex at a hostname.
- What is a DNS zone: where these records live.
- Point a domain at your server: the first record you create.
Next#
Continue with CNAME flattening and ALIAS records.
Check what you learned
Frequently asked questions
How do I create a subdomain?
Add a record in your domain's DNS zone with the subdomain as the name, for example an A record named app pointing to your server IP. The subdomain exists as soon as the record does.
What does a wildcard DNS record do?
A record named * answers queries for any name under the domain that has no explicit record. For example *.example.com can send any random subdomain to the same server.
Does a wildcard DNS record cover the root domain?
No. The apex example.com needs its own A or ALIAS record. The wildcard only matches names below it.
Do I need a wildcard certificate for a wildcard DNS record?
DNS and certificates are separate. A wildcard record lets any subdomain resolve, but each name still needs a certificate that covers it, either one per name or one wildcard certificate.
Sources
Keep going: guides and tutorials
- Self-Hosted Static Site Hosting: Deploy a Folder With Levelrail Self-hosted static site hosting from a plain folder: one deploy command, _redirects, _headers and a custom 404 honored, plus a one command rollback.
- Deploy Next.js on a VPS With Docker, Git Push and HTTPS Deploy a Next.js app to your own VPS with Docker, a health check, HTTPS and rollback. Includes the NEXT_PUBLIC build trap that leaves variables empty.