You can't retrieve an iPhone's forgotten passcode — Apple doesn't store or display it, so no genuine recovery tool or service can hand it back. What you can do is regain access: reset the lock screen passcode (iOS 17 and later), reset the whole iPhone on-device, or restore it with a computer, then set a new code. Which route is available depends on your iOS version, whether Find My was enabled, the network state, and whether the "Forgot Passcode?" button appears. Also settle which code you've actually lost: the device passcode, an iCloud security code tied to older two-factor setups, or the Apple Account password. Each has a different recovery path.
The rest of this guide walks through each case in a workable order, explains what happens behind the scenes when you reset, and covers the failure points that send people to a computer, a carrier, or Apple support.
First, identify which "security code" you're missing
People use the same phrase for at least three different things, and the fix changes completely depending on which one is stuck. Read the screen carefully before you erase anything.
The device passcode. This is the six-digit (or custom alphanumeric) code you type to unlock the iPhone. If you've forgotten it, the Lock Screen eventually shows a "[Device] Unavailable" or Security Lockout message after repeated wrong entries. Apple has no way to tell you the old passcode — the secure enclave stores it in a form designed to be unrecoverable. You must reset and set a new one.
The iCloud Security Code. This is a distinct, older mechanism. At a time when Apple introduced two-factor authentication, some accounts used a four-digit iCloud Security Code to approve iCloud Keychain on a new device. Enter it incorrectly too many times and iCloud Keychain is disabled on that device and the keychain in iCloud is deleted; Apple's guidance is to approve the device from another device that uses iCloud Keychain or reset the keychain. This is not the lock screen passcode and resetting your iPhone won't fix it.
The Apple Account password. This protects your Apple Account (the email-and-password login used for iCloud, the App Store, Find My, and activation). If you've forgotten this, you can't complete most device resets, because the on-device reset asks for it to sign out. Recovery goes through Apple's account recovery flow, which may involve a trusted device, a trusted phone number, or a waiting period.
Once you know which one is missing, the sequence below is ordered from least destructive to most.
Before you reset: three checks that can save your data
A passcode reset is not a small step. Every sanctioned method ends with the iPhone erased, and your data comes back only if a backup exists. Spend five minutes confirming these three things.
1: Confirm a backup exists. Check iCloud backup status from a second device signed into the same Apple Account (Settings > [your name] > iCloud > Manage Account Storage > Backups) or from iCloud.com, or confirm a recent computer backup. If you have no backup, expect a blank setup — contacts and photos stored only on the phone are gone. 2: Confirm Find My was on. Apple's on-device erase options require Find My to have been enabled. If it was off, the "Forgot Passcode?" button won't appear and you'll need a computer. 3: Gather credentials and connectivity. You need the Apple Account password and an active cellular or Wi-Fi connection for the on-device route. If the phone is offline, reconnect it before starting, or go straight to the computer method.
If any of these checks fails, jump to the relevant section rather than tapping through the Lock Screen hoping for a different result.
Try Passcode Reset first (iOS 17 and later)
Apple's own support flow puts Passcode Reset at the top of the list for forgotten passcodes, and it's the least disruptive route because the company frames it separately from a full erase. The idea: on newer iOS versions, when you're locked out, the Lock Screen can walk you through confirming your Apple Account and setting a new passcode.
In practice, on iOS 17 or later you'll see a Forgot Passcode? option on the Lock Screen once you've triggered the "[Device] Unavailable" state and the phone is connected to cellular or Wi-Fi and signed into your Apple Account with Find My on. Tap it and follow the on-screen prompts to verify your account and establish a new passcode. The precise screens vary by version and region, so follow what the phone shows rather than a fixed script.
If the option appears and completes, you're done — no restore needed. If it doesn't appear, don't keep guessing at the Lock Screen; move to the on-device reset below, which for the erase flow requires the same Find My and network conditions anyway.
A quick success check: after setting the new passcode, lock and unlock the phone once to confirm it accepts the code. If the phone still reports "Unavailable," the account verification step didn't fully complete — start the process again from the Lock Screen rather than entering random codes.
Reset the iPhone on the device without a computer
This is Apple's documented no-computer method for iOS 15.2 and later, and it permanently deletes data and settings. Use it only after a backup check, because nothing here is reversible.
Prerequisites: iOS 15.2 or later (this article's reference date, November 2026, means current iOS releases comfortably exceed that), Find My previously enabled, an active cellular or Wi-Fi connection, and your Apple Account password.
1: From the Lock Screen, enter wrong passcodes until the "[Device] Unavailable" screen appears. 2: Tap Forgot Passcode? — this only appears with an active network connection and Find My on. 3: On the Security Lockout screen, tap Start [Device] Reset to confirm. 4: Enter your Apple Account password to sign out of your Apple Account on the device. 5: Tap Erase [Device] to permanently delete all data and settings. 6: When the phone restarts, follow setup, restore from a backup if you have one, and set a new passcode.
One modern wrinkle: on iOS 17 and later, if you use an eSIM, the erase step lets you choose whether to keep the eSIM and erase data, or delete the eSIM and erase data. Keeping it avoids a trip to your carrier. On iOS 16 or earlier with an eSIM, Apple says to contact your carrier before resetting and ask for a QR code so you can reinstall the eSIM afterward — plan for that extra call.
How to check success: setup asks you to create a new passcode, and the phone reaches the Home Screen. If you never see the "Forgot Passcode?" or "Erase [Device]" options, the Find My or network prerequisite wasn't met, so switch to the computer method.
Reset with a Mac or Windows PC when the on-device route fails
If the Lock Screen never offers the reset options, or the phone won't cooperate, Apple's fallback is a computer restore. The requirements are modest: a Mac or Windows PC, a cable that can charge the phone, an internet connection, and roughly up to 60 minutes.
1: Put the iPhone into recovery mode using the button sequence for your model (Apple publishes separate sequences for Face ID and Home-button iPhones). This is the step people get wrong most often — the timing is specific. 2: Connect the phone to the computer and open Finder (macOS Catalina and later) or the Apple Devices app on Windows. 3: When the computer detects a phone in recovery mode, choose the restore option. This downloads and installs fresh iOS software and erases the device. 4: After the restore, set up the phone and restore from your iCloud or computer backup, then create a new passcode.
The same data warning applies: this erases the phone. And note the activation step — a fully erased iPhone still needs your Apple Account credentials to get past Activation Lock if Find My was on, which is why account access matters more than the old passcode.
A troubleshooting distinction worth keeping straight: if the computer doesn't detect the phone, that's a cable, port, or recovery-mode-timing problem — redo the button sequence and try a known-good cable. If the computer detects the phone but the restore fails partway, that's usually a network or storage issue on the computer side. Neither symptom means the passcode is recoverable; both point to retrying the reset, not hunting for a code.
When the blocker is the Apple Account password, not the passcode
Many failed resets stall at step 4 above, when the phone asks for the Apple Account password to sign out. If you don't know it, the fix is account recovery, which Apple handles through iforgot.apple.com and its account recovery process. That flow may ask you to confirm from a trusted device, verify a trusted phone number, or wait a period of days before regaining access — the wait is a security feature, not a bug.
Only after account access is restored can you complete the on-device erase or the computer restore. Don't waste time trying passcode workarounds when the real missing credential is the account password; the phone will keep asking for it.
Once you're back in, change the Apple Account password to something you'll remember and confirm your trusted phone number and recovery contacts are current — that's what makes the next lockout recoverable.
What cannot be recovered, and the traps to avoid
Several things people try simply don't work, and some are actively risky:
Third-party "passcode recovery" tools and services. Apple doesn't expose the passcode for retrieval, so software that claims to "show" your old code is either doing a standard erase-and-restore (which you can do yourself for free) or misrepresenting what it does. Paying for it doesn't change the underlying cryptography. Repeated guessing to "find" the code. Each wrong entry pushes the lockout timer longer. There's no hidden counter that reveals the code, and on devices configured to erase after ten failed attempts, guessing can wipe the phone for you. Expecting the old passcode to be reused. A reset gives you a new passcode; the old one is gone permanently. Your backups and apps return, but the code does not. The iCloud Security Code trap. If your actual blocked screen references iCloud Keychain and a security code entered too many times, resetting the iPhone is the wrong response. Follow Apple's iCloud Keychain guidance — approve from another device or reset iCloud Keychain — and expect the keychain to have been cleared if the limit was hit.
There's also a regional and version dimension worth flagging: Apple's support pages exist in country-specific versions, and some functions "may not be available in this country." If a button described here doesn't appear, check the Apple Support page for your region and your exact iOS version rather than assuming the instructions are wrong.
Reducing the damage next time
The passcode itself can't be recovered, so the practical goal is making the reset survivable. A few habits do most of the work: keep iCloud Backup or regular computer backups current so a restore returns your data; enable Find My, since both on-device reset routes depend on it; keep your Apple Account password in a password manager and your trusted phone number up to date; and consider a longer alphanumeric passcode you're less likely to forget rather than a short numeric one you type dozens of times a day. If you share a device with family, set up the appropriate account structure so one person's forgotten code doesn't lock out everyone's data.
None of this gets the old code back — nothing does. It just turns a lockout from a data-loss event into an inconvenience you can undo in under an hour with the right cable and credentials.