Every time you upgrade an iOS device to a new version of the operating system, there's a brief window in which you can easily roll it back (just in case you come across a bug or two).
You really are limited in terms of timing on this one: Apple devices will only install software that's been "signed off" by Apple, and once there's a new version of iOS, older ones get marked as invalid within a few days (or weeks if you're lucky). The process of jumping back must be done while the older version is still authorised.
Before you the downgrading process, make sure everything on your device is backed up somewhere — save games, photos, music and anything else you want to keep. The downgrade and restore process wipes your iPhone or iPad clean and forces you to start again. As far as official iOS backups go (in iTunes and iCloud) you're going to have to go back to the last saved state for the iOS version that you're downgrading to, so if you've saved any photos or other files since then, they need to be handled separately.
To downgrade iOS you need the older IPSW (iPhone or iPad software) file. This may be on your computer if you upgraded through iTunes and your desktop OS hasn't cleared it away as a junk file. On OS X look in ~/Library/iTunes and in Windows 10 navigate through Users\<User>\AppData\Roaming\Apple Computer\iTunes folder. You're looking for a folder called iPhone Software Updates or iPad Software Updates.
If you can't find the older IPSW (.ipsw) file on your local system, there are plenty of repositories on the web where you can download archived files for free, such as IPSW Downloads. Choose your device, select the iOS version you want to go back to, and download the file. IPSW Downloads helpfully marks the packages currently signed as valid by Apple in green.
Fire up iTunes and connect your iOS device. Open the device's page inside iTunes and you get the familiar Restore screen. Rather than just clicking the Restore button as normal, use Option+Click (OS X) or Shift+Click (Windows), which prompts you to choose an IPSW file rather than just using the most recent one from Apple. Pick the file you downloaded earlier and the reset and restore process starts.
Downgrading from a beta version
Getting off a beta version back to an older, stable version is relatively straightforward, but bear in mind that iOS backups saved while running the beta software will no longer work. If you're running beta software, before you connect your iOS device to your computer, turn it off then press and hold the Home button. Keep the button pressed until the Connect to iTunes message appears on screen.
You should see an alert on screen saying there's "a problem" with your device and you can then click Restore to start the process. This time you don't have to pick an IPSW file as iTunes simply uses the most recent stable release of iOS direct from Apple. After a few minutes you'll have a factory-fresh device ready to go again.
That's all there is to it. It's an easy process once you know how, but the limitations put in place by Apple (and with good reason) mean you're restricted in terms of when you can downgrade. It's usually only possible right after a new version of iOS has been pushed out into the wild, so we advise you act fast.