EE Primers · Communication interfaces · CAN

CAN protocol: what the frame looks like, how errors are flagged, and what rides on top

The physical layer gives CAN a wired-AND bus where a dominant 0 beats a recessive 1. The protocol is built entirely on that one property. A frame starts with an identifier that doubles as its priority, carries 0 to 8 bytes, protects them with a 15-bit CRC, and ends with an acknowledge slot that every receiver writes into. When any node sees something wrong it destroys the frame for everyone with an error flag, and counters decide whether a node that keeps causing errors is allowed to stay on the bus. This page goes through the base and extended data frames field by field, builds real frames bit by bit, then the remote, error and overload frames, fault confinement, and the three higher-layer protocols you meet most: CANopen, J1939 and ISO-TP.

Standards: ISO 11898-1 (data link layer) [1], Bosch CAN 2.0 A/B [2]. The wire itself (transceiver, levels, bit timing, circuits) is on CAN Physical Layer; CAN FD has its own page.

01 · Where the protocol sits

Layers: what the CAN controller does and what software does

LayerDefined inWho implements itWhat it does
Application / higher layerCANopen (CiA 301), SAE J1939, ISO 15765-2 (ISO-TP), UDSSoftware stackGives identifiers and bytes a meaning: node addresses, parameter groups, segmentation of long messages, diagnostics.
Logical link control (LLC)ISO 11898-1CAN controller + driverAcceptance filtering, overload notification, recovery management (automatic retransmission).
Medium access control (MAC)ISO 11898-1CAN controller (hardware)Framing, arbitration, bit stuffing, CRC, ACK, error detection and signalling, fault confinement.
Physical coding (PCS)ISO 11898-1CAN controller (hardware)Bit encoding (NRZ), bit timing, synchronisation, sampling.
Physical medium (PMA/MDI)ISO 11898-2Transceiver, cable, terminationDominant/recessive levels on CANH/CANL. See CAN Physical Layer.
What software seesSoftware never handles stuff bits, CRC or ACK. It writes an identifier, a DLC and up to 8 bytes into a transmit mailbox and reads the same three things out of a receive FIFO. Everything on this page between SOF and the end of the error delimiter happens in the controller's hardware.
02 · Frame types

Four frames and the gap between them

FrameSent byPurposeOn the wire
Data frameAny node with something to sendCarries 0–8 bytes under an identifierSOF · arbitration · control · data · CRC · ACK · EOF (§03–§05)
Remote frameA node asking for dataRequests the data frame with the same identifierLike a data frame with RTR recessive and no data field (§08)
Error frameAny node that detects an errorDestroys the current frame for every node so it is retransmittedError flag (6 bits, overlapping flags 6–12) + 8-bit recessive delimiter (§09)
Overload frameA node that sees a dominant bit in the intermission, or needs timeDelays the next frameOverload flag (6 dominant) + 8-bit recessive delimiter (§10)
Interframe space—Separates a data or remote frame from what came before3-bit intermission, then bus idle; plus 8-bit suspend transmission for error-passive transmitters (§10)
03 · Data frame, base format

The 11-bit frame, field by field

Base (CAN 2.0A) data frame. Widths are to scale in bits, except the data field, drawn at 16 of its 0–64 bits. d = must be dominant, r = must be recessive. Stuff bits are not shown; they go anywhere from SOF to the end of the CRC sequence.
FieldBitsValuePurpose
SOF1dStart of frame. Its recessive-to-dominant edge hard-synchronises every node.
Identifier11ID10…ID0Names the content and sets priority (lower value wins arbitration). MSB first. The top 7 bits must not all be recessive (7F0h–7FFh are not allowed).
RTR1d / rRemote transmission request: dominant in a data frame, recessive in a remote frame. Last bit of the arbitration field.
IDE1dIdentifier extension: dominant means base format.
r01dReserved, sent dominant. (In CAN FD this position became FDF.)
DLC40–8Data length code. Values 9–15 are allowed on the wire in classical CAN but still mean 8 bytes.
Data0–64—Payload, byte 0 first, each byte MSB first.
CRC sequence15—CRC-15, polynomial \(x^{15}+x^{14}+x^{10}+x^{8}+x^{7}+x^{4}+x^{3}+1\) (4599h), over the unstuffed bits from SOF to the end of the data.
CRC delimiter1rGives the receivers a recessive bit before they must drive ACK.
ACK slot1r → dSent recessive by the transmitter; every node that received the frame with a correct CRC overwrites it dominant.
ACK delimiter1rRecessive.
EOF7rEnd of frame. Fixed form, not stuffed; a dominant bit here is a form error (except the last bit, see §10).
Intermission3rPart of the interframe space. No node may start a frame here.

