How to use the spf record generator
- Enter the domains your email services use in the Include field, one per line (for example
_spf.google.com). - Add any direct IPv4 or IPv6 addresses or CIDR ranges that send mail on behalf of your domain.
- Check A or MX if your domain's own A record or MX servers are authorized to send mail.
- Choose an All qualifier.
-all(fail) is recommended for strict enforcement. - Copy the generated SPF TXT record and add it to your domain's DNS. Use an SPF record checker after publishing to verify it.
How SPF syntax works
An SPF record always starts with v=spf1, which identifies the string as a Sender Policy Framework version 1 record. After the version tag come zero or more mechanisms, each optionally preceded by a qualifier character. The four qualifiers are + (pass, the default when omitted), - (fail), ~ (softfail) and ? (neutral).
Mechanisms tell receiving servers which hosts may send mail. ip4 and ip6 specify literal addresses or CIDR ranges. a and mx resolve the domain's A or MX records. include pulls in another domain's SPF policy. The record ends with an all mechanism that catches anything not matched earlier.
For example, v=spf1 include:_spf.google.com ip4:203.0.113.0/24 -all authorizes Google's servers and the 203.0.113.0/24 subnet, rejecting everything else.
The generator checks that each include is a valid domain name and that each IPv4 and IPv6 address or prefix length is well formed before it builds the record. It does not query DNS, so it cannot confirm that an include exists or add up the lookups inside it.
The 10 DNS lookup limit
RFC 7208 mandates that evaluating an SPF record must not require more than 10 DNS lookups. Exceeding this limit causes a permanent error, and receiving servers may reject or ignore your policy entirely. This is the most common mistake administrators make when building an SPF record.
The mechanisms that trigger DNS lookups are include, a, mx, ptr, exists and the redirect modifier. Crucially, an include does not count as just one lookup: the included domain's own SPF record is evaluated recursively, and every mechanism inside it that requires resolution adds to your total. The ip4 and ip6 mechanisms never cause lookups because they contain literal addresses.
This SPF record generator tracks lookups from the top-level mechanisms you enter. If you nest deep includes, you should manually audit the chain to ensure the combined total stays at or below 10.
Common mechanisms reference
| Mechanism | DNS lookups | Description |
|---|---|---|
ip4:x.x.x.x | 0 | Matches a specific IPv4 address or CIDR range. |
ip6:x:x::x | 0 | Matches a specific IPv6 address or CIDR range. |
a | 1 | Matches the IP address of the domain's A record. |
mx | 1 | Matches the IP addresses of the domain's MX records. |
include:domain | 1 + nested | Evaluates the target domain's SPF record. |
all | 0 | Matches any sender; used with a qualifier at the end. |
Choosing the right all qualifier
The all mechanism at the end of your record defines what happens to mail that does not match any preceding mechanism. Three options cover nearly every real deployment:
-all(hard fail): Tells receivers to reject unauthorized mail outright. This is the strongest stance and is recommended once you have verified all legitimate sources.~all(soft fail): Tells receivers to accept the mail but flag it as suspicious. Useful during initial rollout while you monitor reports.?all(neutral): Makes no assertion. Receivers treat the message as if no SPF record existed. Rarely appropriate for production domains.
Avoid using +all (pass). It authorizes the entire internet to send mail as your domain, completely defeating the purpose of SPF.
SPF alongside DKIM and DMARC
SPF alone does not fully protect your domain from spoofing. It validates the envelope sender (the Return-Path address), but the visible From header can still be forged. That is why SPF is designed to work together with DKIM and DMARC.
DKIM adds a cryptographic signature to the message headers, proving the content was not altered in transit. You can generate the necessary DNS entries with a DKIM record generator. DMARC ties both protocols together by telling receivers what to do when SPF or DKIM checks fail, and it provides reporting so you can monitor abuse. Use a DMARC record generator to publish a DMARC policy once your SPF and DKIM records are in place.
Together these three standards form the foundation of modern email authentication. Publishing all three significantly reduces the chance that attackers can impersonate your domain.
Worked examples
| Example | Input | Result |
|---|---|---|
| Google Workspace only | Include domains (one per line): _spf.google.com; Include A mechanism: no; Include MX mechanism: no; All qualifier: -all | SPF TXT Record: v=spf1 include:_spf.google.com -all; DNS Lookups: 1 |
| Microsoft 365 with custom server | Include domains (one per line): spf.protection.outlook.com; IPv4 addresses or CIDR blocks (one per line): 203.0.113.50; Include A mechanism: no; Include MX mechanism: yes; All qualifier: ~all | SPF TXT Record: v=spf1 mx include:spf.protection.outlook.com ip4:203.0.113.50 ~all; DNS Lookups: 2 |
| Multiple providers | Include domains (one per line): _spf.google.com / sendgrid.net / mail.zendesk.com; IPv4 addresses or CIDR blocks (one per line): 192.0.2.0/24; IPv6 addresses or CIDR blocks (one per line): 2001:db8::/32; Include A mechanism: yes; Include MX mechanism: yes; All qualifier: -all | SPF TXT Record: v=spf1 a mx include:_spf.google.com include:sendgrid.net include:mail.zendesk.com ip4:192.0.2.0/24 ip6:2001:db8::/32 -all; DNS Lookups: 5 |
FAQ
What is an SPF record?
An SPF record is a DNS TXT entry that lists the mail servers authorized to send email on behalf of your domain. Receiving servers check it to detect forged sender addresses.
Why is there a 10 DNS lookup limit?
RFC 7208 sets a maximum of 10 DNS lookups during SPF evaluation to prevent excessive load on DNS infrastructure. Exceeding this limit causes a permanent error, and your SPF policy will not be enforced correctly.
Should I use -all or ~all?
Use ~all (soft fail) while you are setting up and monitoring your mail flow. Once you are confident that all legitimate sources are listed, switch to -all (hard fail) to instruct receivers to reject unauthorized mail.
Can I have multiple SPF records for one domain?
No. RFC 7208 states that a domain must have exactly one SPF record. Multiple records cause a permanent error. Combine all your authorized sources into a single record using this SPF record generator.
Do ip4 and ip6 mechanisms count toward the lookup limit?
No. Because they contain literal IP addresses or CIDR ranges, they require no DNS resolution and do not count toward the 10-lookup limit.
Is my data sent to a server when I use this tool?
No. This SPF record generator runs entirely in your browser. Nothing you type is uploaded anywhere.