How to Send APDU Commands to a Smart Card

How do you send an APDU to a smart card? You build a byte string in the ISO/IEC 7816-4 format, a four-byte header CLA INS P1 P2, optionally followed by Lc, the command data and Le, and pass it to the card through the reader. On Windows and Linux that means one PC/SC call, SCardTransmit, on a connection opened with SCardConnect. The card answers with optional data followed by two status bytes, SW1 SW2. 90 00 means success. Anything else tells you what went wrong, or, with 61 xx and 6C xx, what to send next.

This page explains the command format, the four APDU cases, the status words you will meet most often, the T=0 GET RESPONSE rule, a few standard commands, and how ACS's class FF reader commands differ from real card commands. It ends with the call flow for sending APDUs from your own program. If you want to try commands in a ready-made tool first, use the ACS Script Tool guide or the ACS Web APDU Tool guide. Facts come from public summaries of ISO/IEC 7816-4, the PC/SC Workgroup specifications and Microsoft's WinSCard documentation (see Sources). BSD Infotech is an independent ACS supplier and integrator, not the manufacturer.

APDU stands for application protocol data unit. Communication is always a pair: the application sends a command APDU and the card returns a response APDU. The card never speaks first. ISO/IEC 7816-4 defines the format, and contactless cards that implement ISO 14443-4 (for example MIFARE DESFire) use the same format.

Command APDU

