What Is a TXT Record
Learn what TXT records are and how they're used for domain verification, SPF, DKIM, and DMARC. Includes examples for the DNScale dashboard and API.
What you'll learn
- Understand the purpose of TXT records and their role in modern DNS
- Write correct SPF records with proper syntax and mechanisms
- Configure DKIM and DMARC records for email authentication
- Work around the 255-character string limit in DNS TXT records
A TXT (Text) record stores arbitrary text data in DNS. While originally designed for human-readable notes, TXT records are now essential for domain verification, email authentication (SPF, DKIM, DMARC), and various security protocols. They are one of the most versatile DNS record types and you will likely have more TXT records than any other type in a production zone.
How TXT Records Work
TXT records contain free-form text, typically enclosed in quotes:
example.com. 3600 TXT "v=spf1 include:_spf.google.com ~all"Multiple TXT records can exist for the same name, and a single TXT record can contain multiple strings that are concatenated. Unlike A records or CNAME records which have strict format requirements, TXT records accept virtually any text content -- which is both their strength and a source of complexity.
The 255-Character Limit
A critical detail when working with TXT records: each individual string within a TXT record is limited to 255 characters by the DNS protocol (RFC 1035). For records that exceed this limit -- which is common with DKIM keys -- the value must be split into multiple quoted strings:
example.com. 3600 TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A" "MIIBCgKCAQEA2K4PavXoNY8eGK2u..."These multiple strings are automatically concatenated by DNS resolvers. DNScale handles the splitting automatically when you enter long values through the dashboard or API, so you don't need to worry about manually breaking strings at the 255-character boundary.
When using
digto inspect long TXT records, you may see the output broken into multiple quoted strings. This is normal -- the resolver reassembles them into a single value.
Common Use Cases
Domain Verification
Prove domain ownership to third-party services. Services generate a unique token, and you add it as a TXT record. The service then queries your DNS to confirm you control the domain.
# Google Search Console
example.com. 3600 TXT "google-site-verification=abc123..."
# Microsoft 365
example.com. 3600 TXT "MS=ms12345678"
# Let's Encrypt (DNS-01 challenge)
_acme-challenge.example.com. 300 TXT "gfj9Xq...token..."For Let's Encrypt DNS-01 challenges, use a short TTL (300 seconds) since the value changes with each certificate renewal. If you use automated certificate management, the TXT record is created and deleted programmatically. See SSL/TLS Certificates for more on certificate issuance, and consider CAA records to restrict which certificate authorities can issue certificates for your domain.
SPF (Sender Policy Framework)
SPF tells receiving mail servers which servers are authorized to send email on behalf of your domain. It works alongside your MX records to form a complete email setup.
SPF Syntax Breakdown
An SPF record begins with v=spf1 and contains a series of mechanisms:
| Mechanism | Meaning | Example |
|---|---|---|
mx | Allow servers listed in MX records | mx |
a | Allow the domain's A record IP | a |
ip4: | Allow a specific IPv4 address or range | ip4:192.0.2.0/24 |
ip6: | Allow a specific IPv6 address or range | ip6:2001:db8::/32 |
include: | Include another domain's SPF policy | include:_spf.google.com |
all | Catch-all for everything else | -all (fail), ~all (softfail) |
SPF Qualifiers
The qualifier before all determines what happens to non-matching senders:
| Qualifier | Meaning | Recommendation |
|---|---|---|
-all | Hard fail: reject unauthorized senders | Use for production with well-tested SPF |
~all | Soft fail: accept but mark suspicious | Use when initially deploying SPF |
?all | Neutral: no policy | Rarely useful |
+all | Pass all: no restriction | Never use -- defeats the purpose of SPF |
# Allow Google Workspace to send
example.com. 3600 TXT "v=spf1 include:_spf.google.com ~all"
# Allow your own mail server
example.com. 3600 TXT "v=spf1 mx a:mail.example.com -all"
# Multiple includes
example.com. 3600 TXT "v=spf1 include:_spf.google.com include:sendgrid.net ~all"Only one SPF record is allowed per domain name. If you need to authorize multiple email services, combine them into a single record using multiple
include:mechanisms. Having two separate SPF TXT records will cause validation failures. See Email Security: SPF, DKIM, and DMARC for a complete setup guide.
SPF Lookup Limit
SPF has a maximum of 10 DNS lookups per evaluation. Each include:, a, mx, and redirect mechanism counts as one lookup. Nested includes count too. Exceeding this limit causes SPF to return a "permerror" result, which may cause email delivery failures. If you hit this limit, consider replacing include: mechanisms with direct ip4: and ip6: entries where possible.
DKIM (DomainKeys Identified Mail)
DKIM adds a digital signature to outgoing emails. The public key is published as a TXT record at a specific subdomain:
google._domainkey.example.com. 3600 TXT "v=DKIM1; k=rsa; p=MIGfMA0GCS..."
selector1._domainkey.example.com. 3600 TXT "v=DKIM1; k=rsa; p=MIIBIjANBg..."The record name follows the pattern selector._domainkey.yourdomain.com, where the selector is provided by your email service. The p= field contains the public key in base64. Since DKIM keys are often long, the 255-character string limit means these records frequently need to be split across multiple strings.
To verify a DKIM record:
dig TXT google._domainkey.example.com +shortDMARC (Domain-based Message Authentication)
DMARC ties SPF and DKIM together with a policy that tells receiving servers what to do when authentication fails:
_dmarc.example.com. 3600 TXT "v=DMARC1; p=quarantine; rua=mailto:dmarc@example.com"
# Strict policy
_dmarc.example.com. 3600 TXT "v=DMARC1; p=reject; pct=100; rua=mailto:dmarc@example.com"Key DMARC tags:
| Tag | Purpose | Example |
|---|---|---|
p | Policy for failures | none, quarantine, reject |
pct | Percentage of messages to apply policy to | 100 |
rua | Aggregate report destination | mailto:dmarc@example.com |
ruf | Forensic report destination | mailto:dmarc-forensic@example.com |
adkim | DKIM alignment mode | r (relaxed), s (strict) |
aspf | SPF alignment mode | r (relaxed), s (strict) |
Security Policies
BIMI (Brand Indicators for Message Identification):
default._bimi.example.com. 3600 TXT "v=BIMI1; l=https://example.com/logo.svg"MTA-STS (Mail Transfer Agent Strict Transport Security):
_mta-sts.example.com. 3600 TXT "v=STSv1; id=20231107"MTA-STS works alongside TLSA records and SSL/TLS certificates to enforce encrypted email transport.
Custom Application Data
Store any text data needed by your applications:
example.com. 3600 TXT "facebook-domain-verification=abc123"
example.com. 3600 TXT "stripe-verification=xyz789"Record Format
| Field | Description | Example |
|---|---|---|
| Name | Domain or subdomain | @, _dmarc, selector._domainkey |
| Type | Record type | TXT |
| Content | Text value (quoted) | "v=spf1 mx -all" |
| TTL | Time to live (seconds) | 3600 |
Querying TXT Records with dig
# Check all TXT records for a domain
dig TXT example.com
# Get just the values (useful for scripting)
dig TXT example.com +short
# Check SPF specifically
dig TXT example.com +short | grep "v=spf1"
# Check DMARC
dig TXT _dmarc.example.com
# Check DKIM for a specific selector
dig TXT google._domainkey.example.com
# Query authoritative nameserver directly
dig TXT example.com @ns1.dnscale.eu
# Check ACME challenge record
dig TXT _acme-challenge.example.com +shortWhen troubleshooting email delivery issues, always check all three: SPF (
dig TXT example.com), DKIM (dig TXT selector._domainkey.example.com), and DMARC (dig TXT _dmarc.example.com). All three must be correct for reliable delivery.
Adding a TXT Record
Using the Dashboard
- Navigate to your zone in the DNScale dashboard
- Click Add Record
- Configure the record:
- Name: Enter the subdomain or
@for apex - Type: Select
TXT - Value: Enter the text content (quotes optional -- DNScale adds them automatically)
- TTL: Set the cache duration (default: 3600)
- Name: Enter the subdomain or
- Click Create Record
Using the API
Create an SPF record:
curl -X POST "https://api.dnscale.eu/v1/zones/{zone_id}/records" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "@",
"type": "TXT",
"content": "v=spf1 include:_spf.google.com ~all",
"ttl": 3600
}'Create a DMARC record:
curl -X POST "https://api.dnscale.eu/v1/zones/{zone_id}/records" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "_dmarc",
"type": "TXT",
"content": "v=DMARC1; p=quarantine; rua=mailto:dmarc@example.com",
"ttl": 3600
}'Create a domain verification record:
curl -X POST "https://api.dnscale.eu/v1/zones/{zone_id}/records" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "@",
"type": "TXT",
"content": "google-site-verification=abc123xyz...",
"ttl": 3600
}'API Response:
{
"status": "success",
"data": {
"message": "Record created successfully",
"record": {
"id": "encoded-record-id",
"name": "example.com.",
"type": "TXT",
"content": "\"v=spf1 include:_spf.google.com ~all\"",
"ttl": 3600,
"disabled": false
}
}
}Email Authentication Setup Guide
Complete email authentication with SPF, DKIM, and DMARC. For a comprehensive walkthrough, see Email Security: SPF, DKIM, and DMARC.
Step 1: Add SPF Record
example.com. 3600 TXT "v=spf1 include:_spf.google.com ~all"Step 2: Add DKIM Record
google._domainkey.example.com. 3600 TXT "v=DKIM1; k=rsa; p=..."Step 3: Add DMARC Record
_dmarc.example.com. 3600 TXT "v=DMARC1; p=none; rua=mailto:dmarc@example.com"Step 4: Monitor and Tighten
- Start with
p=noneto monitor without affecting delivery - Move to
p=quarantineafter reviewing aggregate reports and confirming legitimate senders pass - Finally use
p=rejectfor full protection
This gradual rollout prevents accidentally blocking legitimate email. Each step should run for at least 2-4 weeks while you monitor DMARC reports.
Troubleshooting TXT Records
SPF validation failing?
- Check you have exactly one SPF record:
dig TXT example.com +short | grep "v=spf1" - Verify you haven't exceeded the 10-lookup limit
- Ensure all
include:targets are valid and resolvable
DKIM not passing?
- Verify the record exists:
dig TXT selector._domainkey.example.com +short - Check for line breaks or extra spaces in the public key
- Confirm the selector matches what your mail server is using in signatures
Verification record not detected?
- Some services check the apex (
@), others check a specific subdomain -- verify the exact name required - Allow time for DNS propagation or flush your cache
- Query the authoritative server directly:
dig TXT example.com @ns1.dnscale.eu
Best Practices
-
Only one SPF record - Multiple SPF records cause delivery issues; combine into one
-
Use proper DMARC progression - Start with
p=none, thenp=quarantine, thenp=reject -
Keep verification records - Don't delete verification TXT records after initial setup -- many services re-check periodically
-
Quote special characters - Ensure quotes around values with spaces or special characters
-
Low TTL for challenges - Use short TTL (300s) for ACME/Let's Encrypt challenges that change frequently
-
Avoid TXT records at CNAME names - A CNAME cannot coexist with TXT records at the same name
Online tools for email authentication testing:
- MXToolbox
- DMARC Analyzer
- Mail-Tester
Related Record Types
- MX - Mail server configuration
- CAA - Certificate authority restrictions
- TLSA - DANE certificate authentication
- A - IP address records referenced in SPF
- AAAA - IPv6 addresses referenced in SPF
- CNAME - Used for DKIM selectors from email providers
- NS - Nameserver delegation
- SRV - Service discovery records
Conclusion
TXT records are versatile workhorses of modern DNS, essential for email security, domain verification, and custom application needs. Proper configuration of SPF, DKIM, and DMARC records is critical for email deliverability and security -- without them, your emails are far more likely to end up in spam folders or be rejected outright. Understanding the 255-character string limit, SPF lookup limits, and the relationship between TXT records and other record types like MX and CNAME helps you build a robust DNS configuration. DNScale makes it easy to manage all your TXT records through the dashboard or API, with automatic string splitting for long values.
Ready to manage your DNS with confidence?
DNScale provides anycast DNS hosting with a global network, real-time analytics, and an easy-to-use API.
Start free