Modbus function codes and exceptions

Main function codes (01–06, 15, 16, 23), quantity limits per request, PDU structure and exception responses.

PDU structure

Every Modbus application message consists of a function code (1 byte) and data. All 16-bit fields (address, quantity, register value) are sent high byte first (big-endian): 0x1234 is sent as 12 34. The exception is the Modbus RTU CRC, which is sent low byte first.

Main functions

CodeHexFunctionQuantity per request
010x01Read Coils1…2000
020x02Read Discrete Inputs1…2000
030x03Read Holding Registers1…125
040x04Read Input Registers1…125
050x05Write Single Coil1
060x06Write Single Register1
150x0FWrite Multiple Coils1…1968
160x10Write Multiple Registers1…123
230x17Read/Write Multiple Registersread 1…125, write 1…121

The limits follow from the maximum PDU size (253 bytes). Some devices support less, e.g. at most 32 or 64 registers per request. If a device answers a large request with exception 03, split it.

Function 05: coil value

A coil is not written as 0/1 but as FF 00 (ON) or 00 00 (OFF). Any other value is invalid.

Functions 06 and 16

Function 06 writes one register, 16 writes a block. Use 16 for 32-bit values (FLOAT32, INT32) so both registers are written in one command: with two separate 06 writes the device may briefly see a half-updated value.

Exception responses

If the server receives a valid request but cannot execute it, it returns an exception: the function code with the top bit set (0x80) followed by an exception code.

Request:  01 03 00 64 00 02 ...   read two registers at address 100
Response: 01 83 02 C0 F1          0x83 = 0x03 + 0x80, exception 02
CodeNameTypical cause
01ILLEGAL FUNCTIONfunction not supported (e.g. 04 instead of 03)
02ILLEGAL DATA ADDRESSaddress outside the register map, off-by-one, request spans a gap in the map
03ILLEGAL DATA VALUEinvalid quantity or value
04SERVER DEVICE FAILUREinternal device error
05ACKNOWLEDGEaccepted, processing takes time
06SERVER DEVICE BUSYbusy, retry later
08MEMORY PARITY ERRORmemory error (file record functions)
0AGATEWAY PATH UNAVAILABLEgateway has no route
0BGATEWAY TARGET DEVICE FAILED TO RESPONDdevice behind the gateway did not answer

Distinguish an exception from no response. Per the specification, a server that detects a communication error (parity, CRC) does not respond at all — the client sees a timeout. An exception means communication works and the request itself is the problem.

How to check a request

Paste the frame into the Modbus RTU Frame Parser: it shows the function, address, quantity and data, checks the CRC and decodes exception codes.

Loading the map…

Sources

  1. MODBUS Application Protocol Specification V1.1b3, sections 6 and 7 — Modbus Organization

Updated 2026-10-01