The hosts file location in Windows
The hosts file is a plain text file that tells your computer how to translate website names into IP addresses, before it asks the internet. On Windows, it lives in a specific system folder that is hidden by default, which is why many people have trouble finding it.
The file is located at: C:\Windows\System32\drivers\etc\hosts
There is no file extension — it is just called "hosts", not "hosts.txt" or anything else. Windows hides this entire folder from normal browsing, so you cannot find it by clicking through File Explorer the usual way. You have to type the path directly or navigate there using a specific method.
Key Takeaways
- The hosts file sits at C:\Windows\System32\drivers\etc\hosts and has no file extension.
- You can reach it by typing the full path into File Explorer's address bar, or by opening Notepad and using File > Open.
- You must run your text editor as administrator before you can save changes to the hosts file.
- The hosts file uses a simple format: an IP address, a space or tab, then the domain name you want to redirect.
- A single mistake in the hosts file can break your internet connection to that domain, so back up the original before editing.
Opening the hosts file using File Explorer
The fastest way is to paste the path directly into File Explorer. Open File Explorer and click the address bar at the top (where it shows your current folder path). Clear whatever is there and type the full path: C:\Windows\System32\drivers\etc
Press Enter. File Explorer will take you straight to the folder. You will see the hosts file listed there. Double-clicking it will open it in Notepad, which is the correct program for editing it.
If you want to edit the file, do not just double-click and start typing. You need to open Notepad first as administrator, then open the hosts file from inside Notepad. This is explained in the next section.
Opening the hosts file with administrator permission
To make changes to the hosts file, you must run your text editor as administrator. Windows protects this file because a mistake here can break your internet connection to specific websites.
Right-click on Notepad (search for it in the Start menu, or find it in C:\Windows\System32). Select Run as administrator. Click Yes when Windows asks for permission. Once Notepad is open with the administrator badge, go to File > Open. In the dialog box, type the full path: C:\Windows\System32\drivers\etc\hosts and press Enter. The file will open.
If you try to save changes without running as administrator, Windows will block the save and ask you to try again with administrator permission. This is a common mistake — if you see that message, close the file, close Notepad, and start over with the administrator method above.
Understanding the hosts file format
The hosts file is plain text. Each line that does something follows this pattern: an IP address, then a space or tab, then a domain name. For example:
127.0.0.1 localhost ::1 localhost
These two lines are always there by default. The first one tells your computer that "localhost" means your own machine (127.0.0.1 is the loopback address). The second does the same thing for IPv6 (::1).
If you want to block a website or redirect it to a different address, you add a new line in the same format. For example, typing 127.0.0.1 example.com would make your computer treat example.com as if it were your own machine, effectively blocking it. Lines that start with a hash symbol (#) are comments and do nothing — Windows ignores them.
Backing up the original hosts file before editing
Before you make any changes, make a copy of the original file. Navigate to C:\Windows\System32\drivers\etc in File Explorer. Right-click the hosts file and select Copy. Right-click in the same folder and select Paste. Windows will create a copy called "hosts - Copy". Keep this somewhere safe.
If something goes wrong after your edits — for example, you cannot reach a website you need — you can delete the broken version and rename the backup back to "hosts". This takes only a few seconds and saves you from having to restore the file from a system backup.
Common mistakes that break the hosts file
The most common error is a typo in the domain name. If you type 127.0.0.1 exmple.com instead of example.com, the rule will not work, but it will not break anything either. However, if you accidentally edit one of the default localhost lines and introduce a space or character in the wrong place, your computer may have trouble connecting to itself, which can cause strange network problems.
Another mistake is forgetting to use a space or tab between the IP address and the domain name. The file needs that separator to understand where one ends and the other begins. If you type them together with no space, the line will not work.
Do not add extra blank lines or change the capitalization of "localhost" in the default entries. Leave those two lines exactly as they are. Only add new lines below them if you need to redirect or block something.
Restarting after changes to the hosts file
After you save changes to the hosts file, your computer does not always notice right away. Some programs cache the old information. The safest approach is to restart your computer, which clears all caches and forces Windows to read the updated hosts file.
If you do not want to restart, you can try flushing the DNS cache from the command prompt. Open Command Prompt as administrator (right-click, select Run as administrator) and type: ipconfig /flushdns then press Enter. This tells Windows to forget the old address information and read the hosts file again. It works sometimes but not always — a restart is more reliable.
Frequently Asked Questions
What is the hosts file used for?
The hosts file lets your computer translate domain names to IP addresses before asking the internet. It is useful for blocking websites, redirecting domains to test servers, or mapping local network names. It is also commonly used by malware to redirect you to fake websites, which is why you should check it if your browser keeps going to the wrong place.
Can I edit the hosts file on Windows 11 or Windows 10?
Yes, the location and method are the same on all recent Windows versions. The path is always C:\Windows\System32\drivers\etc\hosts, and you always need administrator permission to save changes. The steps in this guide work on Windows 10, Windows 11, and earlier versions.
What happens if I delete the hosts file?
Windows will recreate a default version the next time you restart. The default version contains only the two localhost lines. If you have made custom entries and want to keep them, do not delete the file — instead, restore your backup copy or edit the file to remove only the lines you do not want.
Why can't I save changes to the hosts file?
Windows is blocking you because you did not run your text editor as administrator. Close the file and Notepad, then right-click Notepad and select Run as administrator. Open the hosts file again from inside the administrator Notepad, make your changes, and save. This time it will work.
How do I know if malware has changed my hosts file?
Open the hosts file and look for any lines you did not add yourself. The default file contains only the two localhost lines. If you see extra entries pointing domains to unusual IP addresses, or if websites you trust are being redirected, malware may have modified the file. Delete those extra lines, save the file, and run a full antivirus scan.