Restore a Mac to default state
For the OSX factory reset, backup all your data, then restart your Mac and hold down Command + R key. Use Disk Utility to erase the hard drive. Click on Disk Utility > Continue. Select the main volume and click Unmount then Erase. Quit Disk Utility. Click Reinstall OS X and Continue. Follow the instructions to reinstall Mac OS X. 

For IOS, go to Settings/General/Reset and select Erase All Content and Settings