In the context of smart cards, an Application Protocol Data Unit (APDU) is the unit of communication between a smart card reader and a smart card. The structure of the APDU is defined by ISO/IEC 7816-4, which specifies organization, security, and commands for interchange.

An APDU consists of either a command message or a response message, which are sent from the interface device to the card or vice versa. A command-response pair is formed by sending a command, processing it in the receiving entity, and sending back a response. A specific response corresponds to a specific command.

The structure of a Command APDU (C-APDU) includes a required header (CLA INS P1 P2) and an optional body ([Lc field] [Data field] [Le field]). The CLA byte defines an application-specific class of instructions, and the INS byte defines a specific instruction within that class. The P1 and P2 fields can further qualify the instruction and provide input data. The Lc field defines the number of data bytes in the Data field, which can contain up to 255 bytes of data. The Le field defines the maximum number of bytes in the data field of the Response APDU (R-APDU).

The structure of a Response APDU (R-APDU) includes an optional body and a mandatory trailer. The Data field contains the response data, which can be up to 255 bytes and is returned by the applet. The fields SW1 and SW2 provide feedback about the execution of the C-APDU, with the status word 0x9000 representing successful execution of the command.

APDU message structure

A step in an application protocol consists of sending a command, processing it in the receiving entity and sending back the response. Therefore a specific response corresponds to a specific command, referred to as a command-response pair.

An application protocol data unit (APDU) contains either a command message or a response message, sent from the interface device to the card or conversely. In a command-response pair, the command message and the response message may contain data, thus inducing four cases which are summarized in the table below.

Command APDU

A C-APDU consists of a required header (CLA INS P1 P2) and an optional body ([Lc field] [Data field] [Le field]). The CLA byte defines an application-specific class of instructions. According to the ISO7816 standard, byte values between 0xB0 and CF can be used. The INS byte defines a specific instruction within the class of instructions defined by the CLA byte. For valid CLA values, the application developer can define his own application specific instructions. The P1 and P2 fields can be used to further qualify the instruction and to provide input data respectively. The other fields are optional: the Lc field defines the number of data bytes in the data field; the Data field can contain up to 255 bytes of data; and the Le field defines the maximum number of bytes in the data field of the R-APDU.

Response APDU

An R-APDU consists of an optional body and mandatory trailer. The Data field contains the response data, maximum 255 bytes, returned by the applet. The fields SW1 and SW2 provide feedback about the execution of the C-APDU. Several status words are predefined in the ISO7816 standard. The status word 0x9000 represents successful execution of the command.