# Advantage of Base64 encoding in MQTT?

**URL:** <https://www.thethingsnetwork.org/forum/t/advantage-of-base64-encoding-in-mqtt/3425>\
**Category:** Uncategorized\
**Created:** [September 9, 2016, 11:30am UTC](https://www.thethingsnetwork.org/forum/t/advantage-of-base64-encoding-in-mqtt/3425 "2016-09-09T11:30:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thaskippy](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/thaskippy/32/1527_2.png) [@thaskippy](https://www.thethingsnetwork.org/forum/u/thaskippy)\
**Post date:** [September 9, 2016, 11:30am UTC](https://www.thethingsnetwork.org/forum/t/advantage-of-base64-encoding-in-mqtt/3425/1 "2016-09-09T11:30:04Z")

</div>

Hey,  
I was wondering what is exactly the added advantage of encoding data through Base64 on the MQTT connection?

---

<div class="post-metadata">

**Author:** ![arjanvanb](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/arjanvanb/32/46626_2.png) [@arjanvanb](https://www.thethingsnetwork.org/forum/u/arjanvanb)\
**Post date:** [September 9, 2016, 11:41am UTC](https://www.thethingsnetwork.org/forum/t/advantage-of-base64-encoding-in-mqtt/3425/2 "2016-09-09T11:41:54Z")

</div>

When the node sends binary data (rather than plain text), which is certainly [best practice](https://www.thethingsnetwork.org/forum/t/best-practices-to-limit-application-payloads/1302), then one needs to make sure that the binary data is encoded in a way that does not break the JSON text message format. Base64 only uses printable characters, so ensures the JSON is fine, even if the payload contains bytes that are not printable, or would have [a special meaning if interpreted as ASCII](https://en.m.wikipedia.org/wiki/Control_character).

One could use hexadecimal codes, but then one would only use the characters 0-9, A-F and would need 2 characters to encode each byte. Base64 uses many more characters in the encoding, so needs fewer characters for each byte.

By the way: note the lovely TTN payload functions if you want [a readable self-documenting MQTT message](https://www.thethingsnetwork.org/forum/t/best-practices-when-sending-gps-location-data/1242/14).

---

<div class="post-metadata">

**Author:** ![arjanvanb](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/arjanvanb/32/46626_2.png) [@arjanvanb](https://www.thethingsnetwork.org/forum/u/arjanvanb)\
**Post date:** [September 10, 2016, 2:52pm UTC](https://www.thethingsnetwork.org/forum/t/advantage-of-base64-encoding-in-mqtt/3425/3 "2016-09-10T14:52:42Z")

</div>

A post was split to a new topic: [Is there any documentation on payload functions?](https://www.thethingsnetwork.org/forum/t/is-there-any-documentation-on-payload-functions/3441)
