Most USB transactions use three packet types to complete a transfer:

  1. Token Packet — Identifies the target and direction
  2. Data Packet — Carries the payload
  3. Handshake Packet — Confirms success or signals an error
Note

Exception: Isochronous transfers use only Token and Data packets — no handshake, no retransmission.


Transaction Sequence

IN Transaction (Device → Host)

Host ──── IN Token ────────► Device
Host ◄─── Data Packet ────── Device
Host ──── ACK ─────────────► Device

The host requests data; the device responds with a data packet; the host acknowledges.

OUT Transaction (Host → Device)

Host ──── OUT Token ───────► Device
Host ──── Data Packet ─────► Device
Host ◄─── ACK ──────────── Device

The host announces a write, sends the data, and the device confirms receipt.

SETUP Transaction (Host → Device, Control Only)

Host ──── SETUP Token ─────► Device
Host ──── DATA0 (8 bytes) ──► Device
Host ◄─── ACK ──────────── Device

Always uses DATA0 PID. The device must accept the setup packet (it cannot NAK a SETUP).


Packet Types in Detail

Token Packet

Sent only by the host to begin every transaction.

Field Size Description
PID 8 bits Packet type: IN (0x69), OUT (0xE1), SETUP (0x2D)
ADDR 7 bits Target device address (0–127)
ENDP 4 bits Target endpoint number (0–15)
CRC5 5 bits Error check over ADDR + ENDP fields

Total size: 3 bytes (including PID)

Data Packet

Contains the actual payload. Can be sent by either host or device depending on direction.

Field Size Description
PID 8 bits DATA0 (0xC3), DATA1 (0x4B), DATA2 (0x87), MDATA (0x0F)
Data 0–1024 bytes Payload (size ≤ endpoint's wMaxPacketSize)
CRC16 16 bits Error check over the entire data field

Data Toggle (DATA0 / DATA1)

USB uses alternating PIDs as a synchronization mechanism:

Transaction 1: DATA0  ──►  (ACK)  ──►  toggle
Transaction 2: DATA1  ──►  (ACK)  ──►  toggle
Transaction 3: DATA0  ──►  (ACK)  ──►  toggle
...
Tip

DATA2 and MDATA are used only in high-speed, high-bandwidth isochronous transfers (multiple transactions per microframe).

Handshake Packet

The simplest packet — just a PID, no payload, no CRC.

PID Sent By Meaning
ACK Host or Device Data received successfully
NAK Device only Endpoint temporarily unable to send/receive (busy)
STALL Device only Endpoint is halted or request is unsupported
NYET Device only (HS) Data accepted, but not ready for next (see Ping Protocol)

Total size: 1 byte (PID only)


Packet Elements

Token-Data-Handshake Packet Types and Elements.png

Element Description
SOP (Start of Packet) Receiver synchronization sequence
PID (Packet Identifier) Indicates packet type and format
Device Address / EP Number Identifies the peripheral target (token packets)
Data Payload 0–1024 bytes; varies with endpoint type and speed
CRC 5 bits for token packets; 16 bits for data packets
EOP (End of Packet) Indicates pending return to idle and position of CRC

IN Transaction — All Possible Outcomes

Example IN Transaction FS or HS.png

Device endpoint to Host Controller

Device Response Meaning Host Action
DATA0/1 → Host ACKs Data successfully received Accept data; toggle
NAK Endpoint has no data ready Retry in next scheduled opportunity
STALL Endpoint is halted Report error to software; endpoint needs CLEAR_FEATURE(ENDPOINT_HALT)
No response (timeout) Device error or disconnected Retry (up to 3 times), then report error

OUT Transaction — All Possible Outcomes

Example OUT Transaction FS or HS.png

Host to device.

Device Response Meaning Host Action
ACK Data received successfully Send next packet; toggle
NAK Endpoint buffer full Retry later (or use Ping Protocol at HS)
NYET (HS only) Data accepted, but not ready for next Switch to Ping before next OUT
STALL Endpoint halted Report error to software
No response (timeout) Device error or disconnected Retry (up to 3 times), then report error

Low-Speed Transaction Variation

Low-Speed Packet from Host Controller.png

Low-speed devices (1.5 Mbps) require special handling when behind a full-speed hub:

  1. Host sends a PRE (Preamble) PID at full speed
  2. Hub enables its low-speed repeater on the target port
  3. Host sends the low-speed token and data packets
  4. Hub disables the low-speed repeater after EOP
Note

The PRE mechanism is only needed between the host and a full-speed hub. High-speed hubs use split transactions instead.


Control Transfer Stages

Control transfers use the Token–Data–Handshake protocol across two or three stages:

Stage Breakdown

Stage Required? Description
Setup Stage Always Single transaction (special OUT variant with SETUP PID); always includes an 8-byte data packet containing request information
Data Stage Optional One or more IN or OUT transactions for moving data between host and device; omitted when no data transfer is needed
Status Stage Always Single IN or OUT transaction with a 0-byte payload; confirms successful completion

Three-Stage Control Transfer (with data)

Three Stage Control Transfer (Read).png

The data stage is included in a three-stage control transfer. The data stage can consist of:

Example: GET_DESCRIPTOR — SETUP stage sends the request, DATA stage returns the descriptor (may take multiple 64-byte transactions), STATUS stage confirms.

Two-Stage Control Transfer (no data)

Two-Stage Control Transfer.png

These transfers omit the data stage because the command or information is incorporated into the Setup packet itself.

Example: SET_ADDRESS — The 7-bit address is included inside the 8-byte data payload of the setup transaction; STATUS stage confirms acceptance.


Maximum Payload Sizes (USB 2.0)

Endpoint Type Low-Speed Full-Speed High-Speed
Control (Data Stage) 8 B 8, 16, 32, or 64 B 64 B
Bulk 8, 16, 32, or 64 B 512 B
Interrupt 1–8 B 1–64 B 1–1024 B
Isochronous 1–1023 B 1–1024 B

Transfer Reliability Summary

Transfer Type Handshake? Retries? Data Toggle? Error Detection
Control Yes Yes (3×) Yes CRC5 (token) + CRC16 (data)
Bulk Yes Yes (3×) Yes CRC5 + CRC16
Interrupt Yes Yes (3×) Yes CRC5 + CRC16
Isochronous No No No (uses DATA0 only at FS) CRC16 only