Unstuffed, a base data frame is \(44 + 8n\) bits plus the 3-bit intermission, where \(n\) is the number of data bytes: 111 bits for 8 bytes. Stuffing adds up to \(\lfloor(34 + 8n - 1)/4\rfloor\) bits (§06).

04 · Data frame, extended format

The 29-bit frame: SRR, IDE and the split identifier

Extended (CAN 2.0B) data frame. The 29-bit identifier is split into an 11-bit base identifier and an 18-bit extension, with SRR and IDE between them. Same scale as above.
FieldBitsValuePurpose
SOF1dAs in base format.
Base identifier (ID28…ID18)11—The 11 most significant bits of the 29-bit identifier.
SRR1rSubstitute remote request: sits where a base frame has RTR, always recessive.
IDE1rRecessive: this is an extended frame. Still inside the arbitration field.
Identifier extension (ID17…ID0)18—The 18 least significant bits.
RTR1d / rData or remote frame. End of the 32-bit arbitration field.
r1 · r01 · 1d · dReserved, sent dominant.
DLC … EOF——Identical to the base format.

Why SRR is recessive. When a base frame and an extended frame with the same top 11 identifier bits start together, they agree through ID18. At the next bit the base data frame sends RTR dominant and the extended frame sends SRR recessive, so the base frame wins. If the base frame is a remote frame (RTR recessive) they tie again, and IDE decides: dominant in the base frame. So a base frame always beats an extended frame with the same base identifier, and the two formats can share a bus.

Unstuffed, an extended data frame is \(64 + 8n\) bits plus intermission: 131 bits for 8 bytes, against 111 for base format. Only the top 11 bits are compared against a base frame's identifier; the remaining 18 only arbitrate among extended frames.

05 · Frame builder

Build a frame and watch it on the bus, bit by bit

Pick the format and type, then edit the identifier and data. The builder computes the CRC-15 and inserts stuff bits exactly as a CAN controller does. TXD is node A's controller output, CANH/CANL are the bus, RXD is node B's transceiver output. Stuff bits are marked s (violet); the ACK slot (amber) is the one bit node A sends recessive and node B drives dominant.

Frame builder

CANH is drawn high when dominant (≈ 3.5 V) and CANL low (≈ 1.5 V); both sit at ≈ 2.5 V when recessive. Dashed lines: sample points at 80 % of each bit. Scroll sideways on narrow screens.

Reading the default frame (base, 123h, 00h FFh)

  1. Idle: recessive; CANH and CANL both at 2.5 V.
  2. SOF: node A drives dominant. Every node hard-synchronises to this edge.
  3. Identifier 123h = 001 0010 0011, MSB first. If another node had started at the same moment, arbitration would be decided somewhere in these 11 bits.
  4. RTR, IDE, r0 = 0 0 0, then DLC = 0010. The three dominant control bits plus the first two DLC zeros make five dominant bits in a row, so A inserts a recessive stuff bit.
  5. Data 00h, FFh. Eight zeros and eight ones each force a stuff bit after every fifth identical bit. The receiver removes them using the same rule.
  6. CRC-15 = 63E6h, over the unstuffed bits from SOF to the end of the data; it can itself contain stuff bits.
  7. ACK: A sends a recessive ACK slot; B, having checked the CRC, drives it dominant. A reads dominant and knows at least one node received the frame. Then seven recessive EOF bits and three intermission bits.

Switch to Extended and enter 18FEF100 (a J1939 message, §13) to see SRR and IDE recessive inside the arbitration field and the 18-bit extension after them.

06 · Bit stuffing and frame length

