
esptool.py Guide: Install, Flash, Erase & Backup ESP32 Firmware
Complete esptool.py guide: install on Windows, Linux, and macOS, then flash, erase, backup, and read ESP32 firmware. Includes all essential commands with examples.
If you've ever uploaded firmware to an ESP32 board using the Arduino IDE, ESPHome, PlatformIO, or MicroPython, chances are that esptool.py was working behind the scenes.
What is esptool.py? #
esptool.py is an open-source command-line tool developed by Espressif for ESP32 and ESP8266 chips. It handles flashing firmware, erasing flash, reading backups, and low-level hardware operations - and runs silently behind Arduino IDE, ESPHome, and PlatformIO every time you upload code.
Use esptool.py directly when you need to:
Many ESP32 boards use different USB-to-UART bridge chips (CP210x, CH340) - esptool.py lets you set the correct baud rate and port when defaults fail. More about USB-to-UART bridges →
Setting Up esptool.py #
Install esptool.py on Windows, macOS, or Linux in three steps.
1 Install Python 3
esptool.py requires Python 3. Install it for your platform:
macOS
Install esptool directly:
brew install esptoolOr: brew install python, then pip.
Linux
Ubuntu/Debian:
sudo apt install python3 python3-pip2 Verify Python Installation
Confirm Python is working:
python3 --versionYou should see Python 3.x.x.
3 Install esptool.py
Install esptool via pip - works on Windows, macOS, and Linux:
pip install esptoolVerify the esptool.py version:
esptool.py versionExpected: esptool.py v4.8.1 - https://github.com/espressif/esptool
Windows: 'esptool.py' is not recognized?
Python scripts may not be on your PATH. Use this instead:
python -m esptool versionpython -m esptool is equivalent to esptool.py - use it anywhere this guide shows the latter.
Flashing Your ESP32 with esptool.py for the First Time #
With esptool.py installed, here's the full process to flash ESP32 firmware from the command line.
1 Connect Your ESP32
Use a USB cable to connect your ESP32 development board to your computer.
Important: Make sure the cable supports data transfer - many micro-USB cables are power-only.
2 Identify the Serial Port
Find which serial port your ESP32 is connected to:
Windows
Command Prompt:
wmic path Win32_SerialPort get DeviceID,NameOr use Device Manager → Ports (COM & LPT)
Look for: COM3, COM4, etc.
macOS
Terminal:
ls /dev/tty.*Look for: /dev/tty.usbmodemXXXX
Linux
Terminal:
ls /dev/ttyUSB*Look for: /dev/ttyUSB0

ESP32 not detected? Install USB-to-Serial drivers:
• CP210x (Silicon Labs): Download here
• CH340 (WCH): Download here
See also: ESP32 USB-to-UART bridge guide.
3 Erase Flash Memory (optional but recommended)
Erase existing flash to prevent conflicts with new firmware:
esptool.py --port <your-port> erase_flashReplace <your-port> with your serial port (e.g., /dev/ttyUSB0 or COM3).
Expected: Chip erase completed successfully in 2.5s. Hold the BOOT/FLASH button if it can't connect; release once erase starts.

4 Flash the Firmware
Have your firmware.bin ready, then run:
esptool.py --chip esp32 --port <your-port> --baud 460800 write_flash -z 0x1000 firmware.binFlag reference:
--chip esp32 - Target chip (esp32, esp32s3, esp32c3, …)
--port <your-port> - Serial port (e.g., COM3, /dev/ttyUSB0)
--baud 460800 - Baud rate; reduce to 115200 if errors occur
write_flash -z 0x1000 - Write binary at flash offset 0x1000
Expected: Hash of data verified. / Leaving... / Hard resetting via RTS pin...
Where to get ESP32 firmware:
Download the correct .bin for your ESP32 chip variant.
Your ESP32 is now flashed and ready to go!
Essential Commands #
Quick reference for the most common esptool.py commands. Bookmark this section for easy access.
Quick Reference - All Commands
esptool.py version - check versionesptool.py chip_id - get chip infoesptool.py flash_id - flash size/typeesptool.py erase_flash - wipe flashesptool.py write_flash - flash firmwareesptool.py read_flash - backup/dumpesptool.py verify_flash - verify writeesptool.py read_mac - get MAC addressWindows users: replace esptool.py with python -m esptool if the command isn't recognized.
esptool.py chip_id - Get Chip Info & Flash Details
Before flashing, it's useful to check what ESP32 chip you're working with and verify flash memory details.
esptool.py read_flash - Backup & Dump ESP32 Firmware
Pro Tip: Always back up your ESP32 firmware before making major changes!
Backup / dump entire flash memory (read_flash):
esptool.py --port <your-port> read_flash 0x00000 0x400000 backup.binAdjust 0x400000 based on your ESP32's flash size (4MB shown here)
Saves the full flash content into backup.bin, allowing you to restore later if needed. Also useful to dump firmware from an existing device before reflashing.
Restore firmware from backup:
esptool.py --port <your-port> write_flash 0x00000 backup.binWrites the backup back onto the ESP32, restoring it to its previous state.
esptool.py erase_flash - Erase & Re-flash
Erase the entire flash memory:
esptool.py --port <your-port> erase_flash
Flash new firmware:
esptool.py --chip esp32 --port <your-port> --baud 460800 write_flash -z 0x1000 firmware.binFlag explanations:
--chip esp32 → Specifies the ESP32 chip
--port <your-port> → Your serial port (e.g., COM3, /dev/ttyUSB0)
--baud 460800 → Speeds up flashing (reduce if errors occur)
-z 0x1000 → Writes firmware starting at the correct memory offset
For more details, check out using ESP32 with Arduino IDE
Baud Rates - Speed Up Flashing
If flashing takes too long, increase the baud rate for faster uploads:
esptool.py --port <your-port> --baud 921600 write_flash -z 0x1000 firmware.binNote: Higher baud rates can cause unstable flashing. If you encounter errors, lower it to 460800 or 115200
Tip: Most ESP32 boards work reliably at 460800, which offers a good balance between speed and stability.
Related Guides #
Explore these helpful resources to get the most out of your ESP32 development:
ESP32 USB-to-UART Bridges
Fix serial port connection issues and install drivers
ESPHome First-Time Setup
Complete guide for flashing ESPHome firmware
MicroPython on ESP32
Get started with Python programming on ESP32
Arduino IDE for ESP32
Complete setup guide for Arduino development
Official esptool.py Documentation
Comprehensive technical reference from Espressif
Wrapping Up #
With esptool.py, you now have full control over flashing, backing up, and managing your ESP32 firmware. Whether you're installing ESPHome, setting up MicroPython, or recovering from a failed flash, these commands will get you there.
Quick troubleshooting checklist:
- ✓ Double-check your USB drivers are installed correctly (CP210x or CH340)
- ✓ Verify the correct serial port is selected
- ✓ Try lowering the baud rate to 460800 or 115200 if flashing fails
- ✓ Hold the BOOT button during connection if the chip doesn't respond
Need help with connection issues? See our detailed guide on ESP32 USB-to-UART Bridges.

