DNS Caching and Time to Live
Understand how DNS caches work, what a time to live controls and how to pick values that keep changes predictable.
Key takeaways
- A TTL is a maximum reuse time in seconds, counted from the moment a particular cache fetched the record.
- Different caches fetch at different times, so a change appears gradually across users.
- Lowering a TTL only helps after the old, longer value has had time to expire everywhere.
- "Name does not exist" answers are cached too, with a duration taken from the zone's SOA record.
Every DNS record carries a time to live, or TTL: the number of seconds a cache may reuse the answer before asking again. A TTL of 3600 means an hour. While the copy is fresh, resolvers answer from memory and never contact the domain's own servers.
That single number sets your trade-off. A long TTL means fewer queries, faster answers and more cushion if your DNS provider has trouble. A short TTL means changes take effect sooner. You choose it per record, and you can change it ahead of events that need it.
Where copies live
A DNS answer can be remembered in several places between the authoritative server and your screen.
Large public resolvers are really many servers, often with separate caches in each location. Two queries to the same resolver address can show different remaining times simply because different machines answered.
How the countdown works
When a resolver fetches a record with a TTL of 300, it stores it with a timer. Someone who asks 100 seconds later gets the record with a TTL of 200. At zero, the copy is discarded, and the next question triggers a fresh fetch.
You can watch this with dig on macOS or Linux. Run the same query twice, a few seconds apart:
dig www.example.com A +noall +answer The second column is the remaining TTL. From a resolver it falls between runs. If you query the domain's authoritative server directly with @, it shows the full configured value every time.
On Windows, ipconfig /displaydns lists the local cache with a time-to-live line for each entry.
Why "propagation" is the wrong picture
People often say a DNS change is "propagating", as though the new value is traveling outward. Nothing is pushed. Your authoritative servers have the new record almost at once, and every cache elsewhere keeps its old copy until its own timer ends.
That is why one person sees the new site while a colleague sees the old one. Their resolvers fetched the record at different moments. The longest anyone should wait is roughly the old TTL, counted from the time of your change. The nuances are covered in DNS propagation.
There are reasons the wait can run longer:
- Some resolvers or devices enforce a minimum TTL, stretching very short values.
- Some applications resolve a name once at startup and keep the address until restarted.
- Long-lived connections stay attached to the old server regardless of DNS.
- A change to name servers at the registrar depends on the parent zone's TTL, which you do not control and which is often a day or two.
Choosing a TTL
There is no single correct value. Match it to how often the record changes and how fast you need to react.
| Situation | Reasonable range | Why |
|---|---|---|
| Stable records such as MX and TXT | 1 to 24 hours | Rarely change; caching helps |
| Typical web records | 5 minutes to 1 hour | Balance of agility and load |
| Records used for failover | 30 seconds to 5 minutes | Clients should move quickly |
| Just before a planned move | 1 to 5 minutes | Shortens the overlap |
Very short TTLs mean more queries to your authoritative servers, which can matter if your DNS host charges by volume. They also leave less cushion: if your DNS provider has an outage, short-lived copies vanish from caches quickly.
Some resolvers can deliberately serve an expired record when the authoritative servers cannot be reached, on the view that a slightly stale answer beats none. This behavior is standardized as "serve stale", but you cannot count on every resolver doing it.
Planning a change
The classic mistake is lowering the TTL at the same moment as making the change. Caches that fetched the record earlier are still holding the long TTL. The lower value only takes effect once they come back for a fresh copy.
For a move from one address to another, with a current TTL of 24 hours:
- At least 24 hours before the move, lower the TTL to 300 and leave the address unchanged.
- Confirm the authoritative servers show the new TTL.
- At the move, change the address.
- Keep the old server running well past five minutes, and watch its logs until traffic stops.
- Once you are confident, raise the TTL back.
The DNS TTL change planner helps lay out those times, and lowering TTL before a cutover covers the sequence in detail.
Negative caching
Resolvers also remember failures. If a name does not exist, or exists without the record type requested, the resolver caches that fact so it does not keep asking.
The duration comes from the zone's SOA record: resolvers use the smaller of the SOA record's own TTL and its final field, often called "minimum". See NS and SOA records for the layout.
This produces a familiar trap. You test new.example.com before creating it, get "not found", then create the record. Your resolver may keep reporting that the name does not exist until the negative entry expires. Create records before you test them, or query the authoritative server directly.
A worked example
Say your website's A record points to 192.0.2.10 with a TTL of 3600, and you change it to 198.51.100.25 at noon without any preparation.
- A resolver that fetched the record at 11:10 holds the old address until 12:10.
- A resolver that fetched it at 11:55 holds the old address until 12:55.
- A resolver that had nothing cached gets the new address from its first query after noon.
So for most of an hour, both servers receive visitors, and the share shifts steadily toward the new one. Shortly after 13:00, well-behaved caches have all moved. A few stragglers may keep arriving at the old machine because of software that ignores TTLs or holds addresses in memory.
The practical lesson is to keep the old server serving correct content during the overlap. If it also accepts orders, comments or mail, decide how that data reaches the new system, since some of it will land in the old place.
What a TTL cannot control
TTLs govern DNS answers and nothing else. Several things that feel like DNS caching are separate.
Web caching. Your browser and any content delivery network keep copies of pages and files according to HTTP headers. A site can resolve to the right server and still show an old page. See browser caching and cache-control headers.
Open connections. A browser or app that already has a connection to the old address may keep using it. DNS is consulted when a new connection is made.
Preloaded settings. Some applications have addresses typed directly into their configuration, or listed in a hosts file. No TTL touches those.
Domain-level changes. Changing which name servers your domain uses is recorded in the parent zone. The parent's TTL applies, and resolvers may also still hold the old provider's own NS records. Plan to keep both DNS providers answering correctly for a few days.
Checking before you blame the cache
When someone reports an old result, confirm three things in order. First, ask the authoritative server directly and make sure it returns the new value. Second, ask the resolver that person uses and note the remaining TTL. If the remaining time is shorter than the old TTL and counting down, waiting will solve it. Third, if the resolver already shows the new value, the stale copy is closer to home: the operating system, the browser, a router or a hosts entry. Using nslookup and dig shows how to aim a query at a particular server.
Flushing caches
You can empty the caches you control.
# Windows
ipconfig /flushdns # macOS
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
# Linux with systemd-resolved
sudo resolvectl flush-caches Browsers may need a restart, and a router forwarder may need its own reboot. You cannot flush strangers' caches. Some large public resolvers offer a web page for requesting a purge of a specific name, which helps their users only. Step-by-step instructions are in how to flush your DNS cache.
Common questions
Can I set the TTL to zero?
The standards permit it, meaning "do not reuse". In practice some software ignores zero or imposes its own floor, and your servers receive far more queries. Many DNS hosts will not accept it.
Does a lower TTL make my site faster?
No. It tends to make lookups slightly slower for visitors, since more of them miss the cache. The benefit is agility when you change things.
Why does one record in an answer expire before another?
Each record set has its own TTL. In an alias chain, the CNAME and the final address are cached separately, so a short-lived target can change while the alias stays cached. The full path is described in what happens during a DNS lookup.