The physical 40-pin (2x20) header on the Raspberry Pi has remained mechanically identical since the Model B+, but treating a Pi 5 the same as a Pi 3 is a fast way to fry a sensor. The Raspberry Pi pinout maps to the Broadcom (BCM) SoC pins, not physical pin numbers. If you are wiring a new project, the direct answer is: always use BCM numbering in your code, physically verify Pin 1 via the square solder pad before applying power, and never backfeed 5V into the 3.3V rail.
The 40-Pin Raspberry Pi Pinout Reference Map
The table below maps the physical header to Broadcom (BCM) GPIO numbers and alternate functions. Read it left-to-right, matching the physical pins on your board. Pins 27-40 (the bottom 14 pins) are predominantly standard GPIOs and additional ground/power lines, detailed in the notes below the table.
| Pin (L) | Function (Left Column) | BCM (L) | BCM (R) | Function (Right Column) | Pin (R) |
|---|---|---|---|---|---|
| 1 | 3.3V Power | - | - | 5V Power | 2 |
| 3 | I2C SDA1 | 2 | - | 5V Power | 4 |
| 5 | I2C SCL1 | 3 | - | Ground | 6 |
| 7 | GPIO | 4 | 14 | UART TXD | 8 |
| 9 | Ground | - | 15 | UART RXD | 10 |
| 11 | GPIO | 17 | 18 | PCM CLK / PWM0 | 12 |
| 13 | GPIO / PWM1 | 27 | - | Ground | 14 |
| 15 | GPIO | 22 | 23 | GPIO | 16 |
| 17 | 3.3V Power | - | 24 | GPIO | 18 |
| 19 | SPI MOSI | 10 | - | Ground | 20 |
| 21 | SPI MISO | 9 | 25 | GPIO | 22 |
| 23 | SPI SCLK | 11 | 8 | SPI CE0 | 24 |
| 25 | Ground | - | 7 | SPI CE1 | 26 |
| 27 | I2C SDA0 (ID) | 0 | 1 | I2C SCL0 (ID) | 28 |
| 29 | GPIO | 5 | - | Ground | 30 |
| 31 | GPIO | 6 | 12 | GPIO / PWM0 | 32 |
| 33 | GPIO / PWM1 | 13 | - | Ground | 34 |
| 35 | PCM FS / SPI MISO | 19 | 16 | GPIO | 36 |
| 37 | GPIO | 26 | 20 | GPIO / SPI MOSI | 38 |
| 39 | Ground | - | 21 | GPIO / SPI SCLK | 40 |
Wire Color Standards: GPIO Dupont vs. IEC/NEC Mains
The Raspberry Pi ecosystem does not have a legally mandated wire color code. However, a de facto standard exists for low-voltage Dupont jumper wires, which heavily conflicts with international mains wiring standards. When your Pi project interfaces with relays, contactors, or AC loads, you must switch your mental model from hobbyist colors to regional electrical codes.
| Function | Hobbyist Dupont (Pi GPIO) | IEC 60446 (EU/UK/AU) | NEC (US/Canada) |
|---|---|---|---|
| Logic Power (3.3V) | Orange or Yellow | N/A (Extra-low voltage) | N/A |
| Logic Power (5V) | Red | N/A | N/A |
| Logic Ground | Black | Green/Yellow Stripe | Green or Bare |
| Signal / Data | Blue, Green, White | Brown, Black, Grey (Phases) | Black, Red, Blue (Phases) |
| AC Neutral (Load Side) | Never use on Pi | Blue | White or Grey |
| AC Earth (Load Side) | Never use on Pi | Green/Yellow Stripe | Green or Bare |
If you are wiring a Pi to a 5V relay module that switches 120V/230V AC, the low-voltage side uses the Dupont colors (Red for 5V VCC, Black for GND, Yellow for IN). The high-voltage load side must use IEC or NEC color codes depending on your region. Never run a red Dupont wire into a 120V AC terminal block; an inspector or future maintainer will assume it is a live phase conductor. For deep dives into regional wiring codes, reference the IEC and NEC wiring color standards.
Rows People Get Wrong (and Fried Board Prevention)
Most destroyed Raspberry Pi boards are the result of misinterpreting three specific rows on the header. Here is what the rows mean in practice and how they fail.
Row 1 & 2: The 3.3V vs 5V Trap
Pin 1 outputs 3.3V. Pin 2 outputs 5V. The Pi SoC operates at 3.3V logic. If you accidentally wire a 5V sensor's data line to a GPIO pin, or wire Pin 2 (5V) into a breadboard rail you designated for 3.3V, you will instantly destroy the Broadcom SoC's input protection diodes. Rule: Always measure the breadboard power rails with a multimeter before plugging in the Pi's GPIO wires.
Row 2 & 3: The I2C Pull-Up Backfeed
Pins 3 and 5 (BCM 2 and 3) are the primary I2C bus. On the Pi board, these pins have hardwired 1.8kΩ pull-up resistors tied to the 3.3V rail. If you connect a 5V I2C device (like an older Arduino or a 5V LCD backpack) to these pins without a logic level shifter, the 5V device will pull the line high to 5V. That 5V will travel backward through the Pi's pull-up resistors directly into the 3.3V rail, potentially corrupting the Pi's power management IC (PMIC).
Row 4 & 5: The UART Boot Garbage
Pins 8 and 10 (BCM 14 and 15) are the primary UART TX/RX lines. By default, the Pi outputs kernel boot logs to the TX pin (Pin 8) on startup. If you connect a sensitive serial device (like a motor controller that accepts UART commands) to these pins, the boot garbage will be interpreted as random commands, causing the motor to spin unpredictably on power-up.
Decision Path: Which GPIO Pin Should You Actually Use?
Do not just pick random pins. Use this decision tree to select the optimal pin for your specific hardware requirement, terminating in a concrete default pick.
| Your Task | Condition / Requirement | Concrete Pin Pick (BCM / Physical) |
|---|---|---|
| Hardware PWM (Motor/LED dimming) | Need true hardware PWM, not software jitter. | BCM 12 / Pin 32 (PWM0) or BCM 13 / Pin 33 (PWM1) |
| I2C Sensor (Temp/Humidity) | Standard 400kHz I2C device, 3.3V logic. | BCM 2 / Pin 3 (SDA) and BCM 3 / Pin 5 (SCL) |
| SPI Display (TFT/OLED) | High-speed data transfer required. | BCM 10 (MOSI), 9 (MISO), 11 (SCLK), 8 (CE0) |
| Generic Button / Limit Switch | Needs internal pull-up, no boot conflicts. | BCM 17 / Pin 11 (Safe default, no alternate boot functions) |
| Relay Trigger (Active Low) | Driving an optocoupler relay module. | BCM 27 / Pin 13 (Defaults to LOW on boot, prevents relay chatter) |
The Ultimate Default: If you just need a generic digital I/O pin for an LED or a button and don't want to think about boot states or alternate functions, use BCM 17 (Physical Pin 11). It is safe, well-documented, and has no hidden hardware conflicts.
Safe Interpretation When Silkscreen Markings Fade
On older Pi models (like the Pi 1 Model B+ or early Pi 2s), the silkscreen text on the PCB indicating "5V", "GND", or "3V3" often rubs off, and the plastic shroud can hide the pin numbers. Never guess based on wire colors from a previous project.
To safely identify the pinout on an unmarked or faded board:
- Locate Pin 1 physically: Pin 1 is always the pin with the square solder pad on the underside of the PCB. All other pads are round.
- Use the board edge: Pin 1 is always located in the corner closest to the SD card slot and the main power input (Micro-USB or USB-C).
- Look for the silkscreen triangle: Most Pi boards feature a tiny white triangle or a "P1" / "J8" designation printed on the PCB near Pin 1.
- Verify with a multimeter: Power the board via USB. Set your multimeter to DC Voltage. Place the black probe on a USB port shell (ground) and probe the suspected Pin 2. It should read 5.0V to 5.2V. Probe Pin 1; it should read exactly 3.3V. If your readings differ, your board may have a blown polyfuse or PMIC fault.
For the most up-to-date software mappings and device tree overlays, always cross-reference your physical wiring with the official Raspberry Pi GPIO and configuration documentation. Code libraries like RPi.GPIO and gpiozero default to BCM numbering; ensure your physical wiring matches the BCM column in the table above, not the physical pin numbers.






