The Windows hosts file is located at C:\Windows\System32\drivers\etc\hosts on every modern Windows version, from Windows XP through Windows 11. It is a plain-text file with no file extension, and it sits inside a protected system directory. You can open it in Notepad after launching the editor as administrator, or reach it through the Run dialog by pasting the full path.

That answer covers the default case. The rest of this explainer covers why that path exists, what happens inside Windows when a program looks up a name, which conditions silently bypass the file, and how to edit it without breaking anything. It also covers the popular claims about the hosts file that do not survive contact with how the resolver actually works.

The Resolution Pipeline That Gives the Hosts File Its Power

Windows resolves a hostname through a layered stack, and the hosts file sits near the top. The first stop is usually the DNS Client service, also called dnscache, which answers from an in-memory cache. A cache hit never reaches the hosts file, because the answer is already known. A cache miss falls through to the next layer.

The next layer reads the Name Resolution Policy Table, a registry-backed ruleset that can redirect or encrypt queries for specific namespaces. Group Policy, DNSSEC requirements, and DirectAccess settings populate it. Only after the policy table clears a query does the resolver consult the hosts file. This ordering matters because it explains a common confusion: a hosts entry can appear ignored when a policy rule or a cached answer is intercepting the lookup first.

If the hosts file holds a matching entry, the resolver returns that address and stops. No DNS packet leaves the machine. If the file has no match, the resolver queries DNS servers in the order listed in the adapter settings, with a timeout of roughly one second per server before failing over to the next.

The file itself follows a simple grammar. Each line pairs an IP address with one or more hostnames, separated by whitespace. The hash character starts a comment that runs to the end of the line. A default Windows installation ships the file with everything commented out, so it changes nothing until you edit it.

One counterintuitive detail: the hosts file maps names to addresses but does nothing for the reverse direction. A reverse lookup, which asks what name belongs to an IP address, goes to DNS. Programs that log hostnames from connection addresses will not see your hosts entries.

A Short History of the Path and Why It Still Exists

The location traces back to the Windows NT architecture, which placed drivers and low-level configuration under System32 to keep them separated from user-writable folders. The hosts file inherited the home that the earlier HOSTS file occupied on Unix-derived and early TCP/IP stacks, and Microsoft kept the name in uppercase on older systems to match convention.

The System32 path serves a security purpose. Standard user accounts cannot write to that folder without elevation, so malware cannot casually rewrite name resolution for the whole machine. That protection is partial, which is why the file remains a favorite persistence trick, but it raises the bar above a plain user-profile location.

A second copy exists on 64-bit Windows. The SysWOW64 folder holds a 32-bit view of System32, and a file placed at C:\Windows\SysWOW64\drivers\etc\hosts is not the file that 64-bit applications read. Most users never touch this path, and editing only the System32 copy is correct for normal use.

On Windows for ARM and on Windows Server, the path is identical. The architecture changes; the directory layout does not.

How the Resolver Reads and Caches the File

The DNS Client service loads the hosts file into memory at startup and monitors it for changes. When the file's modification time changes, the service reloads it, typically within a second or two. That is why edits usually take effect without a reboot, though flushing the DNS cache with ipconfig /flushdns is the reliable way to force a clean slate.

The reload behavior has a subtle limit. Some applications perform their own name resolution and keep their own caches, so they may hold a stale answer after your edit. Browsers are the classic example, and many of them maintain internal DNS caches that survive a system flush. Closing and reopening the browser clears those.

Entries in the hosts file do not expire. Unlike a DNS record with a time-to-live, a hosts mapping persists until you remove the line or the file is replaced. That permanence is the feature and the hazard: a forgotten entry can silently redirect traffic for months.

The file has a practical size ceiling that is far above any normal use. A few hundred entries load instantly. Tens of thousands of entries, as some ad-blocking lists attempt, can slow startup of the resolver and are better handled by a dedicated filtering tool or a DNS-based blocklist.

Layer What it consults Typical latency added Can it override the hosts file
Application cache Browser or app memory Near zero Yes, until the app restarts
DNS Client cache (dnscache) In-memory answers Under 1 ms Yes, until flushed
Name Resolution Policy Table Registry rules Under 1 ms Yes, by design
Hosts file Flat text in System32 Under 1 ms It is the override
Local DNS servers Network query 1 to 50 ms No, it loses to hosts
Public DNS resolvers Network query 10 to 100 ms No, it loses to hosts

The table shows the hierarchy at a glance. An entry in the hosts file beats any DNS server, but it loses to a cached answer and to policy rules. Professionals diagnosing a stubborn redirect check the upper rows first.

The Edge Cases That Break the Simple Answer

Path virtualization is the first trap. A 32-bit application running on 64-bit Windows may see C:\Windows\System32 transparently redirected to SysWOW64 through the file system redirector. An installer or script that writes to the System32 path from a 32-bit context can therefore produce a file in the wrong place. Verify the real path with a 64-bit editor or by checking both directories.

Permissions are the second trap. Even an administrator account does not write to System32 by default, because User Account Control strips the elevated token from a normally launched process. Notepad must be started with the Run as administrator option, or the save will fail with an access-denied error. A read-only attribute left over from a security tool produces the same symptom.

File extension hiding causes the third trap. If Notepad saves the file as hosts.txt, Windows may display it as simply hosts while hiding the .txt extension. The resolver reads only the extensionless file, so the edit appears to do nothing. Confirm the true name by enabling file name extensions in File Explorer.

