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)
13.3V Power--5V Power2
3I2C SDA12-5V Power4
5I2C SCL13-Ground6
7GPIO414UART TXD8
9Ground-15UART RXD10
11GPIO1718PCM CLK / PWM012
13GPIO / PWM127-Ground14
15GPIO2223GPIO16
173.3V Power-24GPIO18
19SPI MOSI10-Ground20
21SPI MISO925GPIO22
23SPI SCLK118SPI CE024
25Ground-7SPI CE126
27I2C SDA0 (ID)01I2C SCL0 (ID)28
29GPIO5-Ground30
31GPIO612GPIO / PWM032
33GPIO / PWM113-Ground34
35PCM FS / SPI MISO1916GPIO36
37GPIO2620GPIO / SPI MOSI38
39Ground-21GPIO / SPI SCLK40
Bench Note: Pins 27 and 28 (BCM 0 and 1) are reserved for the HAT ID EEPROM I2C bus. Do not use these for general sensors; the Pi queries them during boot to auto-configure hardware.

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 YellowN/A (Extra-low voltage)N/A
Logic Power (5V)RedN/AN/A
Logic GroundBlackGreen/Yellow StripeGreen or Bare
Signal / DataBlue, Green, WhiteBrown, Black, Grey (Phases)Black, Red, Blue (Phases)
AC Neutral (Load Side)Never use on PiBlueWhite or Grey
AC Earth (Load Side)Never use on PiGreen/Yellow StripeGreen 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.

Safety Warning: When working with Pi HATs or custom PCBs that mate directly to the 40-pin header, a 1-pin offset (shifting the connector by one row) will route 5V directly into a GPIO or Ground pin. Always visually verify alignment from both the top and bottom of the board before applying power.

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:

  1. 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.
  2. 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).
  3. 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.
  4. 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.