Why 40001 Is Address 0: Modbus Register Addressing Explained

The 4xxxx convention, the one-based versus zero-based trap, and how to convert any documented Modbus address into the value you actually put on the wire.

Almost every "Illegal Data Address" exception traces back to this: the number in the documentation is not the number on the wire.

Modbus has two parallel numbering systems, and they have coexisted for forty years because both are useful. Confusing them is the single most common beginner error in the protocol.

Two numbering systems

Protocol (PDU) addresses are what actually travel in the frame. They are zero-based and range from 0 to 65535.

Convention (documentation) addresses are what device manuals print. They are one-based and carry a prefix digit that identifies the register table.

TableConvention rangePrefixExample
Coils (read/write bits)00001–09999000001 = first coil
Discrete inputs (read-only bits)10001–19999110001 = first discrete input
Input registers (read-only 16-bit)30001–39999330001 = first input register
Holding registers (read/write 16-bit)40001–49999440001 = first holding register

The prefix is metadata, not arithmetic. 40001 is not a large number you send to the device — it says "holding register, first one".

The conversion

Strip the prefix digit, then subtract one:

40001  ->  drop '4'  ->  001  ->  minus 1  ->  0
40011  ->  drop '4'  ->  011  ->  minus 1  ->  10
40108  ->  drop '4'  ->  108  ->  minus 1  ->  107
30001  ->  drop '3'  ->  001  ->  minus 1  ->  0
00001  ->  drop '0'  ->  001  ->  minus 1  ->  0
10001  ->  drop '1'  ->  001  ->  minus 1  ->  0

So a datasheet entry that reads "Holding Register 40011: Setpoint" means PDU address 10, function code 03 to read or 06 to write.

Send 40011 instead and you will get exception 0x02 — assuming the device even has that many registers, which it usually does not.

Why the confusion persists

Three reasons, all legitimate:

  1. The convention predates Modbus TCP and came from Modicon PLC memory layouts, where 4xxxx genuinely was a memory area label. Vendors kept printing it because field technicians recognise it.
  2. Every mainstream tool differs. Some Modbus pollers take the convention address and do the conversion for you. Others take the raw PDU address. A few let you switch, with a setting labelled "addressing: PLC / protocol" or "1-based / 0-based". If a tool has no such setting, check its documentation before concluding your device is broken.
  3. Extended six-digit notation. Some modern devices publish 400001–465536. Same idea: drop the leading 4, subtract one, and you land in 0–65535. Do not confuse 400001 with the five-digit 40001 — they are different registers.

A diagnostic procedure that isolates the problem

Suppose you need the value at "40011" and you get 0x02.

Step 1: read address 0, quantity 1     -> success? table & function code are right.
Step 2: read address 10, quantity 1    -> success? your conversion is right.
Step 3: read address 11, quantity 1    -> success? the datasheet is 0-based, use 10 going forward.
Step 4: read address 40011             -> normally fails; confirms you were off by 40001.

Step 1 is the one people skip. It separates "wrong address" from "wrong function code or wrong table" in a single request. If reading address 0 fails, the problem is not your offset — the device may not implement function code 03 at all, or you are talking to the wrong slave ID.

Function code and table must match

The address prefix and the function code are two statements of the same fact. Mismatching them produces 0x02 even when the address arithmetic is perfect:

You wantFunction codeAddress prefix
Read coils010xxxx
Read discrete inputs021xxxx
Read holding registers034xxxx
Read input registers043xxxx
Write single coil050xxxx
Write single register064xxxx
Write multiple coils15 (0x0F)0xxxx
Write multiple registers16 (0x10)4xxxx

Reading a 3xxxx input register with function 03 is a common slip: 03 reads holding registers only. Input registers need 04, and they are read-only — attempting to write them returns 0x01 (Illegal Function), not 0x02.

Practical habits

You can test the whole conversion chain without hardware: the ModbusLab TCP slave exposes known register values on port 502, and the message lab shows you the exact address bytes your frame is carrying.