Why stuff bits exist and what they cost

  • Rule. From SOF to the last bit of the CRC sequence, after five consecutive bits of the same value the transmitter inserts one bit of the opposite value. The stuff bit itself counts toward the next run. Receivers delete it.
  • Why. CAN has no clock line; nodes resynchronise only on recessive-to-dominant edges. Stuffing guarantees an edge at least every 10 bits, inside every node's oscillator tolerance (synchronisation edges).
  • Not stuffed: CRC delimiter, ACK, EOF, intermission, error and overload frames. That is deliberate: six identical bits in the stuffed region are a stuff error, so a 6-bit error flag is guaranteed to be seen as an error by every node.
  • Worst case. The stuffed region is \(34 + 8n\) bits (base) or \(54 + 8n\) (extended). The worst-case pattern produces a stuff bit after the first 5 bits and then after every 4, giving \(\lfloor(34 + 8n - 1)/4\rfloor\) extra bits: 24 for an 8-byte base frame, so 135 bits on the wire. Real traffic averages far fewer.
07 · Arbitration and acknowledge

Who wins, and how the transmitter knows it was heard

Contenders (starting together)Decided atWinnerWhy
Base 100h vs base 101hID0100hLower identifier: its first differing bit is dominant.
Base data 123h vs base remote 123hRTRData frameRTR dominant beats recessive; the requester gets its answer in the same slot.
Base data 123h vs extended 048C0000h (base part 123h)RTR / SRRBaseBase RTR dominant vs extended SRR recessive.
Base remote 123h vs extended, same base partIDEBaseRTR and SRR are both recessive; base IDE is dominant.
Two nodes sending the identical frame—BothThey never disagree, so both "win". Two nodes must never send different data under one identifier: they would disagree in the data field, where a disagreement is a bit error, not lost arbitration.

Arbitration is bitwise and non-destructive: a node that sends recessive and reads dominant inside the arbitration field stops transmitting and becomes a receiver of the winning frame, and no bus time is lost. Outside the arbitration field (and the ACK slot) the same mismatch is a bit error. The waveform of three nodes arbitrating is on CAN Physical Layer.

Acknowledge. Every node that received the frame without error, whether or not its acceptance filter wants the frame, drives the ACK slot dominant. The transmitter only learns that at least one node got it, not which one. If no node acknowledges (for example the transmitter is alone on the bus, or every other node runs at a different bit rate), the transmitter flags an ACK error and retries indefinitely, raising its TEC until it goes error-passive (§12).

08 · Remote frame

Asking for data

  • Same layout as a data frame with RTR recessive and no data field. The DLC should equal the length of the data frame being requested.
  • The node that owns the identifier answers with a data frame. If both are sent at once, the data frame wins arbitration at RTR (§07).
  • Remote frames are discouraged in current designs: two requesters with different DLCs for one identifier collide in the control field and produce errors, and CAN FD removed them entirely. CANopen still uses one for node guarding (now replaced by heartbeat); most systems send data periodically instead.
Try itSet the builder (§05) to Remote frame: the data field disappears, the DLC still shows the requested length, and the RTR bit (just after the identifier) turns recessive.
09 · Error frame

How one node destroys a frame for everyone

A node that detects an error sends an error flag, starting at the next bit (for a CRC error, at the bit after the ACK delimiter). An error-active node's flag is 6 dominant bits. That breaks the stuff rule, so every other node detects a stuff, form or bit error and sends its own flag: the flags overlap, and the bus sees between 6 and 12 dominant bits. Each node then sends recessive, waits until it reads the bus recessive, and sends 7 more recessive bits: the 8-bit error delimiter. After the 3-bit intermission the transmitter retries automatically. An error-passive node's flag is 6 recessive bits, which the other nodes cannot see, so a node with a bad record cannot destroy other nodes' frames.

10 · Overload frame and interframe space

The gap between frames

  • Intermission: 3 recessive bits after EOF (or after an error or overload delimiter). No frame may start here. A dominant bit in the first or second intermission bit triggers an overload frame (the last button above). A dominant bit in the third intermission bit is taken as SOF of a new frame, which tolerates small clock differences between nodes.
  • Overload frame: overload flag (6 dominant bits) plus an 8-bit recessive overload delimiter; overlapping flags give up to 7 dominant bits. It does not raise any error counter and the previous frame stays valid. It is also sent by a receiver that sees a dominant bit in the last bit of EOF. Old controllers could send up to two to request time before the next frame; modern controllers never need to.
  • Bus idle: after the intermission, any node may start with SOF.
  • Suspend transmission: an error-passive node that has just transmitted must wait an extra 8 recessive bits before it may start another frame. Error-active nodes get the bus first, so a misbehaving node cannot monopolise it.
