There are organizations that are called registries that manage each TLD option. When you register domain names, you would first visit a domain registrar who would in turn check with the registry that manages that TLD to see if the domain is available. If the domain for the TLD you want discovers that it is in fact available, the registry adds it to their registry and gives you access to it. If the domain has already been registered by another user for that TLD, you will be shown during the domain registration process that the domain isn't available.
DNS is essentially a database of IP addresses. Each IP address is a series of numbers that allow computers to communicate with each other. A website is identified on a server by its IP address. Instead of your visitors having to remember an IP address to type into their browser to access your site, they instead use your domain name. When your domain is entered into their browser, DNS translates it into an IP address because that is what computers understand.Your computer is able to connect to your web hosting and show your website on the browser once the IP address is found.