NFC tags store data in a special format called NDEF (NFC Data Exchange Format) created by NFC Forum. It defines the structure of the data and can either be implemented in NdefMessage or NdefRecord.
As such, the NDEF format allows for multiple types of data to be stored on a single tag, making it perfect for applications such as contactless payments and marketing campaigns. In this article, we discuss the NDEF format and its key features.
What is NDEF Format?
The NDEF format is a standard data structure that can be used to encode information on NFC tags. It allows flawless data exchange between compatible NFC devices and NFC tags. The data format primarily consists of:
- NDEF Records
- NDEF Messages
NDEF records are made up of three main components:
- A record type identifier
- The actual data being stored
- A cyclic redundancy check (CRC) for guaranteed data integrity
Record Type Identifier
The record type identifier tells the NFC reader what type of information is being stored on that particular NDEF record.
For example, if a contactless payment terminal interacts with an NFC tag, it will read the record type identifier and only process payment-related NDEF records.
The record type identifier can be stored in different formats, including URI records, service delivery records, URI &MIME records, or Eddystone UDI records.
Data Types Supported by NDEF
The data types supported by the NDEF format are URI records, MIME type records, and Service Discovery records. An NFC tag can store diverse information or one type of data per NDEF record.
For example, you might use different URI records to store the URL of your website, the download address for an Android app, and the contact information for your company.
- URI Record
This type is used solely to store Uniform Resource Identifier (URI) data. As its name suggests, it can be used to point NFC devices at sources of various types of URI data. For example website URLs, applications installations, and contact information.
- MIME Type Record
MIME stands for Multipurpose Internet Mail Extension. This record store both a Uniform Resource Identifier (URI) and a MIME Type record in the NDEF format. The MIME type is used to determine how to handle the information stored in the URI part of the record, so you should always include this when storing content on an NFC tag. For example, if you stored a URI record pointing to a website on an NFC tag, the MIME-type for this record should be ‘text/HTML.
- Service Discovery Record
This record is used to store service discovery information in the NDEF format. This information can be used by ‘discoverable’ NFC devices to determine if they are within the range of services relevant to them.
The information stored in a Type C NDEF record can be up to 27 bytes in total.
- Eddystone UID Record
The Type D record is used to store a unique identifier in the form of a URL that conforms to the Eddystone protocol. The exact format of this URL will depend on which particular Eddystone protocol is being used.
What are NDEF Messages in NDEF Format?
NDEF messages are the data packets that contain information stored on an NFC tag. These messages are created by placing NDEF records into a container structure called an NDEF Message.
Each record contains a specific type of data that can be recognized by its ‘payload’ format field value. Most often, the data include URLs, Uniform Resource Identifiers (URIs), NDEF messages, or MIME types to identify the content of the data.
NDEF records comprise three parts:
The header defines the type of record and where the payload starts. The exception to this is NDEF URI records which have no payload. The footer is just a string terminator marking the end of the record.
The NDEF format allows for multiple types of data to be stored on a single tag, making it perfect for applications such as contactless payments and marketing campaigns.
What are NDEF Specifications?
Several specifications ensure that NFC tags and devices are compatible with each other. This is essential to avoid any interoperability problems between different manufacturers.
The NFC Forum specification defines guidelines for writing, formatting, and encoding NDEF data. This ensures that all manufacturers will write compatible content onto NFC tags.
One of the most important parts of this specification is the NDEF record type table. It specifies the types of records that can be included in an NDEF message and what action should be taken by the device when each one is encountered. For example, if you want to write a URI onto an NFC tag using the NDEF format, this would need to be specified in the record type table; otherwise, the device would not know what action to take when it encountered this record.
Benefits of Using NDEF Format
The most obvious benefit of the NDEF format is compatibility. It offers a widely accepted format that enables NFC users to exchange data with ease. Other of its advantages include:
- There is no minimum or maximum size for an NDEF record. This makes it possible to store more information on your NFC tags than you could in most other formats. For example, you could use an NDEF record to store a YouTube video or photo gallery URL, which would be too large for many other formats.
- The NDEF format is supported by almost all NFC devices and operating systems. The only exception is the old Windows Phone 7 devices, which do not support the NDEF format when reading NFC tags.
- NDEF records can be used to store multiple pieces of data in a single NFC tag. If you need to fit more information into a single tag, this is the format that you should use. The great thing about using NDEF for storing your information is that it allows other NFC tags to read and aggregate information from different sources.
What is an NDEF Record Type Table?
As we have discussed above, the NDEF Record Type Table defines which types of records can be included in an NDEF message and what actions should be taken by the devices that encounter them.
As you have seen, the NDEF format allows for multiple types of data to be stored on a single tag. This makes it perfect for applications such as contactless payments and marketing campaigns which require a wide range of different data formats.
To make this process easier for developers, Android has implemented some APIs that can be used to manipulate NDEF messages directly.