When you need to reinstall macOS on a computer, how you’ll go about it depends on which version of the software you’d like to use. As Apple points out in this support document, there are several key combos you can hold down when you’re starting up your machine to tell the Mac what to install. The basic shortcut, Command-R, will use whatever was already on your computer. But here are the other choices:
Option-Command-R: If you start up your Mac while holding these keys, selecting “Reinstall macOS” within macOS Recovery will allow you to upgrade your Mac to the latest compatible version.
Shift-Option-Command-R (for Macs upgraded to 10.12.4 and later) or Option-Command-R (for all other Macs): Installs the version of macOS that came with your computer or the closest available version.
For example, my computer is an early 2015 MacBook Pro running 10.13.3, and when I hold down Shift-Option-Command-R at startup and pick “Reinstall macOS” afterward, the machine offers to install Yosemite for me.
Obviously, this would be most useful if you were intending to just install the operating system before selling your computer; you can’t put Yosemite, say, over an existing High Sierra install (or any version that came later than Yosemite) without erasing the Mac’s drive first. Oh, and if you are wiping your Mac for sale, be aware of something else Apple says in the article I linked above:
If you’re selling or giving away a Mac that is using OS X El Capitan or earlier, use Command-R to make sure that the installation isn’t associated with your Apple ID.
Handy tip there, guys!
Apple actually has an entire article on what to do before selling or giving away your Mac as well, so if that’s your situation, go and read it. Twice, maybe. Especially the section on backups. I’d suggest reading that one until your eyes bleed.