I'll add that it works on a system of delegation.
So there are authoritative servers (which own a part of a domain) which can then have actual records or delegate to other authoritative servers.
So the authoritative server for "com" (yes, as in .com, com is technically a valid domain name) will delegate google.com to a DNS server (likely one owned by Google). And then Google will have DNS records for mail.google.com and so on.
So looking up mail.google.com, technically you ask com DNS for the mail.google.com. It won't have an actual record, but will essentially say "go talk to this DNS server to get google.com records". So your computer asks this new DNS server for mail.google.com and it might have an answer, or it might have delegated the mail.google.com somewhere else.
What your computer most likely is using, however, is a recursive DNS service. You ask it for mail.google.com and it will "walk the tree" to finally return the IP address.
And then it will cache the results (for com google.com and mail.google.com) so the next queries are significantly faster.
I was always proud of the UK government having (a majority of) good online services that are easy to use. And that they were open source.
It's what governments should do. It is providing for their citizens in 2 different ways: accessible services & open source.
It's bullshit that they are drawing back from that