If you forget your iPhone passcode, restore the device to factory default settings via iTunes, or erase the system data via the iCloud feature. After you reset the device, restore personal files from a backup if you created one earlier. If these options fail, access the recovery mode. Once the recovery process is complete, set up a new passcode.
To regain access to your iPhone via iTunes, connect it to a computer with which the device is synchronized, and start iTunes. Once iTunes completes the synchronization and backup processes, click on the Restore iPhone button, and select the Restore From iTunes Backup option. Select your iPhone from the list, and select the most recent backup file.
To restore the device via iCloud, log in with your Apple ID on iCloud.com, click on the All Devices button, and select your iPhone. Click on the Erase iPhone button, and restore the personal files from an iCloud backup. The downside of this option is that it only works if your iPhone has access to a wireless or cellular network. To use the recovery mode, connect your iPhone to a computer, start iTunes, press the Sleep and Wake buttons at the same time, and hold them until the recovery mode screen appears. Select the Restore option, wait for iTunes to download the necessary software, and set up your iPhone again.