9 OTP Best Practices for Code Length, Expiry & Resend Limits

Illustration of a smartphone with a six-digit OTP and a green check, beside a stopwatch, a resend arrow and a message bubble

If you’re implementing OTP verification in your application, you’ll need to decide the code length, expiration time, how often users can request a new code, and how many incorrect attempts to allow.

These decisions affect both your application’s security and how easily users can complete verification.

For example, if your OTPs expire too quickly, users on slower networks may receive their codes with little time left to enter them. Similarly, letting users request new codes too often can lead to unnecessary messaging costs and confusion about which code to use.

In this guide, we’ll cover nine OTP best practices, including our recommendations for code length, expiration times, resend limits, and message templates, along with ways to improve delivery reliability and reduce verification costs.

1. Choose the Right OTP Length

For most applications, we recommend using a six-digit numeric OTP for account registration, login, and phone number verification.

Shorter codes are easier to remember and type, but they also have fewer possible combinations, making them easier to guess.

Longer codes provide more combinations but can increase the likelihood of users making mistakes when entering them manually.

OTP lengthPossible combinations
4 digits10,000
5 digits100,000
6 digits1,000,000
7 digits10,000,000
8 digits100,000,000

The National Institute of Standards and Technology (NIST) also recommends at least six decimal digits, or an equivalent level of complexity, for out-of-band authentication codes.

You can also use alphanumeric OTPs, which offer more possible combinations for the same code length.

However, users can easily confuse similar-looking characters, such as the letter O and the number 0, especially when switching between messaging and authentication screens.

For applications where most users complete verification on mobile devices, numeric OTPs also allow you to display a numeric keypad, making it easier for users to enter their codes manually.

2. Set an Appropriate OTP Expiration Time

For most applications, we recommend setting an OTP expiration time of 3 to 5 minutes. This gives users enough time to receive and enter their codes while limiting how long an unused code remains valid.

However, the appropriate expiration time also depends on what users are verifying and how quickly you can deliver their codes.

For example, you may want a shorter validity period for sensitive actions such as authorizing a financial transaction than for verifying a phone number during account registration.

You should also consider delivery times across the countries and messaging channels you support. If your OTPs expire after 60 seconds and an SMS takes 40 seconds to arrive, users have only 20 seconds left to enter their codes before requesting another one.

If you notice a high percentage of OTPs expiring in a particular market, review your delivery times for that market before increasing the expiration period. Switching to a more reliable delivery channel or setting up automatic fallback may help resolve the underlying issue.

Regardless of the expiration time you choose, each OTP should become invalid immediately after successful verification.

3. Limit Failed OTP Verification Attempts

We recommend allowing users three to five incorrect attempts before invalidating an OTP and requiring them to request a new one.

This gives users a reasonable chance to correct typing mistakes while reducing the risk of repeated guessing of verification codes.

However, limiting incorrect attempts for each individual OTP is only part of the process. If users can request a new code every time they reach the attempt limit, they can keep guessing.

To prevent this, you should also limit the total number of failed verification attempts associated with an account or phone number within a given period. Requesting a new OTP shouldn’t reset this limit.

Once users reach the limit, temporarily restrict further verification attempts and let them know when they can try again.

4. Set OTP Resend Limits and Cooldown Periods

If users don’t receive their OTP within a few seconds, they may request another one while the original message is still on its way. This can increase your messaging costs and cause confusion if multiple codes arrive at different times.

We recommend waiting at least 30 seconds before allowing users to request another OTP and gradually increasing the waiting period with each subsequent request.

For example, you could configure your resend intervals as follows.

Resend requestWaiting period
First resend30 seconds
Second resend60 seconds
Third resend120 seconds

You should also display a countdown next to the resend button so users know when they can request another code.

Another consideration is whether to resend the same OTP or generate a new one. Resending the same code within its original validity period can help prevent confusion when messages arrive out of order.

If you generate a new OTP with each request, invalidate the previous code immediately and let users know they should enter the most recently requested code.

Regardless of which approach you choose, limit the total number of OTP requests a user can make within a given period to prevent abuse and control messaging costs.

5. Write Clear and Concise OTP Messages

Your OTP message should make it easy for users to identify who sent the code, what it’s for, and how long they have to use it.

We recommend placing the verification code near the beginning of the message so users can easily find it in their notification preview without opening the messaging app.

Here are a few OTP message templates you can adapt for different verification purposes.

PurposeMessage template
Account registration482913 is your [Brand] verification code to complete your registration. It expires in 5 minutes. Do not share this code with anyone.
Account login482913 is your [Brand] login code. It expires in 5 minutes. Never share this code with anyone.
Password reset482913 is your [Brand] password reset code. It expires in 5 minutes. If you didn’t request this, ignore this message.
Payment verification482913 is your [Brand] verification code for a payment of [Amount] to [Merchant]. It expires in 3 minutes. Do not share this code.

