ESP32 vs ESP8266 is the first hardware decision in most Wi-Fi MQTT projects, and the right answer depends less on raw speed than on memory, TLS and the peripherals you need. This comparison walks through the differences that matter when your device must stay connected to a broker for months. By the end you will know which chip to buy for your next sensor, actuator or gateway.
The Short Answer
Choose the ESP32 for new designs that need encrypted connections, more than a handful of sensors, Bluetooth, over-the-air updates with room to spare, or any kind of local processing. Choose the ESP8266 for very simple, cost-sensitive nodes such as a single relay or temperature sensor, especially when you already have the boards or a proven codebase.
The rest of this article explains why.
Specification Comparison
The table compares the classic ESP32 (ESP32-WROOM-32 class modules) with the ESP8266 (ESP-12 class modules). Newer ESP32 variants are discussed below.
| Feature | ESP8266 | ESP32 (classic) |
|---|---|---|
| CPU | Single-core Tensilica L106, 80/160 MHz | Dual-core Xtensa LX6, up to 240 MHz |
| Data RAM | About 80 KB user data RAM, much less free for your sketch | 520 KB SRAM |
| Wi-Fi | 802.11 b/g/n, 2.4 GHz | 802.11 b/g/n, 2.4 GHz |
| Bluetooth | No | Classic Bluetooth and BLE |
| GPIO | About 17, several with boot restrictions | About 34 |
| ADC | One 10-bit channel | Up to 18 channels, 12-bit |
| Hardware crypto | No | AES, SHA, RSA acceleration |
| Other peripherals | UART, SPI, I2C (software), PWM | UART, SPI, I2C, I2S, CAN (TWAI), touch, DAC, many PWM channels |
| Deep sleep current | Low | Low, plus ULP coprocessor |
| Arduino core | esp8266 by ESP8266 Community | esp32 by Espressif Systems |
| FreeRTOS | No (non-OS SDK under Arduino) | Yes |
For the authoritative datasheets and variant tables, see the Espressif documentation.
Memory: The Difference That Matters Most
MQTT itself is light. A PubSubClient connection with a small buffer fits easily on either chip. Memory becomes the deciding factor once you add the things real products need.
On the ESP8266, Wi-Fi, the TCP/IP stack and the Arduino core already use a large share of the RAM, leaving a comparatively small heap for your application. A TLS session then needs a substantial contiguous block for its record buffers and certificate checks. Add a JSON library, a web configuration page and a 2 KB MQTT buffer, and you are close to the edge. The device may work on your desk and fail days later because the heap fragmented and the next TLS handshake cannot find a large enough block.
The ESP32's 520 KB of SRAM changes this. You can run TLS, a web server, a larger MQTT buffer and a JSON document at the same time with plenty of headroom, and many modules add PSRAM for even more.
Practical rule: if your ESP8266 project needs TLS and anything beyond a simple sensor loop, budget time for memory tuning, or move to the ESP32.
TLS Capability
Production MQTT should use TLS on port 8883 with credentials. Both chips can do it, but the experience differs:
- Certificate validation. The ESP32
WiFiClientSecureuses mbedTLS and accepts a PEM root certificate withsetCACert(). The ESP8266 uses BearSSL, which also validates certificate dates, so you must sync time over NTP before connecting. - Handshake speed. The ESP32's hardware acceleration and faster cores complete handshakes quickly. The ESP8266 is noticeably slower, especially at 80 MHz, which matters for battery devices that reconnect on every wake-up.
- Concurrent sessions. An ESP32 can comfortably hold more than one TLS connection, for example MQTT plus an HTTPS OTA download. On an ESP8266 that is risky.
- Buffer tuning. The ESP8266 can reduce TLS buffers via maximum fragment length negotiation only when the server supports it, so you cannot count on it.
Our ESP8266 MQTT tutorial shows the exact BearSSL setup, and the ESP32 MQTT tutorial shows the ESP32 equivalent.
Peripherals and Sensors
The ESP8266's single 10-bit ADC is its most common limitation. If you need more than one analog input, you add an external ADC such as an ADS1115 over I2C. Several of its GPIOs also have boot-time functions, so the usable pin count is smaller than it looks.
The ESP32 offers many ADC channels, capacitive touch inputs, I2S for microphones and audio, a CAN controller (TWAI) for vehicle and industrial buses, and Bluetooth Low Energy. BLE is especially useful for MQTT gateways: the ESP32 can collect readings from BLE sensors and publish them to a broker over Wi-Fi.
Software and Library Support
Both chips are well supported by the Arduino ecosystem, but the ESP32 is where active development happens.
| Library | ESP8266 | ESP32 |
|---|---|---|
| PubSubClient | Yes | Yes |
| ArduinoMqttClient | Yes | Yes |
| AsyncMqttClient | Yes, with ESPAsyncTCP | Yes, with AsyncTCP |
ESP-IDF native MQTT client (esp-mqtt) |
No | Yes, with MQTT 5 support |
| FreeRTOS tasks | No | Yes |
The FreeRTOS foundation on the ESP32 matters for MQTT firmware. You can run the network client in one task and sensor sampling in another, so a slow broker reconnect does not stall your control loop. On the ESP8266 everything shares one loop, and long blocking calls trigger the watchdog. Read more about non-blocking designs in async MQTT client on ESP32.
Power Consumption
Both chips spend most of their energy on the radio. For battery sensors that wake, publish and sleep, the dominant factors are how quickly you can connect and how long the radio stays on, not the idle current of the CPU. The ESP32's faster TLS handshake can offset its higher active current, and its ultra-low-power coprocessor can watch a sensor while the main cores sleep. The ESP8266 remains a reasonable choice for simple wake-publish-sleep nodes on plain MQTT inside a trusted network.
Cost and Availability
The ESP8266 is usually the cheaper module, and development boards for both chips are inexpensive and widely available. In most projects the price difference is small compared with the sensor, enclosure, power supply and your development time. Spending a little more on an ESP32 often saves hours of memory tuning. Prices change often, so compare current offers from reputable suppliers rather than relying on old forum figures.
What About the Newer ESP32 Variants?
Espressif's family has grown well beyond the classic ESP32:
- ESP32-C3: single-core RISC-V, Wi-Fi and BLE, low cost. It is the natural modern replacement for many ESP8266 designs and keeps TLS comfortable.
- ESP32-S3: dual-core with vector instructions, USB OTG and often PSRAM, good for camera, audio and edge processing workloads.
- ESP32-C6: adds Wi-Fi 6 and an 802.15.4 radio for Thread and Zigbee, useful for gateways.
If you are tempted by the ESP8266 purely for cost, look at the ESP32-C3 first.
Decision Checklist
Answer these questions in order. The first "yes" decides:
- Do you need Bluetooth, CAN, I2S, touch or more than one analog input? Choose ESP32.
- Will the device use TLS and run a web server, OTA or large JSON payloads? Choose ESP32.
- Do you need local processing, multiple tasks or MQTT 5 on the device? Choose ESP32 (ESP-IDF).
- Is it a single sensor or relay on plain MQTT in a trusted network, with existing ESP8266 boards? The ESP8266 is fine.
- Still undecided? Choose an ESP32-C3 for a low-cost, modern, TLS-friendly option.
The Broker Side Is the Same
Whichever chip you pick, the broker does not care. Both connect with the same MQTT 3.1.1 packets to the same topics. Start testing on broker.connectmq.com, the free public MQTT broker from ConnectMQ, with a unique client ID and topic prefix:
mosquitto_sub -h broker.connectmq.com -p 1883 -i compare-91c4 -t "connectmq/demo/compare-91c4/#" -v
Then flash the same topic layout to an ESP32 and an ESP8266 and compare reconnect times and free heap in your own environment. That small experiment tells you more than any datasheet. The ESP32 IoT tutorial is a good next step once you have chosen, and PubSubClient is the library to start with on both boards.
Connect Either Chip to ConnectMQ
When your device leaves the bench, give it private credentials on a fully managed MQTT service. ConnectMQ runs MQTT 3.1.1 and 5.0 on TCP 1883, TLS 8883 and WebSockets, with a portal that shows live topics, connected devices and threshold alerts, whether your fleet is ESP32, ESP8266 or both. For background on choosing infrastructure, see our guide to the cloud MQTT broker options. Create a free Serverless broker at app.connectmq.com, no credit card required.
Frequently Asked Questions
Is the ESP8266 obsolete?
Not obsolete, but it is no longer the best choice for most new designs. It remains fine for simple nodes, while the ESP32-C3 covers the same low-cost niche with more memory and better TLS.
Can the ESP8266 handle MQTT over TLS?
Yes, with BearSSL and careful memory management. Sync the clock, keep the MQTT buffer small and avoid heap fragmentation, and it works reliably for simple sensors.
Does the ESP32 support MQTT 5?
The ESP-IDF MQTT client supports MQTT 5. The popular Arduino libraries, PubSubClient and ArduinoMqttClient, use MQTT 3.1.1, which every major broker still supports.
Can ESP32 and ESP8266 devices share the same broker?
Yes. MQTT is hardware-agnostic, so both chips can publish and subscribe to the same topics on the same broker, as long as each device uses a unique client ID.



