Your BMS driver asks for a "function code", a gateway log shows FC16, a VFD manual says "supports functions 3, 6 and 16 only", and a capture shows 0x90. All of these are Modbus function codes: the one-byte instruction at the start of every Modbus request that says read this table or write that value.
This guide explains each one in plain English: the full table from the specification, real frames, the limits per request, and a method to see each code at work with a free simulator.
What is a Modbus function code?
A Modbus function code is a single byte, from 1 to 127, that tells the device (the server, or "slave") which action to perform. It sits right after the unit ID in Modbus RTU and right after the 7-byte MBAP header in Modbus TCP. The rest of the request (address, quantity, values) depends on the code.
The device answers with the same function code when it succeeds. When it receives the request intact but refuses it, it answers with the function code plus 0x80 (128) and a one-byte exception code. That is why 03 comes back as 0x83 and 16 (0x10) comes back as 0x90. The full list of reasons is in All Modbus exception codes.
The MODBUS Application Protocol Specification V1.1b3 (free on modbus.org) defines the public codes in the table below. Codes 65 to 72 and 100 to 110 are user-defined: a vendor may use them for its own features. Codes 128 to 255 are never requests: they are exception replies.
Modbus function codes list: the full table
These are the public function codes from the specification. The first eight are the ones you will use almost every day.
| Code (dec) | Hex | Name | Max per request |
|---|---|---|---|
| 01 | 0x01 | Read Coils | 2000 bits |
| 02 | 0x02 | Read Discrete Inputs | 2000 bits |
| 03 | 0x03 | Read Holding Registers | 125 registers |
| 04 | 0x04 | Read Input Registers | 125 registers |
| 05 | 0x05 | Write Single Coil | 1 bit |
| 06 | 0x06 | Write Single Register | 1 register |
| 15 | 0x0F | Write Multiple Coils | 1968 bits |
| 16 | 0x10 | Write Multiple Registers | 123 registers |
| 07 | 0x07 | Read Exception Status (serial line only) | 8 bits |
| 08 | 0x08 | Diagnostics (serial line only) | — |
| 17 | 0x11 | Report Server ID (serial line only) | — |
| 22 | 0x16 | Mask Write Register | 1 register |
| 23 | 0x17 | Read/Write Multiple Registers | 125 read / 121 write |
| 43 | 0x2B | Read Device Identification (MEI type 14) | — |
The specification also lists 11 and 12 (serial event counters), 20 and 21 (file records) and 24 (FIFO queue), which you will rarely meet. Two traps in this table:
- Decimal vs hex. Manuals mix them. "Function 10" in a hex manual is 16 decimal (write multiple registers), not 10. "FC 0x0F" is 15. When in doubt, look at the name, not the number.
- The "max per request" values are protocol limits. Many devices accept less and answer exception 03 for a bigger block.
How function codes map to the four data tables
Modbus has four data tables. Each one has its own read code, and only two of them can be written:
| Table | Old prefix | Size | Read | Write one | Write many |
|---|---|---|---|---|---|
| Coils | 0x (00001) | 1 bit, read/write | 01 | 05 | 15 |
| Discrete inputs | 1x (10001) | 1 bit, read-only | 02 | — | — |
| Input registers | 3x (30001) | 16 bits, read-only | 04 | — | — |
| Holding registers | 4x (40001) | 16 bits, read/write | 03 | 06 | 16 |
The prefix in a register number is not sent on the wire. "Register 40012" means function 03 (or 06/16), address 11: the 4 picks the function code, and the address counts from 0. More in 40001 vs address 0.
Choosing between 03 and 04? The device decides, not you: the map tells you whether a value lives in holding or input registers, and asking the wrong table usually returns exception 02 or 01. More in Holding registers vs input registers.
The read function codes (01, 02, 03, 04)
Function code 01: Read Coils
FC01 reads 1 to 2000 on/off outputs. The request carries a start address and a quantity. The reply packs the bits eight per byte: the first coil requested is the lowest bit of the first data byte, and unused bits in the last byte are filled with zeros.
Example: you read 10 coils from address 0 on unit 1 and get 01 01 02 05 01 7B 6C. The two data bytes are 0x05 and 0x01. 0x05 is binary 0000 0101, so coils 0 and 2 are ON; 0x01 in the second byte means coil 8 is ON. Everything else is OFF.
Function code 02: Read Discrete Inputs
FC02 works exactly like FC01 but reads the read-only bit table: alarms, end switches, run feedback, filter status. Same 2000-bit limit, same packing.
Function code 03: Read Holding Registers
FC03 reads 1 to 125 consecutive 16-bit registers. It is the workhorse of building automation and energy metering: setpoints, measurements and configuration usually live here.
Example: read the return air temperature, a float32 stored in holding registers 1 and 2 of unit 1 (the values come from the screenshot later in this article).
| Direction | Bytes (hex) | Meaning |
|---|---|---|
| Request | 01 03 00 01 00 02 95 CB |
Unit 1, FC03, address 1, quantity 2, CRC |
| Response | 01 03 04 41 B2 25 88 54 DE |
4 data bytes: 0x41B2, 0x2588 |
Joined in ABCD order, 0x41B22588 is the float 22.27. The function code only moves raw 16-bit words; the data type and byte order are your job. If the result looks crazy, see Modbus float byte order or paste the two words into the free Modbus register converter.
Function code 04: Read Input Registers
FC04 has the same format and 125-register limit as FC03, but reads the read-only input register table, where many energy meters keep their measurements. Example: 02 04 00 00 00 02 71 F8 asks unit 2 for input addresses 0 and 1; the reply 02 04 04 00 00 43 66 79 9E carries 0x0000 and 0x4366, which in CDAB (word swap) order is the float 230.0, a voltage.
The write function codes (05, 06, 15, 16)
Function code 05: Write Single Coil
FC05 turns one coil on or off. The value field is fixed: 0xFF00 = ON, 0x0000 = OFF. The specification says any other value is illegal, so a device answers exception 03 if a driver sends 0x0001 for "on".
| Direction | Bytes (hex) | Meaning |
|---|---|---|
| Request | 01 05 00 00 FF 00 8C 3A |
Unit 1, FC05, coil 0, ON |
| Response | 01 05 00 00 FF 00 8C 3A |
Exact echo of the request |
A normal FC05 reply is an echo. It proves the device accepted the command, not that the output moved (an interlock or hand/off/auto switch may block it).
Function code 06: Write Single Register
FC06 writes one 16-bit value to one holding register. Like FC05, the reply is an echo.
| Direction | Bytes (hex) | Meaning |
|---|---|---|
| Request | 01 06 00 0B 00 91 39 A4 |
Unit 1, FC06, address 11, value 145 |
| Response | 01 06 00 0B 00 91 39 A4 |
Echo |
With a ×0.1 scale, raw 145 is a setpoint of 14.5. FC06 cannot write a float32 or 32-bit value safely: one half would be written alone.
Function code 15: Write Multiple Coils
FC15 (0x0F) writes 1 to 1968 coils in one request. The values are packed eight per byte, lowest bit first, exactly like the FC01 reply. The device answers with the start address and quantity, not the data.
Function code 16: Write Multiple Registers
FC16 (0x10) writes 1 to 123 consecutive holding registers. The request adds a byte count (2 × quantity) before the values; the reply returns only the start address and quantity.
Writing value 145 to address 11 with FC16:
| Direction | Bytes (hex) | Meaning |
|---|---|---|
| Request | 01 10 00 0B 00 01 02 00 91 66 87 |
FC16, address 11, quantity 1, 2 bytes, value 0x0091 |
| Response | 01 10 00 0B 00 01 70 0B |
Address 11, quantity 1 written |
FC06 vs FC16: which one should you use?
Use FC16 for anything that spans two or more registers (float32, int32, 64-bit values, strings). For a single register both usually work, but some devices (some VFDs, for example) only implement FC16 and answer exception 01 to FC06: send FC16 with quantity 1 instead (most drivers have a setting). A few older devices are the reverse. The manual's list of supported codes settles it.
The less common codes (08, 17, 22, 23, 43)
- 08 Diagnostics, sub-function 00 "Return Query Data", makes a serial device echo your data: a link test that touches no register.
- 17 (0x11) Report Server ID returns a device-specific ID. Do not confuse 0x11 (a function code) with exception 0x0B (gateway target failed).
- 22 (0x16) Mask Write Register changes some bits of one holding register without touching the others: result = (current AND and_mask) OR (or_mask AND NOT and_mask).
- 23 (0x17) Read/Write Multiple Registers writes, then reads, in one transaction.
- 43 (0x2B), MEI type 14, Read Device Identification returns text such as VendorName, ProductCode and MajorMinorRevision.
A device that doesn't support a code should answer exception 01. Some stay silent instead.
Step-by-step: see each function code at work with ModLens
You can learn all of this on a laptop before going to site. The screenshots below come from ModLens connected to the free ModLens Sim simulator. In ModLens you pick the table, not the number, and the app sends the matching function code: Holding registers = 03, Input registers = 04, Coils = 01, Discrete inputs = 02.
The simulated AHU-1 controller is unit ID 1. It has supply air temperature at holding address 0 (int16, ×0.1), return air temperature at 1 (float32 ABCD), duct static pressure at 3 (float32 CDAB), fan speed command at 10 and supply temperature setpoint at 11 (int16, ×0.1). The main power meter is unit ID 2, with input registers only.
Step 1: Read holding registers (FC03)
In the Explorer, choose unit ID 1, Holding registers (4x), start address 0, count 12, and click Read.

