DNS is, to most people, magic that makes the internet easier to use. When you want to go to a website, you type "mywebsite.com" and not "22.214.171.124" because unless you're a savant or have a thing for memorising numbers, you'll never be able to remember more than one or two websites, if that.
It's the thing that says:
mysite.com lives at 126.96.36.199
www.mysite.com lives at 188.8.131.52
mail.mysite.com lives at 184.108.40.206
Send my mail to mail.mysite.com
This is a word you'll hear from your domain registrar or hosting provider on occasion but very few people know what it actually means, worse is that many use lamen's terms to describe it quite wrongly. It isn't "the amount of time it takes for the new things to travel through the internet" nor is it "how long it takes for it to go through all the other providers like a tree".
DNS records use something called a TTL which stands for "Time to Live". Basically how long the record should be remembered
for. Normally this is 24 hours (you may see the figure 86400 which is 24 hours in seconds).
"So can't I just clear my browser cache and see the new site?" - Nope. Your browser doesn't cache the DNS (usually anyway). It caches the actual web pages and content. Your computer may cache the DNS too but this isn't common anymore and generally it's not long enough to matter.
The usual problematic link in the chain is actually your Internet Service Provider - assuming you're an every day Joe (or Jane) Bloggs who's browsing the internet on their home computer.
"Can I do anything about this?" - Not after the fact if you're using your ISP's DNS resolvers (which, again unless you have a special office setup, you will be) BUT
you can avoid this problem yourself if you plan ahead...
To test that a DNS change has gone through (whilst not being able to use your own internet because of it still showing the old cached result) you can try several things, for example using a friend or colleagues internet connection (if they are with a different ISP - someone sat next to you in the office will not be of any use) or even using your mobile phone, just make sure you're not using WiFi on your phone else you'll just be using your own normal internet connection and see the same thing!
The reason for this is that it is your ISP who has cached these DNS records, so if you use a different ISP, they'll perform a fresh lookup and get the new results.
There are two ways to plan ahead. One method only affects you, the other will help everyone, you can do both if you wish.
The first is actually pretty simple, if you remember the earlier comment that DNS records are normally kept for 24 hours, this should trigger a thought - "If I don't visit the domain in the 24 hours prior to the change, will there be no cached record?" - Correct. Of course your ISP will cache the record if someone else goes to the site, but if this is a small site you own (or even a much larger site, you'd be surprised) then this will still work. So simply - don't visit your website before changing the DNS
- simple principle. If you've not been to it, it won't be cached.
Having visited the site 12 hours before changing the DNS would mean that, in a worst case scenario, you would only have to wait 12 hours for that old record to expire.
The second method requires making some changes to your DNS records, before you want to change the DNS records. Something people don't often realise is that the TTL can be changed, great! BUT, the TTL itself, is subject to the previous TTL. So if you want to lower the TTL from 24 hours to say, 30 minutes, it'll take 24 hours for the new 30 minute TTL to propagate. Fun. But this provides you with the benefit that anyone that visited your site before you changed the DNS will only have to wait a maximum of 30 minutes for the old record to expire.
But remember, you need to lower the TTL in advance of changing the actual DNS records
by at least whatever the previous TTL was. I'll give you a minute to wrap your head around that. So if the TTL is currently 24 hours, you need to lower the TTL at least 24 hours before making the real change.
But why does mysite.com work and www.mysite.com doesn't? (or vice versa)
This is because every DNS record is it's own, single entity. This means that even though one record has been cached, others may not have, likewise if one has expired, the others may not have yet. Each DNS record has it's own ticking clock
that needs to expire before you'll see any changes.
So in summary, changes to existing records take time to propagate, depending on what the TTL was. You cannot speed this up without planning some time in advance.
All the above information applies to regular Joe Bloggs who doesn't know DNS from his elbow. There are ways around some issues stated above but it requires access to your own DNS resolvers and other technical knowledge which is generally far beyond what most people will ever dabble in.
Some ISPs override the TTL that DNS records have set and store records for however long they want. This may be longer (or shorter) than the TTL you have set. This is rare, but it's worth keeping in mind.
Never set the TTL too low
(i.e. one minute) as it will drive you mad. Every time you try using your website you'll get delays and see messages such as "Resolving mysite.com..." and this will continue to happen every time the DNS record expires.