APDU is an application-level protocol, defined in ISO 7816-4, used between a smart card and a POS, ATM, etc.
There are two types of APDU:
- Command APDU
- Response APDU
The structure of the APDU is given below:
Command APDU structure
| Mandatory Header | Mandatory Header | Mandatory Header | Mandatory Header | Optional body | Optional body | Optional body |
| CLA | INS | P | P2 | Lc | Data Field | Le |

The first four sections, namely CLA , INS , P1 and P2 are mandatory in all APDU commands, and each one is one byte long . These one-byte-long sections respectively represent Class, Instruction, Parameter 1, and Parameter 2.
The last three sections, namely Lc, CData and Le are optional.
- Command APDU (C-APDU): This command is used by the host application to send a command to the card.
- Header: consists of 4 bytes:
- Class (CLA)
- Instruction code (INS)
- Parameters: P1 and P2
- Optional body: varies in length.
- Lc = indicates the length (in bytes) of the optional body, or data field.
- Le = indicates the data length, or the number of bytes the host expects in response to the command sent.
- The data field contains the data sent to the card to execute the instruction specified in the header.
- Header: consists of 4 bytes:
- Response APDU (R-APDU): This command is used by the card to respond to the command sent by the host application.
- Optional body: consists of the data field, whose length is specified by Le
- Trailer: consists of two words, SW1 and SW2, called the status words, which indicate the processing status on the card after the APDU command has been executed.
Response APDU structure
| Optional body | Mandatory Trailer | Mandatory Trailer |
| Data Field | SW1 | SW1 |

- A command is always paired with an APDU response.
- The data field is optional in both the APDU command and the APDU response.
APDU categories
There are four types of APDU categories:
- There is no data transfer to or from the card
- C-APDU: contains only the header.
- R-APDU: contains only the trailer information.
- There is no data transfer to the card, but data is returned from the card.
- C-APDU: contains only Le, which indicates the number of data bytes expected in the corresponding APDU response.
- Data is transferred to the card, but no data is returned from the card.
- C-APDU: contains Lc, which indicates the length of the data field, and the data field itself.
- R-APDU: contains the trailer status words SW1 and SW2.
- Data is transferred to the card and data is returned from the card.
- C-APDU: contains Lc, the data field, and Le.
- R-APDU: contains the optional body and the trailer status words SW1 and SW2.