Address 0 reads raw 144 (14.4 °C with the ×0.1 scale). Address 1 shows 22.26833 in float32 ABCD (words 0x41B2 and 0x2588, the FC03 frame above). Address 3 shows 1.378741 in float32 CDAB (static pressure), then 65 at 10 and 140 at 11 (setpoint 14.0 °C).
The status says "5 address(es) don't exist": addresses 5 to 9 are gaps. The full-block FC03 got exception 02, so ModLens re-read address by address and marked only the gaps. A BMS driver won't do that: give it two blocks, 0 to 4 and 10 to 11.
Step 2: Read input registers (FC04)
Change the unit ID to 2, choose Input registers (3x), count 7, and click Read.

In the float32 CDAB column: 230 at address 0 (voltage), 10 at address 2 (current), 6.9 at address 4 (kW). Address 6 reads raw 900: a power factor of 0.900 with a ×0.001 scale. Asking the same addresses with FC03 on this meter returns exception 02, because it has no holding registers.
Step 3: Read a coil (FC01)
Back to unit ID 1, choose Coils (0x), start address 0, count 1, and click Read.

Coil 0 is the occupancy schedule. It reads OFF (the simulated schedule runs Monday to Friday, and this was taken on a Saturday). ModLens decodes the packed bits for you.
Step 4: Write a coil (FC05)
Click Turn ON. ModLens sends FC05 with 0xFF00, then reads the coil again.

