← Articles
Modbus/11 min read/— views

Why Modbus TCP Stops You at 125 Registers Per Read

The 253-byte PDU limit that sets every quantity cap, the 7-byte MBAP header whose Length field isn't the frame length, 0-based addressing, and why 32-bit word order is not in the standard at all.

Modbus TCPRegistersNetworkingTroubleshooting

The manual said read 200 registers starting at 40001, so that went into the driver as written. What came back was not data — it was Illegal Data Address. Changing the address to 0 did the same thing. The device is not broken. There was never room for 200.

A Modbus TCP request is short. A Read Holding Registers request is twelve bytes. Count those twelve bytes by hand once and half of what you meet in the field explains itself.

A twelve-byte Read Holding Registers request splits into a 7-byte MBAP header and a 5-byte PDU, and the Length field at bytes 4 to 5 holds 6 — the Unit ID plus the PDU, not the length of the frame Read Holding Registers request — 12 bytes Length = 6 Transaction ID Protocol ID = 0 Unit ID PDU Length 0001 0000 01 03 0000 0002 0006 01 23 45 6 789 1011 MBAP — 7 bytes FC 03 · start · quantity Length = Unit ID + PDU

Every frame below was assembled by hand from the field definitions in the MODBUS Application Protocol Specification V1.1b3 and the MODBUS Messaging on TCP/IP Implementation Guide V1.0b. These are not captures lifted off a real device. What they do give you is length arithmetic you can count and check yourself.

Seven bytes of MBAP, then the PDU

request    00 01   00 00   00 06   01   03   00 00   00 02

The first seven bytes are the MBAP header. Transaction ID 00 01, Protocol ID 00 00, Length 00 06, Unit ID 01. Protocol ID is fixed at zero for Modbus; a non-zero value means something that isn't Modbus is sitting on that socket.

The Length field is the trap. It is not the length of the frame. It is the count of bytes that follow it — Unit ID 1 plus PDU 5 = 6. The whole frame is twelve bytes and the field says six. When a hand-rolled parser loses frame boundaries in the TCP stream, this is nearly always why.

The PDU is five bytes, 03 00 00 00 02: function code 3, start address 0, quantity 2. Addresses and data items are big-endian, and the specification states that outright.

The response comes back like this.

response   00 01   00 00   00 07   01   03   04   01 2C 00 00

Length has grown to 7: Unit ID 1 + function code 1 + byte count 1 + data 4. The byte count 04 is two registers at two bytes each. The values are 01 2C = 300 and 00 00 = 0. Transaction ID 00 01 came back exactly as sent — the implementation guide tells the server to copy it into the response, and a gateway that always returns zero instead takes away your ability to overlap requests. That case has its own walkthrough.

A refusal is two bytes of PDU and done.

exception  00 01   00 00   00 03   01   83   02

The function code is 83, not 03 — the original code with 0x80 added. The 02 behind it is exception code ILLEGAL DATA ADDRESS, and §7 of the specification defines codes 01, 02, 03, 04, 05, 06, 08, 0A and 0B. The two a gateway hands back, 0A GATEWAY PATH UNAVAILABLE and 0B GATEWAY TARGET DEVICE FAILED TO RESPOND, mean the problem is the serial side behind the gateway rather than the device you were aiming at. What to do per code is in exception code troubleshooting.

253 bytes is what creates every quantity cap

The specification caps the PDU at 253 bytes. That number comes from the 256-byte serial ADU minus one address byte and two CRC bytes, and Modbus TCP carries the same PDU. So the largest TCP frame is 7 + 253 = 260 bytes.

Every quantity limit falls out of that. A Read Holding Registers response PDU is function code 1 + byte count 1 + 2N register bytes.

253 - 1 - 1 = 251 bytes
251 / 2 = 125.5  ->  125 registers

The cap written in the specification is exactly 125 (0x7D). Write Multiple Registers is tighter because the request side carries more: function code 1 + start 2 + quantity 2 + byte count 1 = 6 bytes of overhead, leaving 247, which divided by two is 123.5 and caps at 123 (0x7B). That matches the specification's number too.

Function codeNameCap per request
01Read Coils2000 (0x7D0)
02Read Discrete Inputs2000 (0x7D0)
03Read Holding Registers125 (0x7D)
04Read Input Registers125 (0x7D)
0FWrite Multiple Coils1968 (0x7B0)
10Write Multiple Registers123 (0x7B)
17Read/Write Multiple Registers125 read / 121 write (0x79)

