The ESP32 features 34 physical GPIO pins, but only 25 are universally safe for general I/O due to boot strapping requirements and input-only hardware limitations. Below is the definitive map to keep your board from bricking at boot, followed by critical notes on board variants and common wiring mistakes.

The Complete ESP32 GPIO Pinout Reference Table

How to read this table: 'Default State' refers to the pin's logic level during the ROM bootloader phase. 'Safe for Output?' indicates if the pin can reliably drive relays, LEDs, or MOSFETs without causing boot loops. 'Strapping Role' defines the hardware configuration the pin forces if pulled HIGH or LOW at reset.

GPIO Pin Default Boot State Safe for Output? Strapping / Special Role Practical Notes
GPIO 0Internal Pull-UPNoBoot mode select (LOW = Flash mode)Outputs PWM at boot. Avoid for relays.
GPIO 1LOWNoTX0 (Serial Debug)Outputs debug logs. Do not use for I/O.
GPIO 2Internal Pull-DOWNYes (with caution)Boot mode select (Must be LOW or floating to boot)Connected to onboard LED. Must not be pulled HIGH at boot.
GPIO 3HIGHNoRX0 (Serial Debug)Inputs serial data. Do not use for I/O.
GPIO 4LOWYesNoneExcellent general-purpose I/O pin.
GPIO 5HIGHYesStrapping pin for SDIO timingOutputs PWM at boot. Safe for outputs after boot.
GPIO 6-11N/ANoConnected to internal SPI FlashUsing these will crash the firmware instantly.
GPIO 12Internal Pull-DOWNNoMTDI: Sets flash voltage (HIGH = 1.8V)If pulled HIGH at boot, 3.3V boards will brownout.
GPIO 13LOWYesNoneSafe for general I/O and PWM.
GPIO 14LOWYesNoneOutputs PWM at boot. Safe after boot.
GPIO 15HIGHYesStrapping pin for boot log outputOutputs PWM at boot. Safe for outputs after boot.
GPIO 16LOWYesNoneSafe for general I/O. No ADC2 conflicts.
GPIO 17LOWYesNoneSafe for general I/O.
GPIO 18LOWYesNoneDefault VSPI SCK. Great for SPI displays.
GPIO 19LOWYesNoneDefault VSPI MISO.
GPIO 21LOWYesNoneDefault I2C SDA. Excellent for sensors.
GPIO 22LOWYesNoneDefault I2C SCL.
GPIO 23LOWYesNoneDefault VSPI MOSI.
GPIO 25LOWYesNoneConnected to internal DAC1. Safe for I/O.
GPIO 26LOWYesNoneConnected to internal DAC2. Safe for I/O.
GPIO 27LOWYesNoneSafe for general I/O and PWM.
GPIO 32LOWYesNoneSafe for I/O. Connected to ADC1 and touch.
GPIO 33LOWYesNoneSafe for I/O. Connected to ADC1 and touch.
GPIO 34LOWNoInput Only (No internal pull-up)Requires external 10kΩ pull-up for buttons.
GPIO 35LOWNoInput Only (No internal pull-up)Requires external 10kΩ pull-up for buttons.
GPIO 36LOWNoInput Only (VP / ADC)Extremely sensitive to noise. Use for analog only.
GPIO 39LOWNoInput Only (VN / ADC)Extremely sensitive to noise. Use for analog only.

Board Variants, Standards, and Faded Silkscreen Recovery

In mains electrical work, you must follow regional codes like the US NEC (black/red for hot, green/bare for ground) or the EU/UK IEC 60446 (brown/blue for AC). Microcontroller GPIO, however, does not follow regional electrical codes; it follows the silicon manufacturer's datasheet. For the ESP32, the Espressif ESP32 Datasheet is your universal standard. That said, 'regional' differences in the maker space manifest as board layout variants.

The two most common board variants are the Espressif DevKit V1 (often cloned by NodeMCU and AI-Thinker) and the Wemos D1 Mini ESP32. While the silicon pin numbers (GPIO 0-39) remain identical across all variants, the physical breakout order on the headers changes. A pin labeled 'D4' on a Wemos board maps to a completely different GPIO than 'D4' on an older NodeMCU ESP8266. Always wire by the GPIO number printed on the silkscreen, never by the 'D' or 'A' legacy labels.

