How to Read and Write NFC Tags

<\/script>\n
'; }, get iframeSnippet() { const domain = '{ SITE_DOMAIN }'; const type = '{ embed_type }'; const slug = '{ embed_slug }'; return ''; }, get activeSnippet() { return this.method === 'script' ? this.scriptSnippet : this.iframeSnippet; }, copySnippet() { navigator.clipboard.writeText(this.activeSnippet).then(() => { this.copied = true; setTimeout(() => { this.copied = false; }, 2000); }); } }" @keydown.escape.window="open = false" @click.outside="open = false">

Embed This Widget

Theme


      
    

Widget powered by . Free, no account required.

Step-by-step operational guide

Practical guide to reading and writing NFC tags using smartphones and dedicated readers. Covers NDEF formatting, common apps, password protection, and troubleshooting failed operations.

| 3 min read

How to Read and Write NFC Tags

Reading and writing NFC tags requires understanding the NDEF data model, your platform's NFC API, and common failure modes. This guide covers the complete workflow from tapping a tag to persisting structured data.

Reading Tags

When an nfc-enabled-device enters reader-writer-mode, it polls for tags at 106–424 kbit/s. Once a tag responds, the reader retrieves the tag's uid and reads the NDEF memory area.

The NDEF memory contains a sequence of ndef-records wrapped in an ndef-message. Each record carries a Type Name Format (tnf), a type string, an optional ID, and a payload. Common record types:

TNF Type Payload Example
1 (Well Known) U URI https://nfcfyi.com
1 (Well Known) T Text en:Hello NFC
2 (MIME) text/vcard vCard blob Contact card
4 (External) nfcfyi.com:cfg Custom bytes App config

On Android, a successful read delivers an NfcAdapter.ACTION_NDEF_DISCOVERED intent containing a NdefMessage. On iOS (Core NFC), NFCNDEFReaderSession calls readerSession(_:didDetectNDEFs:). Both platforms expose the raw NdefRecord array.

Writing Tags

Before writing, verify that the tag is not locked. Tags expose lock-bits that, once set, make the memory permanently read-only. A capability-container at the start of the NDEF area declares memory size, access conditions, and whether the tag is NDEF-formatted.

Writing workflow: 1. Authenticate if the tag has a password (PWD_AUTH for NTAG, AUTHENTICATE for DESFire). 2. Format the tag if it has no capability container (first use). 3. Construct an NdefMessage with one or more NdefRecords. 4. Write the message using the platform API (Ndef.writeNdefMessage() on Android, NFCNDEFTag.writeNDEF() on iOS). 5. Optionally set the otp lock page to protect the content.

NDEF Basics

The NDEF specification defines a compact binary encoding. Each record begins with a flags byte encoding MB (Message Begin), ME (Message End), CF (Chunk Flag), SR (Short Record), IL (ID Length), and TNF. A short record stores the payload length in 1 byte (max 255 B); a normal record uses 3 bytes (max 16 MB).

The most important record types for getting started:

  • ndef-uri — Encodes a URL with a 1-byte prefix abbreviation (e.g., 0x03 = https://)
  • ndef-text — Encodes a UTF-8 or UTF-16 string with an IANA language code
  • smart-poster — Composite record combining URI + Text title + optional action

Common Errors

Error Cause Fix
TagLostException Tag moved before write completed Hold steady; retry
FormatException Malformed NDEF message Validate with NDEF Decoder
ReadOnlyException Lock bits set Use a different tag
Write returns success but read fails Buffer too small for payload Check user-memory with Memory Calculator
Auth failure Wrong password Reset via backdoor if available (chip-specific)

Use the NDEF Message Encoder to construct and preview NDEF payloads before writing, and the NDEF Message Decoder to inspect raw bytes from an existing tag.

See also: Your First NFC Project and Android NFC Programming Guide.

자주 묻는 질문

The most popular no-code NFC tools are NFC Tools (iOS/Android), NFC TagWriter by NXP (Android), and TagInfo by NXP (Android, read-only diagnostics). These apps let you write NDEF records — URLs, plain text, vCards, Wi-Fi credentials, phone numbers, and more — to any writable NFC tag without writing a single line of code. NFC Tools is recommended for beginners due to its clean UI and broad record-type support.

Most NFC Forum Type 2 tags support write-locking via OTP (One-Time Programmable) lock bits. Once set, these bits cannot be reversed and the tag becomes permanently read-only. Some chips like NTAG213 also support a 32-bit password that prevents writes without the correct PIN but leaves the tag readable. Apps like NFC Tools include a 'Write Protect' option that applies the appropriate lock mechanism automatically.

The most common causes are: (1) NFC is disabled in device settings; (2) the phone's NFC antenna location does not align with the tag — try moving the tag across the phone's back slowly; (3) the tag memory is full or the NDEF record is malformed; (4) the tag is placed on metal without a ferrite spacer, which absorbs the RF field. For iPhones, ensure you are running iOS 13+ and have granted the app NFC permissions.

NDEF (NFC Data Exchange Format) is the standard container format for data stored on NFC tags. Each NDEF message contains one or more NDEF records, where each record has a TNF (Type Name Format) byte, a type field (e.g., 'U' for URI, 'T' for Text), and a payload. A URL record encoding 'https://example.com' typically requires fewer than 30 bytes after prefix compression, leaving the rest of the tag memory free for additional records.

Our guides cover a range of experience levels. Getting Started guides are written for beginners with no prior NFC knowledge. Programming guides target developers integrating NFC into mobile apps or embedded systems. Security guides are for engineers designing secure NFC deployments for payments, access control, or authentication.

Most guides require only an NFC-enabled smartphone (iPhone 7+ or any modern Android device) and a few NFC tags (NTAG213 or NTAG215 recommended for beginners, available for under $1 each). Advanced guides may reference USB NFC readers like the ACR122U or Proxmark3 for development and testing.

Yes. Programming guides include code examples for Android (Kotlin/Java with the Android NFC API), iOS (Swift with Core NFC), and web-based tools (Web NFC API for Chrome on Android). All code samples are tested and include inline comments explaining each step.