To set up a website, you will need two things: web hosting and domain name. These two are more of a package deal, and it is quite hard to differentiate these two, but they are two different things.
The domain name can be compared to the entries of a phone book. Computers use these entries (domain name) to communicate with each other, and these are called IP addresses. Just like how the phone book allows to you to contact or reach out to a person. The domain tells computers that a particular domain is hosted on a specific server. The web-hosting or server portion can be compared to space we rent to have our business. Web-Hosting is just space, and it does not account to include a site for you to sell your services or products; to say in simple terms, a domain name is the address of your business, and space which your business occupies is called as web-hosting.
You get to claim the rights to your site’s name when you register a domain, and nobody will be able to access to your website’s name in that particular domain, other than you.
If you have a domain, it does not mean that you can provide your site to the rest of the world. To run and put your site up, you will need a web server which is appropriately configured and a proper domain.
Web hosting refers to the web server which stores all the data files. The web host providers rents out network connection and web servers for the end users. The web hosting providers will handle most server maintenance work like root configuration, backup, disaster recoveries, maintenance, etc. But there are some cases where the end users need to do all the maintenance work.
Only when you have web hosting, you will have a place to keep your files, and thus your domain will be like a phone which is disconnected.
You will need web hosting and domain name to put your site online. When you get both these elements from the same provider, it makes your registration process very easy. When you have the same provider, you can start working on your site at the earliest. If you happen to get the web hosting and the domain name from two different companies, then you need to transfer your domain name from the register of your web host. It is more like asking the phone company to change your number of the phone to your new location. The changing process is called as changing the DNS.
So if a person visits the site that you have put up, the server will send files to that user and they will be able to see the webpage.