DESFire Random UID: Why a Card's ID Can Change Every Tap
A DESFire card that reports a new ID on every tap is usually not broken. It is using the optional random ID. Here is how that works and what to read instead.
If a DESFire card shows a different ID every time you tap it, the card is most likely using its random ID option, not failing. The change is deliberate. It stops a stranger's reader from using the card's serial number to recognize it again. It does mean any app that treats the ID as a permanent name for the card will stop working.
Fixed UID or random ID
Every NFC card announces a low-level serial number when a reader finds it. Android's documentation describes it as an identifier "used for anti-collision and identification", and says most tags have a stable unique identifier (UID).
DESFire cards give the issuer a choice. NXP's MIFARE DESFire EV3 page lists the ID as "7B UID or 4B RID", and calls the random option an "optional 'RANDOM' ID for enhanced security and privacy". Random ID support isn't new in EV3: the MIFARE overview on Wikipedia lists it among the DESFire EV1 features.
The privacy reasoning is simple. A fixed UID is the same wherever you tap, so anyone with a reader could log it and recognize the card later. A random ID gives that reader nothing stable to log.
NXP's page doesn't say how the byte layout of the random ID works, or how a real UID can still be retrieved when the random option is on, so we won't guess. If you're designing a system around either, the datasheet for your exact card is the place to check. For picking between card generations in the first place, see DESFire Light vs EV3.
How a phone sees the ID
On Android, Tag.getId() returns the tag identifier. The Android Tag reference says most tags have a stable UID, "but some tags will generate a random ID every time they are discovered", and that a few have no ID at all. It also says the call returns the ID as determined at discovery time, with no further RF communication.
Android creates a new Tag object each time a tag comes into range, even for the same physical card. So with a random-ID card, your app gets a fresh value on each tap, and nothing in the phone API links two taps together.
A quick way to check which kind you hold: tap the card, note the ID, lift it away, and tap again. Same bytes both times means a fixed UID. Different bytes means a random ID. For how iPhone and Android differ when they read these cards at all, see reading a DESFire card with a phone.
What breaks, and what to use instead
Anything that uses the ID as the card's identity will misbehave:
- A "known cards" list will never match the second tap.
- An attendance or check-in log will record every tap as a new person.
- A lookup table keyed on ID will fill up with entries that never come back.
The fix is to stop treating the ID as the identity. DESFire stores data in applications and files, protected by keys, so the identity can live inside the card and be read after the reader authenticates. Our guide to applications, files, and keys covers how that is organized.
This applies to cards you own or that your organization issues. Reading identifiers from cards that belong to someone else, or that you aren't authorized to manage, is outside what we cover.
Checking a card in NFCore
In NFCore, scan a card twice and compare the ID shown for each scan. If it changes, you are looking at a random ID, and you should plan your project around data stored on the card instead. NFCore is also on Google Play. iPhone and Android expose different amounts of low-level detail, so what you see for a given card can differ between the two.
What to take away
A changing ID on a DESFire card is a privacy feature doing its job. Test with two taps, and keep identity in the card's own data, not its serial number.
Frequently Asked Questions
Is a DESFire random ID the same as the card being broken?
No. A changing ID is the random ID option working as designed. NXP lists it as an optional feature for enhanced security and privacy.
Do all DESFire cards use a random ID?
No. NXP lists the ID as either a 7-byte UID or a 4-byte random ID, so it depends on how the card was configured. Tap the card twice and compare the IDs to find out which one yours uses.
Can an iPhone or Android phone show me the same ID every time?
Only if the card sends a fixed UID. Android's Tag.getId() returns the ID found at discovery time, and Android documents that some tags generate a random ID each time they are discovered.