The device echoed the request ("Written ✓") and the read-back shows ON. Always read back after a write: the echo only proves the device accepted the command.
Step 5: Read a discrete input (FC02)
Choose Discrete inputs (1x) and click Read.

Discrete input 0 is the filter alarm, here ON. There is no Write column: no function code writes discrete inputs.
Step 6: Write a single register (FC06)
Choose Holding registers (4x), read addresses 10 to 11, then fill the Write a holding register card: address 11, data type uint16, value 145, and click Write. ModLens asks you to confirm, because a write changes how the equipment behaves.

For a one-register type like uint16, ModLens sends FC06 with the data from the frame above (06 00 0B 00 91; over TCP behind an MBAP header instead of a CRC). Register 11 goes from 140 to 145: setpoint 14.5 °C. For float32 or uint32, ModLens sends FC16 with two registers, so both halves are written together.
Step 7: Force FC16 for devices that reject FC06
If a device answers exception 01 to single writes, open Devices → Edit → Advanced: device limits and tick "Always write with function 16".

The same panel holds the read limits: 125 registers and 2000 coils, the specification's maximums. Lower them when a device answers exception 03 to big blocks; ModLens then splits reads. Every screen is described in the install and user guide.
Worked example: commissioning a VFD over Modbus RTU
A typical scenario: the VFD manual says "Supported functions: 03, 06, 16. Speed reference: register 40002 (0.01 Hz). Status word: register 40004. Max 16 registers per request."
- Translate the numbers. 40002 = holding address 1; 40004 = holding address 3.
- Read first. FC03, address 3, quantity 1 returns the status word. Link, unit ID and table are confirmed before any write.
- Write the speed. 45.00 Hz with a 0.01 scale is raw 4500 (0x1194). FC06 to address 1:
01 06 00 01 11 94plus CRC, and the drive echoes it. - Write two values at once. Speed (address 1) and command word (address 2) are neighbours, so one FC16 with quantity 2 writes both.
- Set the block size. A BMS driver that polls 30 registers in one FC03 gets exception 03. Set the driver's block size to 16, as the manual says.
Common mistakes with Modbus function codes
- Reading the wrong table. FC03 on a meter that only has input registers returns exception 02 or 01. Try FC04.
- Reading "function 10" as decimal. In hex manuals 10 is 16 and 0F is 15.
- Writing a 32-bit value with FC06. Two separate writes leave a half-updated value in between. Use FC16 with quantity 2.
- Sending 0x0001 to turn a coil on. FC05 only accepts 0xFF00 and 0x0000.
You can try every code on your own laptop: install ModLens with the free 14-day trial key, start the free ModLens Sim, and watch real replies and exceptions. After the trial, ModLens Lite stays free for basic reads and writes. Licences are on the pricing page.
FAQ
What are Modbus function codes?
They are one-byte numbers in every Modbus request that tell the device what to do: 01 to 04 read the four data tables, 05 and 06 write one coil or register, 15 (0x0F) and 16 (0x10) write several. The device answers with the same code, or with the code plus 0x80 when it refuses the request.
What is the difference between Modbus function code 3 and 4?
Function code 03 reads holding registers (the 4x table, usually read/write). Function code 04 reads input registers (the 3x table, read-only). The frame format and the 125-register limit are the same; only the table differs. The device's register map tells you which one to use.
What is the difference between function code 6 and 16?
Function code 06 writes one holding register and the device echoes the request. Function code 16 (0x10) writes 1 to 123 consecutive registers and the reply returns only the address and quantity. Use 16 for float32, 32-bit and 64-bit values; some devices only support 16, even for a single register.
How many registers can I read with function code 03?
The Modbus specification allows 1 to 125 registers per FC03 or FC04 request, and 1 to 2000 bits per FC01 or FC02 request. Many devices accept less; if a large read returns exception 03, lower the block size to the value in the manual.
What does function code 0x83 or 0x90 mean in a reply?
These are exception replies. The device adds 0x80 to the function code when it refuses a request: 0x83 means FC03 failed, 0x84 means FC04 failed, 0x90 means FC16 failed. The next byte is the exception code, such as 02 (illegal data address), which tells you why.
Does Modbus TCP use the same function codes as Modbus RTU?
Yes. The function code and its data (the PDU) are identical on Modbus RTU, Modbus ASCII and Modbus TCP. Only the wrapping changes: RTU adds the unit ID and a CRC, TCP adds the 7-byte MBAP header. A few diagnostic codes (07, 08, 11, 12, 17) are defined for serial lines only.