The Raspberry Pi 40-pin GPIO header contains 26 general-purpose I/O pins, 8 ground pins, two 5V power pins, and two 3V3 power pins. Pin 1 is always the 3V3 pin located closest to the SD card slot and USB-C power input. Never apply mains AC wiring color codes to this low-voltage DC header; doing so risks catastrophic failure of the Pi's power management IC (PMIC).
The Complete Raspberry Pi GPIO Pinout Reference (40-Pin)
The physical layout below applies to all 40-pin models (Pi 1 Model B+ through Pi 5). While the Pi 5 introduces additional dedicated I2C/UART headers and a PCIe connector, the primary 40-pin header remains backward-compatible for standard GPIO, SPI, I2C, and UART assignments.
| Pin | Left Bank (Odd) | Right Bank (Even) | Pin |
|---|---|---|---|
| 1 | 3V3 Power | 5V Power | 2 |
| 3 | GPIO 2 (I2C1 SDA) | 5V Power | 4 |
| 5 | GPIO 3 (I2C1 SCL) | Ground | 6 |
| 7 | GPIO 4 (GPCLK0) | GPIO 14 (UART TXD) | 8 |
| 9 | Ground | GPIO 15 (UART RXD) | 10 |
| 11 | GPIO 17 | GPIO 18 (PCM CLK / PWM0) | 12 |
| 13 | GPIO 27 | Ground | 14 |
| 15 | GPIO 22 | GPIO 23 | 16 |
| 17 | 3V3 Power | GPIO 24 | 18 |
| 19 | GPIO 10 (SPI0 MOSI) | Ground | 20 |
| 21 | GPIO 9 (SPI0 MISO) | GPIO 25 | 22 |
| 23 | GPIO 11 (SPI0 SCLK) | GPIO 8 (SPI0 CE0) | 24 |
| 25 | Ground | GPIO 7 (SPI0 CE1) | 26 |
| 27 | ID_SD (I2C ID) | ID_SC (I2C ID) | 28 |
| 29 | GPIO 5 | Ground | 30 |
| 31 | GPIO 6 | GPIO 12 (PWM0) | 32 |
| 33 | GPIO 13 (PWM1) | Ground | 34 |
| 35 | GPIO 19 (PCM FS) | GPIO 16 | 36 |
| 37 | GPIO 26 | GPIO 20 | 38 |
| 39 | Ground | GPIO 21 | 40 |
Source: Pinout.xyz and Raspberry Pi Official Documentation.
Wire Color Standards: GPIO vs. Mains Regional Variants
A common and dangerous mistake among beginners is applying mains AC electrical color codes to low-voltage DC microcontroller wiring. The standards that govern your wall outlets do not apply to your Pi's GPIO header.
| Standard / Region | Live / Hot (AC) | Neutral (AC) | Earth / Ground (AC) | Applies to Pi GPIO? |
|---|---|---|---|---|
| NEC (US/Canada) | Black / Red | White / Gray | Green / Bare | NO |
| IEC 60446 (EU/UK) | Brown / Black / Gray | Blue | Green-Yellow | NO |
| Old UK (Pre-2006) | Red / Yellow / Blue | Black | Green | NO |
| IEC DC Adaptation | Brown (+) | Blue (-) | N/A | Yes (Industrial) |
| Maker / Hobbyist DC | Red (VCC) | Black (GND) | N/A | YES (Default) |
The 'Rows People Get Wrong' (And How They Brick Your Pi)
When reading the pinout table above, three specific areas cause 90% of hardware failures on the bench. Understanding what these rows mean in practice will save you from ordering a replacement SoC.
1. Pin 1 (3V3) vs. Pin 2 (5V) Power Reversal
Pins 1 and 2 sit side-by-side. Pin 1 outputs 3.3V from the onboard regulator. Pin 2 is tied directly to the 5V USB-C input rail. If you accidentally wire a 5V sensor's VCC to Pin 1, it will brownout the 3V3 regulator. Worse, if you feed 5V into Pin 1, you will instantly destroy the 3V3 PMIC and likely the Broadcom SoC. Always verify Pin 1 orientation before applying power.
2. Pins 3 & 5 (I2C1 SDA/SCL) and the 1.8k Pull-Up Trap
GPIO 2 and GPIO 3 are the hardware I2C bus. On the Pi, these pins have physical 1.8kΩ pull-up resistors wired directly to the 3V3 rail. If you connect a 5V I2C device (like an older Arduino sensor) without a logic level shifter, the 5V device will push 5V back through the sensor's data lines, through the Pi's 1.8k pull-ups, and directly into the 3V3 rail. This backfeed bypasses the regulator and can fry 3.3V components on the board.
3. Pins 27 & 28 (ID_SD / ID_SC)
These pins form a dedicated I2C0 bus reserved exclusively for reading the EEPROM on Raspberry Pi HATs (Hardware Attached on Top). They are not general-purpose GPIOs. Driving these pins as standard outputs can interfere with HAT enumeration during boot and cause unpredictable I2C bus lockups.
Peripheral Decision Tree: Which Pin Should You Actually Use?
Do not assign GPIO pins randomly. Hardware-accelerated peripherals are mapped to specific pins. Use this decision path to select the correct pins for your circuit, terminating in a concrete wiring choice.
| If your peripheral requires... | Then choose this interface... | Concrete Pin Pick (BCM Numbering) |
|---|---|---|
| I2C (OLEDs, BME280, MPU6050) | Hardware I2C1 | GPIO 2 (SDA) & GPIO 3 (SCL) |
| SPI (High-speed ADCs, TFT LCDs) | Hardware SPI0 | GPIO 9 (MISO), 10 (MOSI), 11 (SCLK), 8 (CE0) |
| UART (GPS modules, Console Debug) | Hardware UART0 (PL011) | GPIO 14 (TXD) & GPIO 15 (RXD) |
| Hardware PWM (Motor drivers, Servos) | PWM0 / PWM1 | GPIO 18 (PWM0) or GPIO 13 (PWM1) |
| Simple Digital I/O (Buttons, Relays) | Standard GPIO | GPIO 17, 22, 23, 24, 25, 26, 27 (Avoid 2/3/14/15) |
sudo raspi-config (Interface Options -> Serial Port -> Login shell: No, Serial hardware: Yes), otherwise your data will be corrupted by boot logs.
Safe Interpretation When Silk-Screen Markings Fade or Fail
On older Pi models, or when using a bare Compute Module 4 on a custom carrier board, the physical '1', '2', '3', '4' silk-screen numbers next to the header may be missing, faded, or obscured by a HAT.
Never guess Pin 1 based on the USB ports. Instead, use these physical verification methods:
- The Square Pad Rule: Flip the board over. Look at the solder joints for the GPIO header on the bottom of the PCB. Pin 1 is universally designated by a square solder pad, while all other pins (2 through 40) have round solder pads. This is an IPC-standard PCB design convention that holds true even if the top silk-screen is completely sanded off.
- The Ground Continuity Test: If the board is in an enclosure and you cannot see the bottom, set your multimeter to continuity mode. Probe the metal USB port shielding or the metal Ethernet jack housing (which is tied to system ground). Touch your other probe to the suspected ground pins on the header (Pins 6, 9, 14, 20, 25, 30, 34, 39). The ones that beep are grounds. Pin 1 is the 3V3 pin immediately adjacent to the ground pin that is closest to the SD card/USB-C edge of the board.
- Voltage Verification: With the Pi powered on, set your meter to DC Volts. Place the black probe on a known ground (USB shield). Probe the corner pins. The pin that reads exactly 3.2V to 3.3V is Pin 1. The pin next to it reading 4.9V to 5.1V is Pin 2. Do not use the 5V pins to orient yourself if you are using a USB-C PD power supply that negotiates higher voltages, as some Pi 5 active coolers and PD triggers can briefly spike this rail during handshake.
By anchoring your wiring to the square pad and adhering strictly to the Maker DC color code (Red/Black/Yellow), you eliminate the most common vectors for GPIO-related hardware failure. Always double-check your physical pin mapping against the software BCM (Broadcom) numbering in your Python or C++ code before executing your script.






