DNS queries are a bit different. Since it is the first requirement that must be resolved before being able to show a web page. If you are going to give a phone call to your mom, you must first know which is her phone number right?
There are many DNS records, but the important ones for a simple DNS query are A and AAAA records. These records hold the final IP address to where you want to connect to. A is for IPv4 addresses and AAAA is for IPv6 addresses. Yes, as you might have predicted A stands for Address and the repeated As are, well, longer addresses. Why? this is topic for another post.
When DNS query is sent you can ask either for A, AAAA or other records, but if you don’t specify it then an A record will be considered the default.
So far, it has been a really summarized understanding. But finding the answer for a query is not that simple. It requires several other queries to several DNS servers to finally get the final answer. It is like asking for a phone number of a someone you know but still haven’t given you their number? How can you find out the phone number? You need to ask someone that you think might know, and if that person doesn’t then he/she might lead you to someone who knows. In the end, a definitive source would be asking a central authority who must know (phone book).
In DNS the central authority is IANA (Internet Assigned Names Authority) and it offers a free to use phonebook or database we can query to via the DNS protocol on a fixed set of servers called root servers (13 root servers all over the world). Don’t worry these are not just 13 physical servers, but 13 organizations in charge of maintaining them operational all the time.
When your device ask a DNS query it will ask it’s local cache first in case it already asked before, but if it is the first time then it will need to ask one root server which are fixed widely known IPs (IANA-list). Then the DNS recursive resolution happens as follows:
1- We ask root A on IP 198.41.0.4, our DNS query would be what is the A record for http://www.test.com. , to which the root server replies “I don’t know, but I know someone who knows” and that is the .com. authority which turns out to be 192.33.14.30
2- Now we go and ask them the same question. This server will say I don’t know, but I know someone who knows which is test.com. authority and their IP is 204.12.76.1
3- Finally we know who the authority of test.com is, they for sure will know what is the IP for http://www.test.com, then we do one last query and we get the correct IP address for http://www.test.com which is 67.225.146.248.

This looks like so much trouble right? But, it happens so fast that we barely notice, it takes usually just a few milliseconds.
Would you like to know more? There are more servers in between playing vital roles so that we can always get faster responses to the DNS queries, otherwise surfing the internet would be slower than it is today. Check the following posts with more information.
What are DNS recursive servers?
What is an authoritative DNS server?
One thought on “How does a DNS query work?”