Modbus Data Types Explained: 16-Bit, 32-Bit Float, IEEE 754 & Byte Order Guide
A complete technical reference for automation engineers and PLC programmers decoding 16-bit registers, 32-bit single-precision floats, signed integers, and mastering word-swapping endianness across industrial equipment.
When the Modicon corporation authored the original Modbus protocol specification in 1979, industrial computing was rooted in 16-bit microprocessor architectures. The protocol designers created an elegant, minimalist framework where all data was either a single binary bit or a 16-bit register word. However, modern industrial automation requires logging decimal temperatures, high-precision pressures, 32-bit energy totals, and ASCII alphanumeric serial numbers.
Because the original Modbus protocol does not natively specify how to represent 32-bit or 64-bit structures, automation vendors implemented differing byte and word storage formats. Understanding how these data types map to 16-bit Modbus memory tables is essential for eliminating register decoding errors, preventing corrupted SCADA trends, and ensuring reliable communications.
1. The Four Fundamental Modbus Memory Tables
Every Modbus slave device stores data within four distinct tables categorized by bit-width and access permissions:
| Table Name | Object Type | Access | Address Range | Function Codes |
|---|---|---|---|---|
| Discrete Inputs | 1-Bit (Binary) | Read-Only | 10001 – 19999 (0x0000) | FC02 (Read Discrete Inputs) |
| Coils | 1-Bit (Binary) | Read-Write | 00001 – 09999 (0x0000) | FC01 (Read), FC05 (Write Single), FC15 (Write Multiple) |
| Input Registers | 16-Bit Word | Read-Only | 30001 – 39999 (0x0000) | FC04 (Read Input Registers) |
| Holding Registers | 16-Bit Word | Read-Write | 40001 – 49999 (0x0000) | FC03 (Read), FC06 (Write Single), FC16 (Write Multiple), FC23 (Read/Write) |
2. 16-Bit Data Types: Integer Representation
A single 16-bit Modbus register contains 2 bytes (16 bits) of information, ranging in hex representation from 0x0000 to 0xFFFF. Depending on how your client or SCADA system parses the bits, a 16-bit register represents:
- Unsigned 16-Bit Integer (UInt16): Values from
0to65,535. Frequently used for raw ADC counts, timer presets, and status bitmasks. - Signed 16-Bit Integer (Int16 / Two's Complement): Values from
-32,768to+32,767. The most significant bit (bit 15) serves as the sign flag. Widely utilized for ambient temperature readings that span negative and positive values (e.g., -20°C to +85°C). - Scaled Integer (Fixed-Point): Because older PLCs lacked floating-point math co-processors, engineers adopted fixed scaling. For instance, a pressure transmitter might transmit
1013in a 16-bit holding register to indicate101.3 kPa, requiring the SCADA driver to apply a scale factor of 0.1.
3. 32-Bit Floating Point: IEEE 754 Standard
Scientific measurements—such as flow rates in m³/hr, power factors, and analytical pH readings—demand wide dynamic range and decimal precision. Automation devices achieve this using the IEEE 754 single-precision floating-point format, which spans 32 bits (4 bytes).
In IEEE 754, the 32 bits are allocated as follows:
- Sign Bit (S - 1 bit): Bit 31.
0represents positive,1represents negative. - Exponent (E - 8 bits): Bits 30 to 23. Biased by 127.
- Mantissa / Fraction (M - 23 bits): Bits 22 to 0. Normalized significand precision.
The mathematical value is computed as: (-1)^S × (1 + M) × 2^(E - 127).
To transmit a 32-bit float over Modbus, the master must read two consecutive 16-bit registers (for example, Holding Registers 40001 and 40002). However, how those 4 bytes are ordered across the two registers varies by PLC brand!
4. The Endianness Challenge: Word and Byte Ordering
Standard Modbus protocol requires that each individual 16-bit register transmits its high byte first (Big-Endian byte order). However, the protocol says nothing about which 16-bit register carries the high word (MSW) versus the low word (LSW) when packing a 32-bit number. This creates four common byte arrangements:
| Format Name | Byte Sequence | Word Order | Common Hardware / Vendor |
|---|---|---|---|
| Big-Endian (ABCD) | Byte 1, Byte 2, Byte 3, Byte 4 | High Word First, High Byte First | Siemens S7, Modicon Quantum, Yokogawa |
| Mid-Little / Word-Swapped (CDAB) | Byte 3, Byte 4, Byte 1, Byte 2 | Low Word First, High Byte First | Schneider Electric, ABB, GE Fanuc, AutomationDirect |
| Byte-Swapped (BADC) | Byte 2, Byte 1, Byte 4, Byte 3 | High Word First, Low Byte First | Custom DSP Controllers, Embedded ARM Microcontrollers |
| Little-Endian (DCBA) | Byte 4, Byte 3, Byte 2, Byte 1 | Low Word First, Low Byte First | Intel x86 Native, Beckhoff TwinCAT, Omron |
Real-World Hex Example: Decoding 1234.56
The floating-point number 1234.56 in IEEE 754 hexadecimal notation is 0x449A51EC (where Byte A=44, B=9A, C=51, D=EC).
- ABCD (Big-Endian): Reg 1 =
0x449A, Reg 2 =0x51EC→ Decodes as1234.56 - CDAB (Word-Swapped): Reg 1 =
0x51EC, Reg 2 =0x449A→ Decodes as1234.56 - If your client expects ABCD but receives CDAB: It will interpret
0x51EC449A, which computes to1.269 × 10^11instead of1234.56!
5. 32-Bit & 64-Bit Integers and ASCII Strings
Beyond single-precision floats, modern Modbus slave devices frequently output extended data formats:
- 32-Bit Unsigned Integer (UInt32 / DWord): Covers values from
0to4,294,967,295. Standard in electrical power meters (e.g., Schneider PM5000, Socomec) logging cumulative energy totals in watt-hours (Wh). - 32-Bit Signed Integer (Int32 / DInt): Covers values from
-2,147,483,648to+2,147,483,647. - 64-Bit Double-Precision Float (IEEE 754 Double): Spans 4 consecutive 16-bit registers (64 bits). Provides 53 bits of precision (15–17 significant decimal digits) for high-precision custody transfer gas chromatographs and mass flow meters.
- ASCII Character Strings: Each 16-bit register stores two 8-bit ASCII characters (High Byte = Char 1, Low Byte = Char 2). For example, the string "PUMP" is encoded in two registers as
0x5055('P', 'U') and0x4D50('M', 'P').
6. Simulating and Testing Modbus Data Types
Debugging endianness mismatches and data type formatting in a live production plant is risky and time-consuming. Modbus Simulator Desktop allows automation engineers to test every data type configuration offline on Windows before connecting to physical PLCs.
Python Example: Decoding Modbus Floats with PyModbus
When writing custom automation scripts in Python, the pymodbus.payload.BinaryPayloadDecoder utility simplifies byte and word swapping:
from pymodbus.client import ModbusTcpClient
from pymodbus.payload import BinaryPayloadDecoder
from pymodbus.constants import Endian
client = ModbusTcpClient('127.0.0.1', port=502)
client.connect()
# Read 2 consecutive holding registers starting at address 0
response = client.read_holding_registers(address=0, count=2, slave=1)
if not response.isError():
# Example 1: Big-Endian (ABCD)
decoder_abcd = BinaryPayloadDecoder.fromRegisters(
response.registers,
byteorder=Endian.BIG,
wordorder=Endian.BIG
)
val_abcd = decoder_abcd.decode_32bit_float()
print(f"Decoded Float (ABCD): {val_abcd:.2f}")
# Example 2: Word-Swapped (CDAB)
decoder_cdab = BinaryPayloadDecoder.fromRegisters(
response.registers,
byteorder=Endian.BIG,
wordorder=Endian.LITTLE
)
val_cdab = decoder_cdab.decode_32bit_float()
print(f"Decoded Float (CDAB): {val_cdab:.2f}")
client.close()
7. Troubleshooting Common Modbus Data Type Pitfalls
- Offset Confusion (0-Based vs. 1-Based Addressing): Some SCADA platforms expect register address
40001to correspond to protocol packet address0x0000, while others expect0x0001. If your decoded float shows corrupted bytes shifted by one word, verify whether your master client uses 0-based or 1-based indexing. - Register Boundaries: Never attempt to read half of a 32-bit float. If a float spans registers 40001 and 40002, polling only 40001 will return a raw 16-bit integer that bears no resemblance to the actual floating-point value.
- Negative Numbers Transmitted as 65535: If a client reads
65535when the sensor measures-1, the client driver is configured to treat the 16-bit register as an unsigned UInt16 rather than a signed Int16.
8. Frequently Asked Questions (FAQs)
What are the fundamental data types defined in the Modbus protocol?
The official specification defines only 1-bit binary objects (Coils and Discrete Inputs) and 16-bit word registers (Holding Registers and Input Registers). All 32-bit, 64-bit, and string representations are assembled by combining multiple contiguous 16-bit words.
How does Modbus represent 32-bit floating-point numbers?
Modbus pairs two 16-bit registers using IEEE 754 single-precision format. The master must query 2 consecutive registers and decode them according to the server's word order.
What is the difference between Big-Endian (ABCD) and Word-Swapped (CDAB)?
ABCD places the most significant word first, whereas CDAB places the least significant word first. Both keep bytes within each 16-bit word in high-byte-first order. CDAB is dominant in Schneider and ABB PLCs.
Why do I see nonsensical numbers (like NaN or 1.23e-38) when reading Modbus floats?
This indicates an endianness mismatch between the client's decoding mode and the slave's register transmission order. Flipping word endianness in your SCADA tag configuration fixes the issue.
How can I simulate and test different Modbus data types without physical hardware?
Modbus Simulator Desktop enables you to configure virtual registers in ABCD, CDAB, BADC, or DCBA formats and verify client driver compatibility on Windows over loopback TCP or COM ports.