If you’re sending OTPs via SMS, keep your messages short enough to fit within a single SMS segment whenever possible. Longer messages may be split into multiple segments, each of which your provider may charge you for separately.

You should also consider the template requirements of each messaging channel. For example, WhatsApp requires businesses to use approved authentication templates with predefined wording and options to include an expiration notice and security warning.

If your application serves users across multiple countries, localize your OTP messages so users can understand the purpose of the verification request in their preferred language.

6. Make It Easy for Users to Enter Their OTPs

Users should be able to complete verification without having to switch back and forth between your application and their messaging app to remember or enter their codes.

One of the easiest ways to simplify this process is to support OTP autofill, which lets users enter verification codes directly from incoming messages on supported devices.

Also allow users to copy and paste the entire code, even if your verification screen has separate input fields for each digit.

A few other ways can improve the verification experience:

  • Display a partially masked phone number so users can confirm where you sent the code.
  • Allow users to correct an incorrectly entered phone number without restarting the registration process.
  • Display a numeric keypad for numeric OTPs.
  • Let users know whether the code they entered is incorrect or has expired.
  • Provide an alternative delivery channel if users don’t receive their code.

For example, if a user enters an expired OTP, display a message such as “Your verification code has expired. Request a new code to continue” to give them a clear next step without having to figure out why verification failed.

7. Set Up Automatic Fallback Across Delivery Channels

If your application relies on a single messaging channel to deliver OTPs, any delays or service interruptions affecting that channel can prevent users from completing verification, even if they request another code.

With automatic fallback, you can deliver the OTP through another available channel when the initial delivery fails or remains unconfirmed within a specified period.

For example, if you send an OTP through WhatsApp and don’t receive delivery confirmation within your configured waiting period, you can automatically send the code via SMS without requiring the user to request it again.

When setting up fallback, consider the delivery rates, costs, and availability of each messaging channel in the countries you serve. A channel that offers reliable, low-cost delivery in one market may be more expensive or less widely used in another.

At SecondFactor.ai, we automatically select the lowest-cost eligible channel for each verification request across WhatsApp, SMS, Viber, and RCS.

If delivery isn’t confirmed, we automatically fall back to another eligible channel, so your team doesn’t have to build and maintain separate routing and fallback logic for each market.

8. Generate, Store, and Validate OTPs Securely

If you’re managing OTP generation and verification in your own application, use a cryptographically secure random number generator to ensure that each code is unpredictable.

Also avoid storing OTPs in plain text or including them in application logs, analytics platforms, and error reports where employees or third-party services may access them.

When validating an OTP, make sure the code is associated with the correct user and the specific action they requested. For example, a code issued to verify a phone number during registration shouldn’t be accepted to authorize a payment or reset a password.

All verification checks should happen on your server, including code validity, expiration, and failed attempts.

If you’re using a managed OTP verification service, check which of these responsibilities your provider handles and which security controls your team still needs to implement within your application.

9. Monitor OTP Delivery and Verification Performance

A high OTP delivery rate doesn’t necessarily mean users are successfully completing verification. Your provider may report a message as delivered even if the code arrives too late for the user to enter it.

We recommend tracking the following metrics to identify where users experience difficulties and where you may be incurring unnecessary messaging costs.

MetricWhat it tells you
OTP delivery rateThe percentage of OTP messages successfully delivered.
Verification completion rateThe percentage of verification requests that users successfully complete.
Time to verificationHow long users take to complete verification after requesting a code.
Resend rateHow often users request additional codes.
OTP expiration rateHow often codes expire before successful verification.
Fallback rateHow often you need another channel to deliver an OTP.
Cost per successful verificationHow much you spend on delivery and verification fees for each successfully verified request.

If your application serves users across multiple countries, break down these metrics by destination, delivery channel, and provider.

For example, if you notice a higher resend rate and longer verification times for SMS in a particular country, compare those results with WhatsApp or other available channels in the same market.

You can then adjust your routing preferences, fallback intervals, or expiration settings based on where users are experiencing difficulties and how much each successful verification costs.

Simplify OTP Verification With SecondFactor.ai

Managing OTP generation, expiration, resend limits, message templates, and delivery across multiple channels can require significant development and ongoing maintenance, especially as your application expands into new markets.

With SecondFactor.ai, you can send and verify OTPs across SMS, WhatsApp, Viber, and RCS through a single API integration.

We automatically select the lowest-cost eligible channel for each verification request and fall back to another available channel when delivery isn’t confirmed.

You can also manage your message templates and review delivery logs, verification statuses, and costs from a single dashboard to identify opportunities to improve delivery reliability and reduce verification expenses.

Get started with SecondFactor.ai to simplify OTP verification for your application.