A nonce is a number or value that a system uses only once, so copied messages cannot be reused.
This guide is for anyone who has seen the word "nonce" in sign-in settings, API documents or encryption notes. You do not need to code. It explains what a nonce is and how it stops replay attacks.
In short
- A nonce is a "number used once". Each message or session gets a fresh one.
- In a replay attack, someone copies a real message and sends it again. A nonce lets the system spot the repeat.
- Sign-in systems use nonces to tie a token to the request that asked for it.
- Encryption also uses nonces. Reusing one with the same key can weaken the protection badly.
What you will learn
- Explain what a nonce is in plain words.
- Describe how a nonce stops a copied message being reused.
- Name three places nonces appear: sign-in, APIs and encryption.
- Spot the common mistakes, such as guessable or reused nonces.
- Use-once value (nonce)
- a fresh value that should never be used twice in the same setting.
- Copy and resend (replay attack)
- sending a genuine message again to fool a system.
- Fresh check (freshness)
- proof that a message is new, not an old copy.
What is a nonce?
Think of a raffle ticket with a printed number. Once that ticket number has won a prize, the stall marks it as used. Someone who photocopies the ticket cannot claim the prize again.
A nonce works the same way. It is a value used only once in a given setting. Some definitions add that it is used only once with a given key [1].
The system adds a nonce to a message, request or encryption step. If it later sees the same nonce again, it knows something is wrong. The message is either a copy or a mistake.
Where the comparison stops working: a raffle ticket is printed in order, so you could guess the next number. Many nonces must be random and hard to guess, or an attacker could prepare one in advance.
For more on the attack itself, see Replay Attacks for Beginners. This page focuses on the nonce and where it is used.
Why does it matter?
Many messages are valid on their own: a sign-in token, a payment request, a signed instruction. Without something fresh in them, a copy can work just as well as the original.
If you build APIs or apps
What could happen: someone captures a valid request and sends it again, for example to repeat a payment.
Check this: make sure important requests carry a nonce or unique ID, and that repeats are rejected.
If you set up single sign-on
What could happen: a stolen sign-in token is replayed to open a session it was never meant for.
Check this: confirm your sign-in library sends a nonce and checks it in the returned token.
Next: How to detect adversary-in-the-middle phishing and session token replay in Entra ID
If you work with encryption
What could happen: the same nonce is used twice with the same key, and the protection is weakened.
Check this: use a well-known library and let it create nonces for you.
What does it look like?
Here is a made-up request from an app to a payment service. The nonce makes each request unique.
Example only. All values are made up.
POST https://pay.example.invalid/transfer amount: 10.00 (1) to: EXAMPLE-account-0000 (2) nonce: EXAMPLE-nonce-7d1f9a (3) time: 0000-00-00T09:15:00Z (4) signature: EXAMPLE-signature-FAKE (5)
- What the request asks the service to do.
- Where the money goes.
- In a real file, this line would contain a long random value made fresh for this one request.
- A time label, so very old requests can be turned away.
- A signature over all the lines, so nobody can change the nonce without being caught.
Why this is risky: without the nonce and time, a copied request with a valid signature could be sent again and again.
The safer way: sign the nonce with the rest of the request, and have the server reject any nonce it has seen before.
How does it work?
- Make a fresh value. The client or server creates a new random nonce for this one exchange.
- Bind it to the message. The nonce goes inside the request or token and is covered by its signature.
- Send the message. The other side receives it with the nonce inside.
- Check it. The receiver checks that the nonce is the one it expected, or one it has never seen.
- Remember or discard. The receiver records the nonce as used, often only for a short time window.

