The hosts file in Windows is like an address book for your computer. It is loaded into memory (cache) when Windows starts and associates host names, such as www.google.com with IP addresses, such as 22.214.171.124 for Google. The IP address is like the telephone number for that site.
However, so we don’t have to remember a string of numbers for every site we want to visit, we enter easy-to-remember host names.Because the computer uses IP addresses to find sites, it needs to translate the host name for a site into an IP address. If the IP address for a site is in your hosts file associated with a host name, your computer can use that to “call” the site when you enter the host name in your browser’s address bar. If not, your computer must contact a DNS (domain name server) computer on the Internet for the IP address before it can contact the site.
Initially, there are no host name/IP address associations in the hosts file. Examples of the format and layout of the IP addresses and host names are listed in the comments in the file.
If you add host names and their associated IP addresses into the hosts file for sites you visit often, access to those sites becomes faster. Your computer doesn’t have to query DNS servers on the Internet to get the IP addresses for those sites. If there are any sites that don’t have a domain name, you can enter the site’s IP address in your hosts file with a custom domain name which can serve as a “shortcut” to the site.
So how can you use a HOSTS file in Windows? Well, websites can collect various types of information about you as you surf the web. The hosts file can help block sites from tracking you, as well as block ads, banners, third-party cookies, and other annoying parts of web pages.Each computer has a host address of its own, known as the “localhost” address. The IP address for localhost is 127.0.0.1. This can be used to block sites serving ads or objectionable content by entering a site’s host name in the hosts file and associating it with the localhost IP address. That refers the host name to your own computer, which then thinks it found the site and displayed it already, even though that site was never actually contacted.
For example, DoubleClick is an ad server that, in some cases, will quietly try to open a separate connection on the current webpage and record your activity on that page as well as follow you to other sites you visit. Adding the following entry to your hosts file, prevents DoubleClick from ever serving you any ads or tracking your activity.127.0.0.1 ad.doubleclick.net
NOTE: The entries in the hosts file allow you only to block entire sites. Therefore, if you are viewing a site, any ads that are served to you by that site, cannot be blocked with the hosts file without blocking the whole site.
Another advantage of blocking ads, banners, hit counters, and other annoying webpage elements is that it can also speed up your browsing experience. You don’t have to wait for all those webpage elements to load before viewing the page.
You can set up the hosts file yourself to block websites or you can download a hosts file that is already filled out with common sites you may want to block. The following image shows a ready-made hosts file created by the MVPS site.
NOTE: You cannot use wildcards for the host names in the hosts file. For example, *.sitehostname.com will not work.
If you decide to edit the hosts file yourself, it is located in the following directory for Windows 7, Vista, and XP. The file does not have an extension, but it is a standard text (.txt) file. An easy way to open it is to open Notepad, or other text editor, first and then open the hosts file from within the editor program.
NOTE: If you choose to download and use a ready-made hosts file, be sure to make a backup copy of the original hosts file, in case you want to use that again. The easiest way to do that is to add an extension to the original hosts file, such as .mvp (for the site from which you downloaded the file) before copying the new hosts file to the directory listed above.
The hosts file is an easy way to restrict undesirable websites from accessing your computer and tracking your web activity without using third-party software and to speed up your browsing experience for sites you visit often.
"windows tips---Your computer Hosts File in Windows and How Can You Use It."
Reference : online-tech-tips.com