FieldLengthWhat it holds
CLA1 byteInstruction class. 00 is the usual interindustry class for ISO 7816-4 commands. Other values are proprietary: FF is reserved for PC/SC reader commands, and card makers define their own (DESFire's wrapped native commands use 90).
INS1 byteInstruction code: what to do, for example A4 SELECT, B0 READ BINARY, CA GET DATA, C0 GET RESPONSE.
P1 P22 bytesParameters of the instruction, such as a selection mode or a file offset. With CLA and INS they form the mandatory four-byte header.
Lc0, 1 or 3 bytesNumber of command data bytes (Nc). Absent when no data is sent.
DataNc bytesThe command data, for example an application identifier (AID) for SELECT.
Le0, 1, 2 or 3 bytesMaximum number of response bytes expected (Ne). Absent when no data is expected. In the one-byte form, 00 means "up to 256".

Response APDU

The response is the data the card returns (zero bytes up to Ne), followed by the two mandatory status bytes SW1 SW2. Read a response from the end: the last two bytes are always the status word, and the bytes in front of it are data. If the status word is an error, there is normally no data at all.

A command decoded byte by byte

This SELECT command asks a card to select the NFC Forum Type 4 Tag application by its AID. It is a useful example because it contains every field:

00 A4 04 00 07 D2 76 00 00 85 01 01 00

00                    CLA  interindustry class
A4                    INS  SELECT
04                    P1   select by DF name (application identifier)
00                    P2   first or only occurrence, return file control information
07                    Lc   7 data bytes follow
D2 76 00 00 85 01 01  Data the AID of the NDEF Tag application
00                    Le   return up to 256 bytes

A card that has this application answers with optional data and 90 00. A card without it answers 6A 82 (file or application not found). A MIFARE Classic or NTAG card does not understand ISO 7816-4 APDUs at all, so you talk to it through the reader's class FF commands instead (see ACS FF commands).

ISO/IEC 7816-4 sorts every command into one of four cases, depending on whether data goes to the card, comes back from it, or both. The case decides which of Lc, Data and Le are present.

CaseData to card?Data from card?Byte layoutExample
1NoNoCLA INS P1 P2A command that only changes state and returns just a status word
2NoYesCLA INS P1 P2 LeFF CA 00 00 00 (Get Data, card UID); 00 B0 00 00 0F (READ BINARY, 15 bytes)
3YesNoCLA INS P1 P2 Lc DataFF 82 00 00 06 + 6 key bytes (PC/SC Load Keys)
4YesYesCLA INS P1 P2 Lc Data LeThe SELECT by AID example above

Short and extended length

  • Short APDUs (the default) code Lc and Le in one byte each: up to 255 data bytes to the card and up to 256 back (Le = 00 means 256).
  • Extended APDUs start the length field with a 00 byte and then use two bytes: up to 65,535 data bytes to the card and up to 65,536 back. In a case 2 command the extended Le is three bytes (00 + two bytes); in a case 4 command it is two bytes after the extended Lc.
  • A card may only be sent extended APDUs if it says it supports them (in its ATR or its file control information). The reader and driver must support them too. Check both manuals before relying on extended length; most everyday commands, and every ACS FF command shown on BSD's pages, use short APDUs. For the ATR itself, see the protocol notes in our PC/SC architecture guide.

The status word is the card's verdict on your command. The first digit already tells you a lot: 90 00 is success, 61 and 62/63 are normal or warning results, and 64 to 6F are errors. Meanings below follow ISO/IEC 7816-4; "xx" means "any value", which then carries information.

SW1 SW2TypeMeaningWhat to do
90 00SuccessNormal processing, no further qualification.Use the data in front of the status word.
61 xxSuccess, more dataResponse bytes are still available; xx tells you how many to ask for.Send GET RESPONSE 00 C0 00 00 xx before any other command (see T=0 GET RESPONSE).
62 82WarningEnd of file or record reached before Le bytes were read.The data you got is valid but shorter than you asked for.
63 00WarningNo information given. For ACS class FF commands, ACS manuals use it to mean "the operation failed", for example a MIFARE authentication with the wrong key.For a card command, check the card's manual. For an ACS reader command, check the key, block number and card type.
63 CxWarningA counter, x from 0 to 15. After a VERIFY (PIN) command it usually means "x tries left".Stop and find the right PIN before the counter reaches zero and blocks the card.
67 00ErrorWrong length (Lc or Le).Recount the data bytes and check Lc.
68 81 / 68 82ErrorLogical channel not supported / secure messaging not supported (functions in CLA).Use the class byte your card's manual specifies. PC/SC Part 3 uses 68 00 for "class byte is not correct" on storage-card commands.
69 82ErrorSecurity status not satisfied.Authenticate or verify first, with a key you are entitled to use. Never try keys at random.
69 85ErrorConditions of use not satisfied.The command is valid, but not in the card's current state; check the order of commands.
69 86ErrorCommand not allowed (no current EF).SELECT the file before reading it.
6A 81ErrorFunction not supported.On FF CA: the card has no UID to return (PC/SC Part 3), for example a contact card.
6A 82ErrorFile or application not found.Check the AID or file identifier; the card may simply not have that application.
6A 86ErrorIncorrect parameters P1-P2.Check P1 and P2 against the command definition.
6B 00ErrorWrong parameters P1-P2 (for example an offset outside the file).Check the offset or block number.
6C xxError, retryWrong Le; xx is the exact number of bytes available.Send the same command again with Le = xx, before any other command.
6D 00ErrorInstruction code not supported or invalid.The card does not know this INS. Check you are talking to the right card or application.
6E 00ErrorClass not supported.Wrong CLA. A common cause: sending a reader command (FF) straight to a card, or an ISO command (00) to a card that only has a proprietary class.
6F 00ErrorNo precise diagnosis.Repeat once on a fresh connection; if it persists, check the card's manual.

Status words are a card (or reader) answer, not a PC/SC error. If SCardTransmit itself fails, you get a PC/SC return code such as 0x80100069 instead; those are listed in the PC/SC error code table. Card families can add their own status words: DESFire's native commands, for example, answer with 91 xx, which NXP documents for that card. When the card's own manual and this table disagree, the card's manual wins.

Contact cards talk to the reader with one of two transmission protocols, T=0 or T=1 (ISO/IEC 7816-3). T=1 carries a whole APDU in one exchange. T=0 is older and byte-oriented, and it cannot carry data in both directions in one command. That changes how case 2 and case 4 commands behave, and your program has to handle it.

  • Case 4 on T=0. PC/SC Part 3 says a case 4 APDU cannot be used with T=0, and that the application or service provider must issue GET RESPONSE itself if it needs the response data. In practice the card receives the command without Le, processes it, and answers 61 xx: "xx bytes are waiting". You then fetch them with GET RESPONSE.
  • Case 2 with the wrong Le. If you ask for a different number of bytes than the card has, a T=0 card may answer 6C xx. Send the same command again with Le set to xx.
  • Only short APDUs. PC/SC Part 3 also says only the one-byte forms of Lc and Le are supported on T=0.

The exchange, step by step

> 00 A4 04 00 07 D2 76 00 00 85 01 01        SELECT by AID (case 4, sent without Le on T=0)
< 61 1A                                      26 bytes are waiting
> 00 C0 00 00 1A                             GET RESPONSE, Le = 1A
< [26 data bytes] 90 00                      the data, then success

> 00 B0 00 00 20                             READ BINARY, asks for 32 bytes
< 6C 0F                                      wrong Le: 15 bytes are available
> 00 B0 00 00 0F                             same command, Le = 0F
< [15 data bytes] 90 00

The replies above illustrate the pattern; the byte counts depend on the card. Two rules make the loop safe: send GET RESPONSE (or the retry) immediately, before any other command, because the card discards the waiting data otherwise; and if GET RESPONSE itself returns 61 xx again, keep fetching and append each piece until you get 90 00. Contactless cards often appear in PC/SC with protocol T=1, but some cards still answer 61 xx, so handle it in every program.

Most work on a microprocessor card starts with the same few interindustry commands. The bytes below are the ISO/IEC 7816-4 and PC/SC Part 3 definitions; what a card actually returns depends on its applications and access rules.

CommandBytesGoes toNotes
SELECT by AID00 A4 04 00 Lc [AID] 00CardOpens an application. P1 = 04 selects by DF name (AID). Read-only.
SELECT by file ID00 A4 00 0C 02 [FID]CardP1 = 00 selects by two-byte file identifier; P2 = 0C asks for no response data. Read-only.
READ BINARY00 B0 [offset high] [offset low] LeCardReads a transparent file that is already selected. If bit 8 of P1 is set, P1 carries a short file identifier instead. Read-only.
GET DATA (ISO)00 CA [tag] [tag] LeCardP1-P2 name a data object; the meaning is set by the card or application.
Get Data / UID (PC/SC Part 3)FF CA 00 00 00ReaderThe reader returns the card's UID itself, without sending a command to the card. FF CA 01 00 00 returns the historical bytes of the ATS of an ISO 14443 Type A card, where supported. Read-only.
GET RESPONSE00 C0 00 00 xxCardOnly after a 61 xx reply (see above).

For a working UID read, with the byte-order and decimal questions people often have, see reading an NFC card UID with an ACS reader. PC/SC Part 3 also defines the status words for FF CA: 6A 81 if the card has no UID, 6C xx if your Le was shorter than the UID, and 62 82 if it was longer than the data.

Notice the two READ BINARY commands in this page: 00 B0 is the ISO command a microprocessor card executes, and FF B0 is the PC/SC storage-card command the reader translates for a memory card such as MIFARE Classic. Same instruction, different class, different receiver. The next section explains why.

Everything you send through SCardTransmit looks like an APDU, but it can end up in two different places:

Card APDUReader command ("pseudo-APDU", class FF)
Who executes itThe card's operating system or applicationThe ACS reader firmware
Typical CLA00, or the card's own class (for example 90 for DESFire native commands)FF
CardsMicroprocessor cards: ISO 7816 contact cards, ISO 14443-4 contactless cards such as DESFireStorage cards that do not understand APDUs (MIFARE Classic, Ultralight, NTAG), plus reader functions on any card
Defined byISO/IEC 7816-4 and the card maker's manualPC/SC Part 3 (FF CA, FF 82, FF 86, FF B0, FF D6, FF 20) and each ACS reader's API manual (ACS's own FF 00 xx commands)
Status words come fromThe cardThe reader; the same command can give a different error code on another reader model
Portable between readers?Yes, any PC/SC reader passes them throughThe PC/SC Part 3 set mostly yes; ACS-specific commands no, they differ by model

PC/SC Part 3 also says the reader must not filter or translate APDUs for cards that understand them, so a DESFire card gets your ISO commands untouched. Settings of the newer ACS readers (ACR1252U, ACR1552U) mostly go through escape commands with SCardControl instead, which is a different route; the full comparison is in SCardTransmit vs SCardControl, and the PC/SC background is in pseudo-APDUs explained.

Which reader commands each model supports is in its ACS API manual (listed as "Application Programming Interface" under Related Documents on the ACS product page). BSD's model guides summarise them with C# examples: the ACR1252U SDK guide, the ACR1552U developer notes and the ACR122U pseudo-APDU explanation. For MIFARE Classic, the read sequence (Load Keys, General Authenticate, Read Binary with the factory key) is shown step by step in the MIFARE card test guide.

Every language that can call PC/SC (C#, C++, Java, Python and others) follows the same sequence, because they all end up in winscard.dll on Windows or pcsc-lite on Linux. Why each call exists is explained in the PC/SC call sequence.

  1. Open a context (SCardEstablishContext) and list the readers (SCardListReaders). Pick the right entry: ACS dual-slot readers list the contactless (PICC) interface and the SAM slot separately.
  2. Connect to the card (SCardConnect) in shared mode, allowing T=0 and T=1. Keep the protocol it returns: you need it for every transmit.
  3. Build the APDU as a byte array and choose its case: add Lc and data only if you send data, and Le only if you expect data back.
  4. Transmit (SCardTransmit) with the protocol header that matches the active protocol, and a receive buffer big enough for the data plus two status bytes (258 bytes covers any short APDU).
  5. Check two results, in this order. First the PC/SC return code: if it is not zero, the command never completed (card removed, reader gone, buffer too small). Then the status word: the last two bytes of the reply.
  6. React to the status word. 90 00: use the data. 61 xx: send GET RESPONSE with Le = xx and append the data, repeating while 61 comes back. 6C xx: resend the same command with Le = xx. Anything else: stop and report the status word.
  7. Clean up: SCardDisconnect with SCARD_LEAVE_CARD, then SCardReleaseContext. Group commands that must not be interrupted by another program inside SCardBeginTransaction / SCardEndTransaction.

The transmit step in C# (.NET 10)

Language: C# 14 on .NET 10, Windows (P/Invoke to winscard.dll). Prerequisites: a card handle and protocol from SCardConnect, and the WinScard P/Invoke declarations from the complete ACR1252U example. The full program, with reader detection, card waiting and error handling, is in our PC/SC programming in C# tutorial.

Not yet tested on a reader. BSD Infotech compiled these lines for .NET 10 on 1 Dec 2026 but has not yet run them with an ACS reader and a card. Treat them as a starting point.

// C# 14, .NET 10, Windows (winscard.dll). Not yet tested on a reader.
byte[] apdu = [0xFF, 0xCA, 0x00, 0x00, 0x00];                  // Get Data (UID), read-only
var pci = new WinScard.SCARD_IO_REQUEST { dwProtocol = protocol, cbPciLength = 8 };
byte[] recv = new byte[258]; uint len = (uint)recv.Length;     // 256 data bytes + SW1 SW2
int rc = WinScard.SCardTransmit(card, ref pci, apdu, (uint)apdu.Length, IntPtr.Zero, recv, ref len);
if (rc != 0) throw new InvalidOperationException($"PC/SC error 0x{rc:X8}"); // transport failed
if (len < 2) throw new InvalidOperationException("Reply too short");
byte sw1 = recv[len - 2], sw2 = recv[len - 1];                 // status word is always last
Console.WriteLine($"Data: {Convert.ToHexString(recv, 0, (int)len - 2)}  SW: {sw1:X2} {sw2:X2}");

Expected result with a contactless card on an ACS reader: the UID bytes and SW: 90 00 (for example a 4-byte UID on a MIFARE Classic 1K, a 7-byte UID on an NTAG). With a card that has no UID, such as a contact card, PC/SC Part 3 specifies 6A 81; the exact reply depends on the reader. To handle 61 xx and 6C xx, wrap these lines in the loop from step 6.

The card executes exactly the bytes you send, and some mistakes cannot be undone. Follow these rules while you learn and test:

  • Start with read-only commands: FF CA 00 00 00 (UID), SELECT, READ BINARY. They tell you whether the reader, the driver and your code work without changing anything.
  • Never send write or authentication commands to a card you don't own or don't know. A wrong write to a MIFARE sector trailer can lock a sector for good, and repeated failed PIN or key attempts can block a card.
  • MIFARE key-load commands (FF 82) only with the factory key or your own keys, on your own test cards. BSD does not publish, and will not help with, recovering or guessing keys of cards that belong to someone else.
  • Use a labelled spare card for anything that writes, and keep a log of what you sent.

The list of commands not to send, with the reasons, is in the Web APDU Tool guide, and the five MIFARE test rules are in the MIFARE test guide.

What you seeLikely causeWhat to do
6E 00 on every commandWrong class: for example an FF reader command that the reader passed to the card, or an ISO command to a card with a proprietary classCheck whether this command is meant for the reader or the card, and which CLA the card's manual uses.
6D 00The card (or the selected application) does not know this instructionSELECT the right application first, or check that the card type is what you expect.
67 00Lc does not match the number of data bytes, or the case is wrongRecount the bytes. Remove Le from case 3 commands.
61 xx and your program stopsT=0 card, response waitingSend GET RESPONSE 00 C0 00 00 xx straight away.
63 00 after an ACS FF commandThe reader could not carry out the operation, for example authentication with the wrong key or a wrong block numberCheck the key location, key type and block, as in the failed-authentication checks.
Works in the ACS Script Tool, fails in your programDifferent bytes, wrong protocol header, or another program holds the cardLog the exact bytes you send and compare. Close QuickView and other tools. See the Script Tool reply guide.
SCardTransmit returns 0x80100008Receive buffer too smallUse at least Ne + 2 bytes (258 for short APDUs).
SCardTransmit returns 0x80100069 or 0x8010000CThe card was removed or is not presentWait for the card with SCardGetStatusChange, then reconnect.
SCardTransmit returns 0x8010000FProtocol mismatch: the header does not match the active protocolUse the protocol returned by SCardConnect.

If the reader is not found at all, or no card is detected, the problem is below the APDU layer: start with the smart card reader troubleshooting guide and the PC/SC reader status checks.

Checked on 30 Nov 2026. ISO/IEC 7816-4 is a paid standard; the field, case and status-word descriptions here are based on the public summaries below and on the PC/SC specifications, written in BSD's own words. ACS command bytes are taken from the ACS manuals cited on BSD's model guides linked above.

BSD Infotech is an independent ACS supplier and integrator, not the manufacturer. ACS, the ACS logo and ACS product names belong to Advanced Card Systems Ltd. MIFARE and DESFire are trademarks of NXP B.V. Windows is a trademark of Microsoft Corporation.

Building software that sends APDUs?

Tell us the reader model, the card type and what your application must do. We help with APDU handling, card commands and PC/SC integration for ACS readers.