BLE MTU Payload Calculator
Try Keep Negotiated MTU (bytes) at 23 and add CO2 level (2B uint16) under Payload fields.
Observe The default fields total 19 bytes, leaving 1 byte of the 20-byte payload capacity. Adding CO2 makes the payload exceed that capacity by 1 byte.
Explain The tool adds the byte sizes of Payload fields and compares the sum with Negotiated MTU (bytes) minus the ATT header.
Calculate payload size
Reset
Technical boundaries. The calculation assumes the listed field sizes and a fixed 3-byte ATT header, with MTU choices of 23, 65, 128, 185 and 247 bytes. It does not perform MTU negotiation or send packets.
Build your sensor payload by toggling fields on/off. See if your total fits within the default BLE MTU or if you need to negotiate a larger one.
viewof mtu_negotiated = Inputs. select ([23 , 65 , 128 , 185 , 247 ], {value : 23 , label : "Negotiated MTU (bytes)" })
viewof mtu_fields = Inputs. checkbox (
["Temperature (2B int16)" , "Humidity (2B uint16)" , "Pressure (4B uint32)" , "Timestamp (4B uint32)" , "Battery (1B uint8)" , "Device ID (6B MAC)" , "CO2 level (2B uint16)" , "Light (2B uint16)" , "GPS lat (4B float)" , "GPS lon (4B float)" ],
{value : ["Temperature (2B int16)" , "Humidity (2B uint16)" , "Pressure (4B uint32)" , "Timestamp (4B uint32)" , "Battery (1B uint8)" , "Device ID (6B MAC)" ], label : "Payload fields" }
)
{
const sizes = {
"Temperature (2B int16)" : 2 , "Humidity (2B uint16)" : 2 , "Pressure (4B uint32)" : 4 ,
"Timestamp (4B uint32)" : 4 , "Battery (1B uint8)" : 1 , "Device ID (6B MAC)" : 6 ,
"CO2 level (2B uint16)" : 2 , "Light (2B uint16)" : 2 , "GPS lat (4B float)" : 4 , "GPS lon (4B float)" : 4
};
const attHeader = 3 ;
const maxPayload = mtu_negotiated - attHeader;
const total = mtu_fields. reduce ((s, f) => s + (sizes[f] || 0 ), 0 );
const fits = total <= maxPayload;
const defaultFits = total <= 20 ;
const fieldList = mtu_fields. map (f => `<span style="display:inline-block;padding:2px 8px;margin:2px;border-radius:3px;background: ${ fits ? "#d5f5e3" : "#fce4e4" } ;font-size:12px;"> ${ f. split ("(" )[0 ]. trim ()} ${ sizes[f]} B</span>` ). join ("" );
return html `<div style="background:#f8f9fa;padding:1rem;border-radius:8px;border-left:4px solid ${ fits ? "#16A085" : "#E74C3C" } ;margin-top:0.5rem;">
<p style="margin:0 0 6px;font-size:13px;"><strong>Selected fields:</strong> ${ fieldList} </p>
<table style="width:100%;border-collapse:collapse;font-size:13px;margin-top:8px;">
<tr><td style="padding:3px;">Total payload</td><td style="padding:3px;text-align:right;font-weight:bold;"> ${ total} bytes</td></tr>
<tr><td style="padding:3px;">ATT header overhead</td><td style="padding:3px;text-align:right;">3 bytes</td></tr>
<tr style="border-top:1px solid #dee2e6;"><td style="padding:3px;">Total on wire</td><td style="padding:3px;text-align:right;font-weight:bold;"> ${ total + attHeader} bytes</td></tr>
<tr><td style="padding:3px;">MTU capacity ( ${ mtu_negotiated} B)</td><td style="padding:3px;text-align:right;"> ${ maxPayload} bytes payload</td></tr>
</table>
<div style="margin-top:8px;padding:6px 10px;border-radius:4px;background: ${ fits ? "#d5f5e3" : "#fce4e4" } ;font-size:13px;">
${ fits
? `✓ <strong style="color:#16A085;">Fits!</strong> ${ maxPayload - total} bytes remaining.`
: `✗ <strong style="color:#E74C3C;">Exceeds MTU by ${ total - maxPayload} bytes!</strong> ${ mtu_negotiated === 23 ? "Negotiate larger MTU or remove fields." : "Increase MTU or split into chunks." } `
}
${ ! defaultFits && mtu_negotiated === 23 ? `<br><span style="color:#E67E22;">This payload requires MTU negotiation — default 23-byte MTU only allows 20 bytes of payload.</span>` : "" }
</div>
</div>` ;
}
Back to the chapter