Mixing up physical pin numbers with Broadcom (BCM) software mappings, or accidentally feeding 5V into a 3.3V-tolerant input, is the fastest way to fry the SoC on a Raspberry Pi 4 or the RP1 southbridge on a Raspberry Pi 5. While the physical 40-pin header layout has remained unchanged since the Pi 1 Model B+, the way you wire, code, and interpret those pins requires strict adherence to hardware limits and regional wiring standards.
Here is the exact hardware reference, wiring color standards, and decision framework you need before you crimp a single Dupont connector.
The Complete RPi GPIO Pinout Reference (40-Pin Header)
The table below maps the physical board pins (1-40) to their BCM GPIO numbers and primary functions. This layout applies universally to the Raspberry Pi 3, 4, and 5. Note: The Pi 5 routes these through the RP1 I/O controller, but the BCM software mapping remains identical for backward compatibility.
| Physical Pin | BCM GPIO | Function / Name | Physical Pin | BCM GPIO | Function / Name |
|---|---|---|---|---|---|
| 1 | - | 3.3V Power | 2 | - | 5V Power |
| 3 | 2 | I2C1 SDA | 4 | - | 5V Power |
| 5 | 3 | I2C1 SCL | 6 | - | Ground |
| 7 | 4 | GPIO 4 | 8 | 14 | UART0 TXD |
| 9 | - | Ground | 10 | 15 | UART0 RXD |
| 11 | 17 | GPIO 17 | 12 | 18 | GPIO 18 (PWM0) |
| 13 | 27 | GPIO 27 | 14 | - | Ground |
| 15 | 22 | GPIO 22 | 16 | 23 | GPIO 23 |
| 17 | - | 3.3V Power | 18 | 24 | GPIO 24 |
| 19 | 10 | SPI0 MOSI | 20 | - | Ground |
| 21 | 9 | SPI0 MISO | 22 | 25 | GPIO 25 |
| 23 | 11 | SPI0 SCLK | 24 | 8 | SPI0 CE0 |
| 25 | - | Ground | 26 | 7 | SPI0 CE1 |
| 27 | 0 | I2C0 SDA (EEPROM) | 28 | 1 | I2C0 SCL (EEPROM) |
| 29 | 5 | GPIO 5 | 30 | - | Ground |
| 31 | 6 | GPIO 6 | 32 | 12 | GPIO 12 (PWM0) |
| 33 | 13 | GPIO 13 (PWM1) | 34 | - | Ground |
| 35 | 19 | GPIO 19 | 36 | 16 | GPIO 16 |
| 37 | 26 | GPIO 26 | 38 | 20 | GPIO 20 |
| 39 | - | Ground | 40 | 21 | GPIO 21 |
RPi.GPIO or gpiozero, always use GPIO.setmode(GPIO.BCM). This forces your code to reference the Broadcom SOC channel numbers (the middle column above) rather than the physical pin numbers, preventing catastrophic misalignment when you swap between Pi models.
Wiring Color Standards: IEC vs. NEC for DC Control Circuits
The Raspberry Pi's silkscreen and pinout are universal, but the wires you crimp onto the header follow regional DC standards. Using the wrong color conventions in a mixed-voltage environment (like a cabinet housing both 24V industrial PLCs and a 5V Raspberry Pi) is a major troubleshooting hazard.
According to Pinout.xyz and standard electrical practices, here is how you should color-code your Dupont or JST connectors based on your region's prevailing low-voltage standard:
| Function | US / NEC (Class 2 Low Voltage) | EU / IEC 60446 (PELV/SELV DC) |
|---|---|---|
| Positive (5V) | Red | Brown |
| Positive (3.3V) | Orange or Yellow | Orange (to distinguish from 5V) |
| Ground / 0V | Black | Blue |
| Signal / GPIO | White, Green, or Yellow | Black or Grey |
The 'Rows People Get Wrong' (And How They Brick Your Pi)
Based on bench repair logs and community debugging, these three specific pinout misunderstandings cause 90% of dead Raspberry Pi boards:
- Pin 1 (3.3V) vs Pin 2 (5V) Reversal: Pin 1 outputs 3.3V from the onboard regulator. Pin 2 is tied directly to the USB-C power input (5V). If you accidentally wire a 5V sensor's VCC to Pin 1, you will overload the 3.3V regulator and shut down the Pi. If you wire a 3.3V logic output into a 5V-tolerant input on a peripheral, you'll fry the peripheral.
- The I2C Pull-Up Trap (Pins 3 & 5): GPIO 2 (SDA) and GPIO 3 (SCL) have onboard 1.8kΩ pull-up resistors tied to the 3.3V rail. If you connect a 5V I2C device and add external 5V pull-up resistors, you will back-feed 5V into the 3.3V rail through the I2C lines, destroying the RP1 chip on a Pi 5 or the BCM2711 on a Pi 4. Always use a logic level shifter (like the BSS138) for 5V I2C devices.
- UART TX/RX Crossover (Pins 8 & 10): Pin 8 is TXD (Transmit) and Pin 10 is RXD (Receive). People frequently wire TX to TX and RX to RX. You must cross them: Pi TX (Pin 8) goes to the peripheral's RX, and Pi RX (Pin 10) goes to the peripheral's TX.
Decision Tree: Which GPIO Pin Should You Actually Use?
Don't just pick 'GPIO 17' because it's first on the list. Hardware-specific features are hardwired to specific pins. Use this decision path to select the correct pin for your component, terminating in a concrete assignment.
| If your project needs... | Then use these specific pins... | Why? (Hardware constraint) |
|---|---|---|
| Hardware PWM (Motor control, LED dimming) | GPIO 18 (Pin 12) or GPIO 13 (Pin 33) | These are the only pins routed to the dedicated hardware PWM channels. Software PWM on other pins causes jitter. |
| I2C Sensors (BME280, OLED displays) | GPIO 2 (Pin 3) & GPIO 3 (Pin 5) | Hardwired to I2C1 bus with onboard 1.8k pull-ups. No external resistors needed for 3.3V devices. |
| SPI Devices (RFID, ADC chips) | GPIO 10, 9, 11, 8 (Pins 19, 21, 23, 24) | Hardwired to SPI0. Do not use GPIO 0/1 (Pins 27/28) as they are reserved for the HAT EEPROM I2C bus. |
| Simple Button / Limit Switch | GPIO 17 (Pin 11) | Standard GPIO with no alternate boot functions. Safe to use with internal software pull-ups via gpiozero. |
Default Recommendation: If you are wiring a standard digital input (like a PIR motion sensor) and have no protocol requirements, default to GPIO 17 (Pin 11). It is physically easy to access, has no conflicting alternate functions during boot, and is universally supported across all Pi OS versions.
Safe Interpretation When Board Markings Are Faded or Missing
If you are working with an older Pi 3, a compute module breakout board, or a board where the silkscreen has been scratched off, do not guess the pinout. Follow this multimeter verification sequence:
- Locate Pin 1: Look at the solder joints on the underside of the board. Pin 1 is the only pin with a square copper pad. All other pins have round pads. Pin 1 is always the one closest to the SD card slot and the USB-C power connector.
- Identify Ground Pins: Set your digital multimeter (DMM) to continuity mode (the diode/beep setting). Place the black probe on the metal shield of the USB port or the Ethernet jack. Probe the header pins with the red probe. Any pin that beeps (reads < 1 ohm) is a Ground pin. On the standard 40-pin header, these are pins 6, 9, 14, 20, 25, 30, 34, and 39.
- Verify Power Rails: Power the board via USB-C. Set the DMM to DC Voltage. Place the black probe on a confirmed Ground pin. Probe the top-row pins (opposite Pin 1). You should read exactly 5.0V to 5.2V. Probe Pin 1; you must read 3.3V. If Pin 1 reads 0V while Pin 2 reads 5V, the onboard 3.3V polyfuse or regulator has blown.
By anchoring your physical wiring to regional DC color standards and your software to BCM numbering, you eliminate the two most common vectors for hardware failure. For the definitive visual map of alternate pin functions (like DPI and JTAG modes), always cross-reference your physical wiring against the official Raspberry Pi GPIO Documentation before applying power.






