Article · Wikipedia archive · Last revised May 28, 2026

Time-based one-time password

Time-based one-time password (TOTP) is a computer algorithm that generates a one-time password (OTP) using the current time as a source of uniqueness. As an extension of the HMAC-based one-time password (HOTP) algorithm, it has been adopted as Internet Engineering Task Force (IETF) standard RFC 6238.

Last revised
May 28, 2026
Read time
≈ 3 min
Length
785 w
Citations
6
Source
2fa by 979, showing time-based one-time passwords source ↗

Time-based one-time password (TOTP) is a computer algorithm that generates a one-time password (OTP) using the current time as a source of uniqueness. As an extension of the HMAC-based one-time password (HOTP) algorithm, it has been adopted as Internet Engineering Task Force (IETF) standard RFC 6238.1

TOTP is a cornerstone of the Initiative for Open Authentication (OATH) and is used in a number of two-factor authentication (2FA) systems.

History

Through the collaboration of several OATH members, a TOTP draft was developed in order to create an industry-backed standard. It complements the event-based one-time standard HOTP, and it offers end user organizations and enterprises more choice in selecting technologies that best fit their application requirements and security guidelines. In 2008, OATH submitted a draft version of the specification to the IETF. This version incorporates all the feedback and commentary that the authors received from the technical community based on the prior versions submitted to the IETF.2 In May 2011, TOTP officially became RFC 6238.1

Algorithm

To establish TOTP authentication, the authenticatee and authenticator must pre-establish both the HOTP parameters and the following TOTP parameters:

  • T0, the Unix time from which to start counting time steps (default is 0),
  • TX, an interval which will be used to calculate the value of the counter CT (default is 30 seconds).

Both the authenticator and the authenticatee compute the TOTP value, then the authenticator checks whether the TOTP value supplied by the authenticatee matches the locally generated TOTP value. Some authenticators allow values that should have been generated before or after the current time in order to account for slight clock skews, network latency and user delays.

TOTP uses the HOTP algorithm, replacing the counter with a non-decreasing value based on the current time:

      TOTP value(K) = HOTP value(K, CT),

calculating counter value C T = T T 0 T X , {\displaystyle C_{T}=\left\lfloor {\frac {T-T_{0}}{T_{X}}}\right\rfloor ,} where

  • CT is the count of the number of durations TX between T0 and T,
  • T is the current time in seconds since a particular epoch,
  • T0 is the epoch as specified in seconds since the Unix epoch (e.g. if using Unix time, then T0 is 0),
  • TX is the length of one-time duration (e.g. 30 seconds).

otpauth:// URI scheme

The URI mentioned in this section, encoded as a QR code. Many smartphones allow users to scan such codes and enroll them in an authenticator app, such as Google Authenticator. source ↗

Some implementations of TOTP for smartphones allow users to scan QR codes to add HOTP and TOTP tokens to their authenticator apps. These QR codes contain Uniform Resource Identifiers (URIs) with the scheme otpauth://.3

TOTP otpauth:// URIs begin with otpauth://totp/ and must contain a label and secret. The label is encoded as part of the path, while the secret is encoded as query parameters. The URI may optionally contain other fields, such as the number of digits (which defaults to 6), the algorithm used (which defaults to SHA1), the period (which defaults to 30 seconds), and the issuer name.

The secret is encoded as RFC 4648 Base32, with padding omitted. For example, the URI otpauth://totp/Wikipedian?secret=JBSWY3DPFQQHO33SNRSCC represents a TOTP token labeled "Wikipedian" with the secret Hello, world! encoded as ASCII.

Security

Unlike passwords, TOTP codes are only valid for a limited time. However, users must enter TOTP codes into an authentication page, which creates the potential for phishing attacks. However, due to the short window in which TOTP codes are valid, attackers must proxy the credentials in real time.4

TOTP credentials are also based on a shared secret known to both the client and the server, creating multiple locations from which a secret can be stolen. An attacker with access to this shared secret could generate new, valid TOTP codes at will. This can be a particular problem if the attacker breaches a large authentication database.5

See also

See also

References

References

  1. m'Raihi, David; Rydell, Johan; Pei, Mingliang; Machani, Salah (May 2011). "RFC 6238 – TOTP: Time-Based One-Time Password Algorithm". Archived from the original on July 11, 2011. Retrieved July 13, 2011.
  2. Alexander, Madison. "OATH Submits TOTP: Time-Based One Time Password Specification to IETF". Open Authentication. Archived from the original on 9 April 2013. Retrieved 22 February 2010.
  3. Habets, Thomas (2018-11-26). "Key Uri Format". GitHub. Retrieved 2026-05-24.
  4. Umawing, Jovi (21 January 2019). "Has two-factor authentication been defeated? A spotlight on 2FA's latest challenge". Malwarebytes Labs. Archived from the original on 25 September 2020. Retrieved 9 August 2020.
  5. Zetter, Kim. "RSA Agrees to Replace Security Tokens After Admitting Compromise". WIRED. Archived from the original on 12 November 2020. Retrieved 17 February 2017.