An early definition from a US standards body describes a nonce as a random value used to defeat "playback" attacks in communication protocols [1]. Playback is another name for replay.
Sign-in is a common example. In OpenID Connect, the app sends a nonce when it asks for a sign-in. The value is passed through unchanged into the returned ID token, and the app must check that the two match [2]. The specification says the nonce is there to link the app's session to the token and to reduce replay attacks [2].
The same specification says nonces need enough randomness that attackers cannot guess them [2]. A counter that goes 1, 2, 3 is easy to predict.
Encryption uses nonces in a slightly different way. Here the nonce makes each encrypted message different, even with the same key. Several definitions say it must be used only once under a given key [1]. You may also see this called an initialisation vector.
A worked example
This story is made up to show the idea.
Juno Zeller builds the mobile app for a small coffee chain. Customers can top up a loyalty card from the app.
During testing, her colleague Umar Ulrich records a genuine top-up request on a test phone. He sends the exact same request to the test server five more times. The test card is topped up six times, though only one payment was taken.
Juno looks at the request. It is signed, so nobody can change the amount. But nothing in it is unique, so every copy looks genuine.
She adds two fields. The app now creates a random nonce for each top-up and adds the current time. Both go inside the signed part of the request.
On the server, Juno adds a short list of nonces seen in the last ten minutes. Any request with a nonce already on the list is refused. Any request older than ten minutes is refused too, so the list stays small.
Umar runs the same test again. The first request works. The five copies are all rejected, and each one is logged.
Juno also checks the app's sign-in. The library already sends a nonce and checks it in the returned token, so she leaves it on and notes it in the design.
Myths and mistakes
| What people think | What is true |
|---|---|
| A nonce has to be secret. | Most nonces are sent openly. What matters is that they are fresh, hard to guess where needed, and never reused. |
| A signature alone stops replays. | A signature stops changes. A copy of a signed message is still valid unless something fresh, like a nonce, is checked. |
| A simple counter is a good nonce for sign-in. | Sign-in nonces need enough randomness that attackers cannot guess them[2]. |
| Reusing an encryption nonce now and then is harmless. | Nonces used in encryption should be used only once under a given key[1]. Reuse can weaken the protection badly. |
| Sending a nonce is enough. | The receiver has to check it. A nonce nobody checks does nothing. |
What can I do this week?
- Pick one important action in your app, such as a payment, and check whether a copied request would work twice.
- Look in your sign-in settings or library documents for "nonce", and confirm the check is switched on.
- Make sure any encryption code uses a trusted library that creates nonces for you.
- Read Replay Attacks for Beginners to see other ways systems spot copies.
Checklist
- I can explain a nonce as a value used only once.
- I know how a nonce helps stop replay attacks.
- Important requests carry a nonce that is covered by the signature.
- The receiver checks nonces and rejects repeats.
- Sign-in nonces are random, not simple counters.
- Encryption nonces are never reused with the same key.
- Rejected repeats are logged so someone can look into them.
Common questions
What does nonce stand for?
It is usually explained as "number used once". The value does not have to be a plain number. It can be any string of characters, as long as it is not used again in the same setting[1].
Is a nonce the same as a timestamp?
No, but they work well together. A timestamp shows when a message was made, so old ones can be refused. A nonce shows a message is unique. Using both lets a server keep only a short list of recent nonces.
Where will I see nonces?
In sign-in systems such as OpenID Connect, where the nonce links a token to the request[2]. In API requests that must not be repeated. And in encryption settings, where a nonce keeps each encrypted message different.
What happens if a nonce is reused?
A reused nonce in a request should simply be rejected as a possible replay. In encryption, reusing a nonce with the same key can expose patterns in the data. That is why trusted libraries handle nonces for you.
Does a nonce protect a stolen password?
No. A nonce stops a copied message being used again. It does not help if someone has your password and signs in fresh. For that, use strong unique passwords and extra sign-in checks.
Where next?
Ready for the detail? Read the practitioner guide: DKIM Replay Attacks Guide. It shows how replay works against signed email and what defenders do about it.
Also useful:
- Replay Attacks for Beginners
- How to detect adversary-in-the-middle phishing and session token replay in Entra ID
- Encoding, Encryption and Hashing for Beginners
Related NHI Mgmt Group resources: Authenticator Apps for Beginners and Hashing Guide.
Key terms
- Nonce
- A value that is used only once in a given context, often to prove a message is fresh.
- Replay attack
- An attack where someone copies a genuine message and sends it again to trick a system.
- Initialisation vector
- A starting value fed into an encryption method so the same input and key give different results each time.
- Nonce claim
- The nonce value carried inside a sign-in token, which the app checks against the one it sent.
- Token replay
- Reusing a stolen or copied sign-in token to get access without signing in again.
Sources and further reading
- NIST Computer Security Resource Center, "Nonce", Glossary. https://csrc.nist.gov/glossary/term/nonce (accessed 30 Nov 2026).
- OpenID Foundation, "OpenID Connect Core 1.0", sections 2, 3.1.2.1 and 3.1.3.7. https://openid.net/specs/openid-connect-core-1_0.html (accessed 30 Nov 2026).