⚠️ Safe Interpretation for Faded or Missing Markings:
Cheap clone boards often suffer from faded or entirely missing white silkscreen. If your board is unmarked, orient it with the micro-USB port facing down. The left header always starts sequentially with 3V3, EN, VP (GPIO 36), VN (GPIO 39), and IO34. The right header starts with GND and GPIO 23. This physical layout is hardcoded into the standard DevKit V1 PCB design, allowing you to map pins safely by counting down from the top.

The "Rows People Get Wrong" Notes Section

Even experienced builders fall into the same ESP32 GPIO traps. Here is what the rows in the table above actually mean when your circuit fails on the bench:

  • GPIO 12 (The Boot Killer): This is the most dangerous strapping pin. If GPIO 12 is pulled HIGH during boot (e.g., by a relay module with an active-high optocoupler), it tells the ESP32 to switch its internal SPI flash voltage from 3.3V to 1.8V. On standard 3.3V boards, this causes an immediate brownout and an endless boot loop. Fix: Never connect active-high loads to GPIO 12, or use espefuse.py to burn the XPD_SDIO_TIEH efuse if you absolutely must use it.
  • GPIO 34, 35, 36, 39 (The Floating Inputs): These pins are physically disconnected from the output drivers and lack internal pull-up/pull-down resistors. If you wire a pushbutton to GPIO 34 without an external 10kΩ resistor to 3.3V, the pin will float, picking up ambient RF noise and triggering false interrupts. Furthermore, these pins share the ADC1 bus, which is disabled when WiFi is active on some firmware configurations.
  • GPIO 6 through 11 (The Ghost Pins): These pins are physically bonded to the onboard SPI flash memory chip. If you attempt to configure them as outputs or read them as inputs, the ESP32 will experience a fatal exception and crash. Treat them as if they do not exist.
  • GPIO 2 (The Onboard LED Conflict): GPIO 2 is hardwired to the blue onboard LED on most DevKits. It must be LOW or floating to enter flash mode. If you wire a sensor that pulls this pin HIGH at boot, the ESP32 will refuse to flash new firmware via USB.

Frequently Asked Questions About ESP32 GPIO

Which ESP32 GPIO pins are safe to use for relays and LEDs?

For outputs that must remain stable during boot (like relays controlling mains contactors or high-power LEDs), use GPIO 4, 13, 16, 17, 18, 19, 21, 22, 23, 25, 26, 27, 32, and 33. These pins default to LOW or Hi-Z at boot and do not output the 80MHz PWM debug signal that plagues GPIO 0, 2, 5, 14, and 15 during the bootloader phase. Always use a flyback diode across relay coils and drive them via a logic-level MOSFET or transistor, as the ESP32 can only source roughly 40mA per pin.

Why does my ESP32 fail to boot when a sensor is connected to GPIO 12?

As detailed in the ESP-IDF GPIO documentation, GPIO 12 is a strapping pin for the SDIO voltage. If your sensor module has an internal pull-up resistor on its data line, it will pull GPIO 12 HIGH during the millisecond the ESP32 resets. This forces the chip into 1.8V flash mode, crashing a 3.3V board. To fix this, either move the sensor to a safe pin like GPIO 13, or add a 4.7kΩ pull-down resistor between GPIO 12 and GND to overpower the sensor's internal pull-up during the boot window.

Can I use ESP32 GPIO pins for 5V tolerant inputs?

No. The ESP32 is strictly a 3.3V logic device. Feeding 5V into any GPIO pin will degrade the silicon over time and eventually destroy the input protection diodes, leading to a shorted pin or a dead chip. If you need to read a 5V signal (like from an automotive sensor or a 5V Arduino), you must use a voltage divider (e.g., a 2kΩ and 3.3kΩ resistor pair) to drop the voltage to a safe ~3.0V, or use a dedicated logic level shifter IC like the TXS0108E for high-speed bidirectional buses.