Encoding matters less than it used to, but it still bites. Modern Notepad saves as UTF-8 by default, and the resolver tolerates UTF-8 and ANSI. Older or specialty editors may add a byte-order mark that some tools dislike, or may save as UTF-16, which renders the file unreadable to the resolver. Save as UTF-8 without a BOM when in doubt.

A hosts entry also cannot express a port. Lines map a name to an address only, so you cannot redirect example.com to 127.0.0.1:8080 with this file. That limitation surprises people trying to test a local web server on a nonstandard port.

The file has no extension, and a hidden .txt extension is the most common cause of a silent failure. Standard accounts cannot write to System32; launch the editor elevated. A 32-bit tool may write to SysWOW64 instead of System32 through path redirection. Browser-internal DNS caches survive a system flush; restart the browser. A stale entry has no expiry, so audit the file after any temporary redirect. The hosts file accepts only IPv4 and IPv6 addresses with names, never ports or URLs.

Misconceptions Worth Retiring

The most persistent myth is that the hosts file is a firewall or a security boundary. It is neither. It redirects names, and a program that connects by raw IP address ignores it completely. Malware that hardcodes an IP is unaffected, and a hosts entry is trivially bypassed by a DNS-over-HTTPS client or a VPN with its own resolver.

A close second is the belief that the hosts file can block ads completely. It can block names that resolve to known ad servers, but modern ads and trackers share domains with content delivery networks and first-party endpoints. Blocking those names can break legitimate parts of a site, and many apps ship their own resolvers that skip the file. A hosts-based blocklist is a blunt instrument, not a complete filter.

People also expect the hosts file to handle wildcards. It does not. Each line names specific hosts, and there is no syntax for a pattern like *.example.com. Every subdomain you want to redirect needs its own entry or its own line with the name spelled out.

The final misconception is that editing the hosts file requires a reboot. It does not, because the DNS Client service watches the file. A flush is usually enough, and a browser restart handles internal caches.

Step-by-Step Editing and Verification

Open the Run dialog with Windows key plus R and type the full path to the etc folder. Alternatively, paste %SystemRoot%\System32\drivers\etc into File Explorer's address bar. Locate the extensionless hosts file.

Right-click Notepad in the Start menu and choose Run as administrator. Then use File, Open, and browse to the hosts file, setting the file type filter to All Files so the extensionless file appears. Opening through the editor after elevation is more reliable than dragging a file onto a shortcut.

Add your entries at the end of the file, one mapping per line, with the IP address first and the hostname second. Comment each line with a hash and a short note describing its purpose and date, so future audits are fast. Save the file and close the editor.

Flush the resolver with ipconfig /flushdns from an elevated command prompt. Then test with ping or nslookup. Ping resolves the name through the standard stack, while nslookup queries DNS directly and will not show your hosts entries. That difference is itself a useful diagnostic: if ping shows the new address and nslookup does not, the hosts file is working as intended.

For a temporary block, map the name to 0.0.0.0, the unspecified address, which fails fast on most systems. Mapping to 127.0.0.1 points the name at the local machine, which only changes behavior if something is listening there. The two choices behave differently, and 0.0.0.0 is the more common blocking convention.

To revert, delete the added lines or restore the original file from a backup. Windows does not keep a version history of the hosts file, so make a copy before your first edit on any machine you care about.

What the File Cannot Do and When to Reach for Something Else

The hosts file is per-machine and per-user-profile in effect. It has no mechanism for pushing entries to other devices on the network, and it cannot be centrally managed without Group Policy or a configuration management tool. For a fleet of computers, a DNS server or a policy-driven resolver is the right layer.

It also cannot encrypt anything. An entry that redirects a familiar name to a local address does nothing for the transport, and if the destination expects HTTPS the certificate check will simply fail for the wrong host. The file changes where a name points, not how the connection is protected.

Services that bypass system resolution remain outside its reach. DNS-over-HTTPS in browsers, built-in resolvers in some applications, and VPN clients with split-DNS logic may never consult the file. If a redirect works in a browser but not in a desktop app, the app is likely using its own resolver.

Tool Scope Wildcards Encryption Best for
Hosts file One machine No No Local testing, single-machine redirects
Local DNS server Network Yes Optional Home lab and small office control
DNS filtering service Network Yes Yes Managed multi-device filtering
Group Policy DNS client rules Domain Yes Depends Enterprise name resolution policy
Browser DoH setting One browser N/A Yes Encrypted browser lookups

The table makes the trade-off clear. The hosts file wins on simplicity and loses on reach, wildcard support, and encryption. Reach for it when the job is one machine and one name, and reach for a resolver when the job is anything larger.

The Bottom Line

The hosts file lives at C:\Windows\System32\drivers\etc\hosts and acts as a per-machine override that outranks DNS but loses to caches and policy. Editing it needs administrator rights, a watchful eye on hidden extensions, and a flush afterward. It is a precise local tool, not a firewall, and treating it as one is the main source of disappointment.

A short timeline helps set expectations for what happens after an edit.

Time after save What happens What to check
Under 1 second DNS Client service detects the file change Nothing; the reload is automatic
1 to 2 seconds New entries are active for new lookups Run ping against the hostname
Immediately after flush Stale cached answers are discarded ipconfig /flushdns output
Browser restart Internal app caches clear Retest in a fresh window
Days to months Entries persist with no expiry Audit commented lines periodically
After a Windows upgrade The file is usually preserved Confirm the file still exists

This is general educational information, not a diagnosis, treatment plan, legal opinion, or investment recommendation. It does not promise any outcome or return. For issues involving system security or regulated data, consult a qualified local IT or security professional, and for immediate danger contact local emergency services.