The Illegal Data Address from the opening ends in that table. 200 is more than 125. The device did not fail to find an address; it rejected a quantity — and exception code 02 covers address and quantity together, so it will not tell the two apart for you.

In practice the number worth more suspicion than the specification's cap is the one the device advertises. I have met several that document 125 and quietly time out past about 60. Walking the quantity up during commissioning until it breaks, and writing down where, costs less than trusting the manual.

Addresses are 0-based, and 40001 is not in the specification

The specification's data model numbers items from 1. The address carried in the PDU is 0-based. As the specification puts it directly, item number 1 goes out as address 0. The 00 00 in the request above is the first holding register.

Notations like 40001, 4x and 30001 are not in the specification text. They are a Modicon-era convention that survives in manuals: the leading 4 is the data area and the four digits behind it count from one. So 40001 is PDU address 0 and 40101 is 100. Which of those numbers your driver expects is decided by the driver's documentation, and the specification will not answer it.

Settling it takes one test. Pick a register whose value you know and read both address N and N-1. Whichever returns the value is that driver's convention. Write it down rather than guessing — what it costs not to record the convention on the register map is covered in register map commissioning.

The order of a 32-bit value is not in the specification at all

The specification states that addresses and data items are big-endian. The data item it means is one 16-bit register. How you pair two registers into a 32-bit integer or an IEEE 754 float is not in the MODBUS Application Protocol Specification.

Not in the specification means the vendor decides. Two byte orders times two word orders gives four combinations, and all four are out there. A float that reads as decimal nonsense, or as something like 1e-38, is word order almost every time.

This is where the hours go, made worse by every driver naming the option differently. The order to try the combinations in is in byte and word order.

Signed versus unsigned has the same shape. Whether FF FF in a register is 65535 or -1 is not something the specification says. It only breaks on values that go negative, like a temperature, which makes it a bug first discovered in winter.

On TCP the Unit ID should be 0xFF

The Unit ID is the old serial slave address slot. On TCP the IP address identifies the device, so the byte has nothing to do, and the implementation guide therefore says to use 0xFF. It adds that 0x00 is also accepted.

Putting 1 there works on most devices in practice, because they ignore it. Gateways are where it matters. There the byte becomes the slave number on the serial side, and 0xFF reaches nothing at all. The routing rules are in gateway Unit ID routing.

Work the poll rate back from the quantity cap

Most people set the poll rate first. That is backwards. Count the requests first.

A thousand contiguous registers is a minimum of eight requests, because they come 125 at a time. Scattered addresses split into more blocks, and every block costs a round trip. Asking for eight round trips inside a 100 ms period is asking for 12.5 ms per round trip, and with a serial gateway in the path that budget never existed.

My own defaults are plain: 500 ms to 1 s for alarms and status bits, 2 to 5 s for analogue values headed into a trend, 60 s or manual for nameplate data and setpoints that do not move. Those are my defaults, not specification values. Reading a temperature every 200 ms has never bought me anything.

Merging blocks almost always pays better than shortening the period. Fewer requests is cheaper for the network and the PLC than a faster cycle. How to decide the block boundaries is in poll block optimization, and what happens when the round trips cannot keep up with the period is in polling timeouts.

Cut in this order

When communication is failing, do not start at the screen bindings. Prove the protocol request first.

  1. TCP port 502 opens — the Modbus port registered with IANA
  2. Protocol ID arrives as 00 00 — otherwise this isn't Modbus
  3. Unit ID — 0xFF or 0x00 direct, the real slave number behind a gateway
  4. Function code — do exceptions come back with 0x80 added
  5. Address and quantity — 0-based, and inside the caps in the table
  6. Data interpretation — word order, signed/unsigned, scaling

Suspecting interpretation before you have cleared the first five is usually wrong. Steps 1 through 5 announce themselves as an exception code or a timeout; only step 6 produces the "communication is fine but the number is strange" shape. Which of those two symptoms you have is what decides where to start.

Modbus TCP also appears as Communication Profile Family 15 in IEC 61784-1, but the document people actually work from is the Modbus Organization's V1.1b3. Where a device manual disagrees with the specification, assume the manual and read it once — far more often the vendor has filled in a slot the specification left undefined than broken a rule it set.