OS X Recovery is a standard feature of modern Macs. Hold down Cmd+R just before the Apple logo appears when your Mac is booting and you’ll boot into a special repair disk partition that contains a copy of Disk Utility, Time Machine, the OS X installer, and the Terminal app, amongst other things. You can usually fix a system using OS X Recovery one way or another.
The problem is that even OS X Recovery can be inaccessible if your Mac’s hard disk is trashed, for example.
If so, you can turn to Internet Recovery. Put simply, this loads OS X Recovery from Apple’s servers instead of from your hard disk. You can start Internet recovery by holding down Option+Cmd+R just before the Apple logo appears while booting (that’s Alt+Cmd+R on some keyboards). You might be prompted for a Wi-Fi password. Notably, Internet Recovery isn’t compatible with Enterprise Wi-Fi used in corporate environments. Whatever the case, I would certainly consider temporarily attaching the Mac via an Ethernet cable if possible for the best quality network connection.
Not all Macs support Internet Recovery. All modern Macs can, manufactured since around 2012 onwards. If your Mac is from 2011 or 2010 you might need to install a firmware update. Before that date… Well, you’re probably out of luck although you might want to give Option+Cmd+R a try anyway. However, standard OS X Recovery should still work.
Internet Recovery takes around five minutes to load depending on the speed of your Internet connection. Curiously, you’ll boot into the version of OS X Recovery that was current when your Mac was manufactured. For example, on my MacBook Pro 2015 model I booted to Yosemite’s recovery mode, even thought the Mac has El Capitan installed, because I got the Mac just a few months before El Capitan was released.
This also means that if you have to undertake a complete reinstallation of OS X then you might have to use the Mac App Store to update to the current version of OS X.