Fortunately this is easy, so long as you use the Mac App Store to download the operating system installer. Apple includes suitable installer files in the bundle provided through the App Store. The instructions come from Apple's support website :- https://support.apple.com/en-us/HT201372
First, you run the Mac App Store application and request the installer of your choice -- e.g. as of this writing El Capitan is the preferred choice, so you select El Capitan and wait for it to finish downloading.
DO NOT LET THE INSTALLER RUN ... instead, let the installer download and cancel any window that pops up to cause the installation to occur.
You need a USB Flash Drive that is bootable and can hold 16 GB of data. I believe these conditions are met by all modern thumb drives. You will be completely overwriting the thumb drive, so make sure you've copied any important files off it before doing the following. Anything on that thumb drive will be overwritten. Don't do this to the drive containing the only copies of your childs baby pictures.
Next, open up a Terminal session. The Terminal app is located in Applications / Utilities.
To write the OS X installer to the USB Flash Drive, use the "createinstallmedia" command that is located INSIDE the OS X installer you downloaded. Just use one of the following commands
Path for Sierra
/Applications/Install\ macOS\ Sierra.app/Contents/Resources/createinstallmedia
Path for El Capitan:
/Applications/Install\ OS\ X\ El\ Capitan.app/Contents/Resources/createinstallmedia
Path for Yosemite:
/Applications/Install\ OS\ X\ Yosemite.app/Contents/Resources/createinstallmedia
Path for Mavericks:
/Applications/Install\ OS\ X\ Mavericks.app/Contents/Resources/createinstallmedia
The command must be run as root (using sudo) and requires a couple command-line options. After "--volume" you put the pathname for the Thumb Drive, which you find by running "df". After "--applicationpath" you put the path to the installer.
Example command for macOS Sierra
sudo /Applications/Install\ macOS\ Sierra.app/Contents/Resources/createinstallmedia --volume /Volumes/MyVolume --applicationpath /Applications/Install\ macOS\ Sierra.app
Example command for El Capitan
sudo /Applications/Install\ OS\ X\ El\ Capitan.app/Contents/Resources/createinstallmedia --volume /Volumes/MyVolume --applicationpath /Applications/Install\ OS\ X\ El\ Capitan.app
Example command for Yosemite
sudo /Applications/Install\ OS\ X\ Yosemite.app/Contents/Resources/createinstallmedia --volume /Volumes/MyVolume --applicationpath /Applications/Install\ OS\ X\ Yosemite.app
Example command for Mavericks
sudo /Applications/Install\ OS\ X\ Mavericks.app/Contents/Resources/createinstallmedia --volume /Volumes/MyVolume --applicationpath /Applications/Install\ OS\ X\ Mavericks.app
Finally, when you run this you'll be asked for your password. That's normal, just type in your password and the command will run.