How can I download an older version of OS X/macOS?
Some of this answer is getting a little dated now, as it's been periodically updated over several years.
It might be simpler to first check Apple's own page on How to get old versions of macOS (which didn't exist until relatively recently), &amp; come back here if you still have issues.
One thing that still applies throughout is - you need a Mac to get macOS easily &amp; legitimately.

If you are trying to jump a long way - say from 10.8 to 10.14 or later, received wisdom is to first upgrade to El Capitan 10.11, then High Sierra 10.13.
This will prepare your machine for the long jump.
Some users seem to have managed to miss out El Capitan, but High Sierra still seems necessary.

Since Mojave
[This section is still work in progress]
It would appear that in the new Mojave App Store, older purchased OS Installers no longer appear at all, so the 'simple method' of grabbing it from your purchase history is no longer valid.
Sierra, High Sierra &amp; Mojave are available via direct links - see below.
Testing the El Capitan installer which has a published URL it will appear in the App Store, but if requested to download no longer says 'not valid for this Mac' it now says 'The requested version of macOS is not available'.

Some further testing is required - contributions welcome - to see if other OS versions are similarly removed. We may need direct links for these, which I don't have at present.
Additional note:-
I've attempted from VMs of older OSes to recreate the App Store as it used to be in El Capitan &amp; High Sierra, to see if I could still access the old 'purchase history'.. with no success. The history appears as it used to, but I have been unable to access any older versions through it.
It seems you actually need a physical Mac running those older OSes to be able to reach back for those older versions.

For macOS versions since Sierra.
Sierra itself has now vanished from everybody's Purchase History. However, Apple are keeping Sierra fully available, even though High Sierra is out. No Apple ID is required.
Apparently, you must use Safari to access these links, otherwise it doesn't correctly redirect to the App Store.

Sierra - Direct download link from the App Store
High Sierra - Direct download link from the App Store
Mojave - Direct download link from the App Store
Catalina - Direct download link from the App Store
Big Sur - Direct download link from the App Store

High Sierra link tested from Mojave Jan 2019 - still works to download, though it does it via the new Software Update control panel. It won't run on a Mojave Mac but you have the installer in your Apps folder to move elsewhere

For OS X versions from Lion up to El Capitan.
I successfully re-tested this method Jan 2019 - still working as stated for a Mac limited to El Capitan. Purchased older OSes are still listed &amp; accessible
The simplest way - if available to you - is to use your Purchase History on the App Store.
If you have ever previously installed any OS X version, it will still be available to you from that list. This should include any public beta versions too.
The version available from that list will always be the latest version of its type - i.e. 10.7.5, 10.8.6... 10.11.6
Image heavily modified to show only OS versions.

Note, it will say Download or Install depending on whether or not you have the Installer file saved locally - even on a non-boot drive.

If the version you are trying to download is older than the Mac you are attempting to download it to - the Store will not allow the download.
[looking for workarounds to this part - edits welcome - I can't test this as the newest Mac I have is a 2012 Mac Pro]
Potential workarounds, need testing -
How to re-download Lion from Mountain Lion

For older Macs
If you are trying to update an older machine running Snow Leopard or Lion, then you can get a special version of El Capitan from the App Store

This version of El Capitan is for users running OS X Snow Leopard or
OS X Lion who would like to upgrade to macOS High Sierra. If you are
running Snow Leopard or Lion and would like to upgrade to High Sierra,
you need to install El Capitan first. This version of El Capitan can
also be installed on computers that are not compatible with High
Sierra.

Note that last sentence... this version will not install on any machine that is not currently on Snow Leopard or Lion, if the machine is capable of running High Sierra.
That leaves it as quite a specific resource &amp; not a general 'get out of jail free card' for anyone wanting El Capitan.


Recovery Options
If you need to reinstall from Recovery, &amp; were previously running Sierra 10.12.4 or higher, there are now 3 options available.
Hold the appropriate key combo at the boot chimes...

 Cmd ⌘  R
reinstall the latest macOS that was installed on your Mac, without upgrading to a later version
 Opt ⌥   Cmd ⌘  R
upgrade to the latest macOS that is compatible with your Mac
 Shift ⇧   Opt ⌥   Cmd ⌘  R
reinstall the macOS that came with your Mac, or the version nearest to it that is still available.

The first 2 options are available to any Mac newer than Lion, approximately 2009.

Should you have access to an older point release of any OS, 10.11.0 etc &amp; wish to upgrade, then you can download Combo Updaters from Apple that contain everything necessary to go straight to the latest point release in a single step, e.g. 10.11.6
Google is good at finding these, as the top hit if you just search combo update 10.11 etc but here are links to a few
Mavericks 10.9.5
Yosemite 10.10.5
El Capitan 10.11.6
Sierra 10.12.6
High Sierra 10.13.6

If you need to create a bootable USB to install from
How do I create El Capitan installer on a Catalina (or post-El Capitan) installed Mac for use on USB boot installer
How do I make a bootable USB OS X installer on a Mac?
How do I create a Mac bootable USB drive using Windows?

If none of these methods are available to you, you have two options

Find a friend who can access the download [recommended]

Find a torrent/sharing site [not recommended]


Additional Note:
There is no 'legitimate' way to download macOS from anything other than a Mac. It requires the Apple App store.

Note: You can not use a Time Machine backup to revert to an OS which is older than the OS of the latest backup on that Time Machine drive.
This means that to preserve your ability to ever restore to an earlier backup &amp; OS with your Time Machine backup, you must swap out that Time Machine drive before upgrading the OS. This is because once the Time Machine drive sees the new OS, there's no going back to the older OS using it. You can still pick data out from the Time Machine manually, but cannot use it to restore to the older OS.

I've moved this section to the bottom, just to keep for historical purposes.
This certificate issue should now be resolved.
NEWS
October 2019
Because of the certificate issue Apple faced, which overnight obsoleted all the previous macOS installers, they have re-released several of these, with new certificates.
Apple KB - If an installer says it can't be verified or was signed with a certificate that has expired
This contains links to further KBs for each of the 6 most recent OSes from Catalina back to Yosemite.
The three newer ones link to the App Store, but Sierra, El Capitan &amp; Yosemite link to direct downloads.
Caution: Use Safari if your browser doesn’t open the Mac App Store links in the App Store app. iTunes and Music and iBooks and other apps can’t download these installers - they will say item not available, often quoting your country store by name.
Note for those of us who like to keep all these for 'just in case'.
Download them one at a time &amp; label them correctly before downloading another, so you know which is which. They are not identifiable from the dmg or installer name as to which OS they are :\
Worse… even when you run it, you get absolutely no indication of which OS it is going to install. Be careful.
The following would probably still apply if you were trying to access something older than Yosemite…
General Note
This task seems to be getting harder as time passes. A new wrinkle is that a lot of these older installers, even if you can get hold of them, have an 'expiry date'. The last widespread expiration date for many Mac installers was October 24, 2019 so you will need to re-download your installers after that date to keep them valid and signed.
If you see a message such as
“This copy of the Install OS X El Capitan application can’t be verified. It may have been corrupted or tampered with during downloading”,
or a more vague “An error occurred while preparing the installation. Try running again”
A new error seems to be…
No packages were eligible for install.
Try setting your clock to a date within a year of the OS's initial release date if you absolutely cannot re-download them.
From Michael Tsai's blog - Installing Old Versions of macOS

It seems that the installer is signed with a certificate that has
expired. When booted from the installer, you can open Terminal and use
the date command to set the clock to the past, i.e. to when that
version of macOS was current. After installing, be sure to set the
clock to the correct date, or various other things won’t work
properly.