If you are giving away your mac at the momment and not keeping it, follow this method here.
Backing up your Mac and your files:
You can use the native app called Time Machine(already installed on every mac, no matter what) to back up every single thing on your Mac to a disk you choose(can be to an external hard drive or usb) and restore to that backup when you update or you can exclude certain files to not backup in Time Machine, but backup everything else. To figure out how, click here.
I would recommend updating to macOS Sierra first before doing the following steps, but it is fine to upgrade after.
"Factory resetting your Mac"
Make sure everything has been backed properly. Go into the apple menu and click on restart. This next text has been copied and pasted from this article here.
"During the restart process, before moving onto the login screen, your computer will show a gray slate screen. This is your opportunity to go behind the scenes: Hold down both the Command key and the R key when you see gray. This should pop you over to the MacOS Utilities, where you can make various important and potentially dangerous changes. Select Disk Utility from the window. Now, this process is going to be a little different based on what version of MacOS you are using, but you will want to look for your startup disk or other startup-related information. Select it and then click on the Erase tab. Next, head over to the Format option and set it to Mac OS Extended (Journaled). Again select Erase. This may take some time. Once finished, go to the Disk Utility menu and select Quit Disk Utility."
You should be at a screen similar to this(depends on your mac version): For this next step you must have your Mac connected to the internet otherwise it won't work. You need an internet connection for this step because this is where your Mac pulls a new copy of macOS from Apple's servers.
"Once you have quit out of Disk Utility, you should see an option to Reinstall your current MacOS. Select that reinstall option, confirm that you really want to do it, and proceed. You may have to click through a few confirmations before the installation is ready to begin."
After this, your Mac is as good as new. If you haven't already updated to macOS Sierra, set up your Mac as if it was new, then update.