11 · Error detection

The five error types

ErrorDetected byWhereConditionError flag starts
Bit errorTransmitterAny bit it sends, except the arbitration field and ACK slotBit read back differs from bit sentNext bit
Stuff errorEvery nodeSOF to end of CRC sequenceSix consecutive identical bitsNext bit
CRC errorReceiversCRC sequenceComputed CRC differs from received CRCBit after the ACK delimiter
Form errorEvery nodeCRC delimiter, ACK delimiter, EOF, error and overload delimitersDominant bit in a fixed recessive field (receivers ignore the last bit of EOF)Next bit
ACK errorTransmitterACK slotReads recessive: nobody acknowledgedNext bit
How good is itThe five checks together leave a residual error probability below about \(4.7\times10^{-11}\) times the message error rate (Bosch's figure for classical CAN). The weak point is stuff bits: a single bit flip that creates or deletes a stuff bit shifts the rest of the frame and can occasionally slip past the CRC. CAN FD fixed this with a stuff count and a longer CRC.
12 · Fault confinement

Error counters and the three node states

EventTECREC
Receiver detects an error—+1
Receiver sees a dominant bit right after sending its error flag (it was the first to notice)—+8
Transmitter sends an error flag (exceptions: error-passive ACK error; stuff error on a recessive stuff bit in arbitration)+8—
Bit error while sending an active error flag or overload flag+8+8
14 consecutive dominant bits after an error flag (then each further 8)+8+8
Frame transmitted successfully (ACK received, no error to end of EOF)−1—
Frame received successfully—−1 (if REC > 127: set to 119–127)

Because a transmitter's error costs 8 and a success earns back 1, a node keeps its standing as long as fewer than about one frame in eight fails. A node that is the cause of errors (a broken transmitter, a wrong bit rate) climbs quickly; nodes that merely observe them climb slowly.

Fault confinement simulator

StateEntered whenError flag it sendsOther effects
Error activeTEC ≤ 127 and REC ≤ 1276 dominant: destroys the frame for allNormal operation.
Error passiveTEC > 127 or REC > 1276 recessive: invisible unless it is the transmitter8-bit suspend transmission after each frame it sends.
Bus offTEC > 255None: the node may not drive the busLeaves after 128 occurrences of 11 consecutive recessive bits (many controllers also need software to request recovery); counters reset to 0.
13 · Higher-layer protocols

CANopen, J1939 and ISO-TP

The data link layer only moves an identifier and up to 8 bytes. Every real network adds a convention for what the identifiers mean and how to carry more than 8 bytes. Three dominate: CANopen in industrial automation and robotics, SAE J1939 in trucks, buses and off-highway machines, and ISO-TP (ISO 15765-2) for diagnostics in cars.

CANopen: function code plus node ID

CANopen (CiA 301) uses base-format frames. The 11-bit identifier, called the COB-ID, is a 4-bit function code followed by a 7-bit node ID (1–127). The function code sets the priority: network management first, process data next, configuration and heartbeats last. Each node exposes an object dictionary (index 16 bits, sub-index 8 bits): PDOs carry real-time process data mapped from dictionary entries with no protocol overhead, and SDOs read or write any dictionary entry with a confirmed request/response.

ObjectCOB-IDDirectionUse
NMT000hMaster → allStart, stop, reset nodes
SYNC080hProducer → allSampling and actuation trigger for synchronous PDOs
EMCY080h + nodeNode → allEmergency error code
TIME100hProducer → allTime of day
TPDO1–4180h / 280h / 380h / 480h + nodeNode → networkProcess data out of the node
RPDO1–4200h / 300h / 400h / 500h + nodeNetwork → nodeProcess data into the node
SDO response / request580h / 600h + nodeServer → client / client → serverObject dictionary access
Heartbeat (NMT error control)700h + nodeNode → allNode state, periodically

CANopen COB-ID decoder

SAE J1939: priority, PGN and source address in 29 bits

J1939 uses extended frames at 250 or 500 kbit/s. The 29-bit identifier is three priority bits, an 18-bit parameter group number (PGN) that says what the data is, and the 8-bit source address of the sender. When the PDU format byte (PF) is below 240 (PDU1), the PDU specific byte (PS) is a destination address and is not part of the PGN; at 240 and above (PDU2) the message is broadcast and PS extends the PGN. Messages longer than 8 bytes use the transport protocol: a connection-management frame (TP.CM, PGN 60416), either broadcast (BAM) or with RTS/CTS handshaking, followed by numbered data-transfer frames (TP.DT, PGN 60160) of 7 bytes each.

J1939 view of the 29-bit identifier. Priority 0 is highest; it sits at the top of the identifier so it dominates arbitration.

J1939 identifier decoder

Try 18FEF100 (vehicle speed, CCVS), 18FECA00 (active diagnostic codes, DM1), 18EAFF00 (request to all) or 1CECFF00 (transport protocol, BAM).

ISO-TP: carrying up to 4095 bytes over 8-byte frames

ISO 15765-2 is the transport layer under UDS diagnostics. The first one or two bytes of each frame are a protocol control information (PCI) field whose high nibble gives the frame type. A message of up to 7 bytes goes in one single frame. A longer one starts with a first frame carrying the 12-bit total length and 6 data bytes; the receiver answers with a flow control frame giving the block size (how many frames before the next flow control, 0 = all) and STmin (minimum gap between frames); the sender then sends consecutive frames of 7 data bytes with a 4-bit sequence number that wraps 1…F, 0, 1….

TypePCI (hex nibbles)Data bytesMeaning
Single frame (SF)0L1–7L = length
First frame (FF)1L LL6LLL = total length, 8–4095
Consecutive frame (CF)2N≤ 7N = sequence number
Flow control (FC)3S BS ST—S: 0 continue, 1 wait, 2 overflow · BS block size · ST STmin

ISO-TP segmenter

14 · Self-check

Questions

A base data frame with identifier 123h and an extended frame whose top 11 bits are 123h start together. Who wins, and at which bit?

The base frame, at the bit after ID18/ID0: base RTR is dominant, extended SRR is recessive.

Where are stuff bits inserted in identifier 000h with DLC 0?

SOF, the 11 identifier bits, RTR, IDE, r0 and DLC are 19 dominant bits in a row. A recessive stuff bit goes in after every fifth: after dominant bits 5, 10 and 15, so the run on the wire is 00000 1 00000 1 00000 1 0000 followed by the CRC.

Who drives the ACK slot dominant?

Every node that received the frame with a correct CRC, whether or not it wants the frame. The transmitter sends it recessive and checks that someone overwrote it.

Why can an error flag be anywhere from 6 to 12 dominant bits long?

The first node sends 6. The others may notice only when the 6th identical bit arrives (a stuff error) and then send their own 6, so the flags overlap by 0 to 5 bits: 6 to 12 in total.

A receiver gets a CRC mismatch. When does its error flag start, and why not immediately?

At the bit after the ACK delimiter. It must first let the CRC and ACK delimiters pass so it does not corrupt the ACK of nodes that received correctly; its flag then appears in EOF, where the other nodes see a form error.

A transmitter is alone on the bus. What happens to its TEC and state?

Every attempt ends with an ACK error: TEC +8. After 16 attempts TEC = 128 and it goes error-passive. From then on the ACK-error exception applies (a passive transmitter does not count an ACK error), so it stays error-passive instead of going bus-off.

Decode J1939 identifier 18FEF100.

Priority 6, PF FEh = 254 (PDU2, broadcast), PS F1h, so PGN = FEF1h = 65265 (cruise control / vehicle speed, CCVS), source address 00h (engine).

How many CAN frames does a 20-byte ISO-TP message take?

A first frame carrying 6 bytes, then 14 bytes in two consecutive frames (7 + 7): three frames from the sender plus one flow control frame from the receiver.

15 · Further reading

References

  1. ISO 11898-1:2015, Road vehicles — Controller area network (CAN) — Part 1: Data link layer and physical signalling.
  2. Bosch, CAN Specification Version 2.0 (Part A: standard format, Part B: extended format), 1991.
  3. CAN in Automation, CiA 301: CANopen application layer and communication profile.
  4. SAE J1939-21, Data Link Layer, and SAE J1939-71, Vehicle Application Layer.
  5. ISO 15765-2:2016, Road vehicles — Diagnostic communication over CAN (DoCAN) — Part 2: Transport protocol and network layer services.
  6. Texas Instruments, Introduction to the Controller Area Network (CAN), SLOA101. Link
CAN Physical Layer →CAN FD →Automotive Ethernet →UART / RS-485 / LIN →