Two-factor authentication adds a second check when you sign in to your Apple ID: something you know (your password) plus something you have (a trusted device or phone number).
Why it matters
If someone learns your password, they still cannot get in without one of your trusted devices. It is the single most effective protection for your account.
Trusted devices and phone numbers
Your iPhone, iPad or Mac can receive verification codes automatically. Keep at least one phone number on file that you can still access.
If you lose access
Start account recovery from the sign-in screen and follow the prompts — Apple explains the wait times there. Write down your recovery key if you created one, and store it somewhere safe and offline.