This article is free to read. Creating a lesson uses your daily or stored credits; review the language and settings before starting.
How does an OTP work?
Quick answer
An OTP is a one-time password: a short code that works for a single login or transaction. An authenticator app and the server share a secret key, then each combines it with the current time or a counter to produce the same code. You type it in, the server checks it, and the code expires immediately after use.
An OTP works by generating a short numeric or alphanumeric code that is valid for only one login or transaction, so a stolen password alone cannot be reused. Authenticator apps and tokens derive the same code as the server from a shared secret plus the time or a counter; SMS codes are simply generated by the server and texted.
Step by step
- During setup, the service and your device share a secret key, often stored in an authenticator app or hardware token; SMS codes are instead generated by the server and texted.
- When you request a login, the device uses that secret plus the current time or a counter to compute a code.
- The server runs the same calculation independently and expects the same result.
- You receive the code by SMS, app, or hardware token and enter it on the login screen.
- The server compares your entry with its own calculation, allowing a small time drift, and grants access if they match.
- The code is then discarded, so it cannot be used again even if someone copied it.
Key things to understand
- A shared secret key is stored on the server and in the user's authenticator app or hardware token during setup.
- The device combines that secret with the current time or a counter using a one-way algorithm.
- The server performs the same calculation independently to produce the expected code.
- The user types the code, and the server checks whether it matches within a short window.
- Because the code changes each time, an intercepted OTP becomes useless after it expires or is used.
Labelled diagram
- Shared secret
A unique key is stored on both the server and the user's device during setup.
- Time or counter
The device and server agree on the current time or an incrementing number.
- Algorithm
A one-way function combines secret and time to produce a short code.
- User enters code
The code is sent by SMS or shown in an app, then typed into the login form.
- Server verifies
The server computes its own code and checks for a match within a small window.
Real-world examples
- A bank sends a six-digit code by SMS when you add a new payee to your online account.
- Google Authenticator generates a fresh six-digit code every 30 seconds for logging into email.
- A UPI payment app asks for an OTP to confirm a transfer above a set limit.
- A hardware token like a YubiKey produces a code when you press its button to log into a corporate network.
Common mistake
✗ Myth: An OTP is just a second password that stays the same every time.
✓ Fact: An OTP changes with every login or transaction and expires quickly, so it cannot be reused. A static second password would offer far less protection because it could be stolen once and used repeatedly.
People also ask
What does OTP stand for?
How long does an OTP last?
Why do banks send OTP on mobile?
What happens if someone steals my OTP?
Why do OTPs expire so quickly?
Is an OTP the same as two-factor authentication?
Can OTPs be intercepted?
Part of the guide: How the Internet Works →

