This updated method works for Windows 7, Windows 8.1, and Windows 10 as of May 2019.
Microsoft has made clean retail ISOs of Windows significantly more difficult, but not impossible, to get directly from their servers in recent years. As of 2019, it appears that the easiest way to download older versions of Windows is to use this utility, which allows you to generate download links for almost any version of Windows or Office released in the last decade. (Note that you still need a product key to activate any of these downloads, and all of the files are served directly from Microsoft servers (they just made them really hard to get to without external tools like this utility or the script given above by Ramhound), so this shouldn't be considered piracy in any way.)
It does open an extra window at launch with an ad, but it's simply a single AdSense banner in an iframe that's used to pay for keeping the download links up to date and is relatively harmless.
To download Windows 7, first select "Windows 7" in the sidebar. This will open another page allowing you to select the edition you want.
Choose the edition you want, and another prompt will pop up allowing you to choose language. If the language you want is grayed out, then Microsoft has temporarily disabled those links, in which case you need to switch over to the "Windows 7 (August 2018)" option and use it instead. Once one of the two options lets you select the combination of language and architecture you want, click the "Copy link for 64 bit" or "Copy link for 32 bit" in the right sidebar. Then paste that into your choice of browser or download manager (you'll notice that it is in fact on a microsoft.com domain, these are not rehosted) and download the resulting ISO.
Now that you have it downloaded, you probably want to validate that it is a real Microsoft-issued image. Luckily, you can do that easily with this web tool which contains the SHA-1 hashes for every single file offered up to MSDN subscribers, which includes almost all Windows images.
Simply grab the SHA-1 hash of the ISO you just downloaded (if you don't have a way to do that, 7-Zip includes a tool to do so) and paste it into the search bar and your desired Windows edition should be listed.
Note that I did say almost all Windows images; Microsoft doesn't offer certain OEM images and for whatever reason Windows 7 Home Basic to MSDN subscribers, so those hashes are not included in the database. Thus, if you want those images, you'll have to either trust the supplied link or download/verify the files a different way.
Moral of the story: Microsoft really wants you to upgrade to Windows 10.
Here is the same question for Windows 8: http://superuser.com/questions/493766/where-can-i-download-windows-8-legally-from-microsoft
– Wilf – 2015-02-17T22:22:32.643What happened to all the links :/ – Wilf – 2015-12-13T12:44:32.663
1contact Microsoft they usually will resolve it or send you a disk out – Englishman – 2016-09-08T10:34:09.337
I wasted a day trying out Windows 10 and now that I want to go back to Windows 7 I am wasting hours chasing links. It seems that Microsoft has made sure to take down all the links. And yes it's OEM, of course. This is the last Window machine that I buy. For my next laptop I'll make sure that it 100% supports Linux or buy Mac if I can afford throwing away money. – Rolf – 2018-04-10T13:17:06.947
8A word of warning though: I used the official ISOs from Microsoft and reinstalled, using the same identical product key and CD key, but it refused to activate. I tought this was simply a case for a robocall to Microsoft, but it turns out this computer (Dell Latitude) is banned from free Microsoft support, and I can not get it to display a phone number to call, that option is simply not there. I then called Dell, but they claim they can not activate windows unless it is installed with an original DELL media. I get an error pointing to the BIOS: 0xC004F063. Apparently there is an certificate on – sandos – 2013-10-21T07:07:06.157
3[Apparently there is an certificate on] the OEM media which together with a BIOS table make activation possible. Without the correct media and BIOS it will not work. (From the answer that was converted in the above comment.) – Arjan – 2014-03-08T18:26:21.813
Latitude is from Dell's business line, not consumer line, so they probably require some sort of business-level type support agreement. – LawrenceC – 2014-06-18T14:30:50.263