If you are running a system prior to iOS 13.4, read this Apple Support document about what to do "If you forgot the passcode on your iPhone, or your iPhone is disabled". Click here then select your device type if necessary --> http://support.apple.com/HT204306 - Also has links for what to do for an iPad or an iPod touch.
This will erase the device. You can restore your device from a backup but the backup has to date from before you set the forgotten passcode or it too will be restored.
On the contingency you are asked for your Apple ID and password AND you have forgotten those:
If you forgot your Apple ID, click here --> https://support.apple.com/HT201354
If you forgot your Apple ID password, click here --> https://support.apple.com/HT201487
To jump directly to the site to help you recover forgotten account information, click here -->- http://iforgot.apple.com/
What to do after [or before] you change your Apple ID email address or password - https://support.apple.com/HT204071