When wiring sensors, relays, or HATs to a Raspberry Pi, confusing physical pin numbers with Broadcom (BCM) GPIO numbers is the fastest way to short a 3.3V logic rail to a 5V power line. Below is the definitive, table-forward reference for the 40-pin header found on the Pi 3, 4, 400, and 5 (note: the Pi 5 routes GPIO through the RP1 southbridge chip, but the physical header layout remains backward-compatible).
The 40-Pin Header: Physical vs BCM Mapping
This table maps the physical board pins (1-40) to their BCM GPIO equivalents and primary functions. Read it with the Pi oriented so the USB ports face you and the GPIO header is on the top-left.
| Phys (Left) | BCM | Function / Name | Function / Name | BCM | Phys (Right) |
|---|---|---|---|---|---|
| 1 | - | 3.3V Power | 5V Power | - | 2 |
| 3 | 2 | GPIO2 (SDA1 / I2C) | 5V Power | - | 4 |
| 5 | 3 | GPIO3 (SCL1 / I2C) | Ground | - | 6 |
| 7 | 4 | GPIO4 (GPCLK0) | GPIO14 (TXD0 / UART) | 14 | 8 |
| 9 | - | Ground | GPIO15 (RXD0 / UART) | 15 | 10 |
| 11 | 17 | GPIO17 (SPI1_CE1) | GPIO18 (PCM_CLK / PWM0) | 18 | 12 |
| 13 | 27 | GPIO27 (PCM_DOUT) | Ground | - | 14 |
| 15 | 22 | GPIO22 (PCM_DIN) | GPIO23 (SPI1_SCLK) | 23 | 16 |
| 17 | - | 3.3V Power | GPIO24 (SPI1_CE0) | 24 | 18 |
| 19 | 10 | GPIO10 (SPI0_MOSI) | Ground | - | 20 |
| 21 | 9 | GPIO9 (SPI0_MISO) | GPIO25 | 25 | 22 |
| 23 | 11 | GPIO11 (SPI0_SCLK) | GPIO8 (SPI0_CE0) | 8 | 24 |
| 25 | - | Ground | GPIO7 (SPI0_CE1) | 7 | 26 |
| 27 | 0 | GPIO0 (ID_SD / I2C HAT) | GPIO1 (ID_SC / I2C HAT) | 1 | 28 |
| 29 | 5 | GPIO5 (GPCLK1) | Ground | - | 30 |
| 31 | 6 | GPIO6 (GPCLK2) | GPIO12 (PWM0) | 12 | 32 |
| 33 | 13 | GPIO13 (PWM1) | Ground | - | 34 |
| 35 | 19 | GPIO19 (PCM_FS) | GPIO16 (SPI1_CE2) | 16 | 36 |
| 37 | 26 | GPIO26 | GPIO20 (PCM_DIN) | 20 | 38 |
| 39 | - | Ground | GPIO21 (PCM_DOUT) | 21 | 40 |
Source: Official Raspberry Pi GPIO Documentation and the Pinout.xyz interactive reference.
The Rows People Get Wrong (And How They Fry the Board)
Even experienced makers brick their boards by misinterpreting this table. Here are the specific failure modes you need to avoid.
The Raspberry Pi operates on strict 3.3V logic. Feeding a 5V signal into any BCM GPIO pin (like BCM 17 on Physical Pin 11) will permanently destroy the RP1 southbridge (Pi 5) or the BCM2711/2837 SoC (Pi 4 and older). Always use a logic level shifter (like the TXS0108E) or a voltage divider when interfacing with 5V Arduino components.
1. Physical Pin 1 vs. BCM GPIO 1
Physical Pin 1 outputs 3.3V power. BCM GPIO 1 is Physical Pin 28, used for the HAT ID EEPROM. If your Python script calls GPIO.setup(1, GPIO.OUT) using the BOARD numbering scheme, you are toggling the 3.3V power rail, not a logic pin. Always explicitly define your numbering scheme in code: GPIO.setmode(GPIO.BCM) is the industry standard for Python/RPi.GPIO.
2. The I2C ID Pins (Physical 27 & 28)
BCM 0 and BCM 1 (Physical 27 and 28) are reserved for the HAT identification EEPROM. They have 1.8kΩ pull-up resistors to 3.3V on the board. Do not use these for general-purpose I2C sensors; use BCM 2 and BCM 3 (Physical 3 and 5) instead.
3. The UART Swap (Pi 3, 4, and 5)
Physical pins 8 and 10 (BCM 14 and 15) are the primary UART TX/RX lines. However, on boards with built-in Bluetooth, the primary hardware UART (/dev/ttyAMA0) is often routed to the Bluetooth module, leaving the mini-UART (/dev/ttyS0) on the GPIO header. The mini-UART lacks baud rate stability. If you need reliable serial communication for GPS or industrial RS-485 adapters, disable Bluetooth in /boot/config.txt (dtoverlay=disable-bt) to reclaim the hardware UART for the header.
GPIO Wiring Color Codes: Regional Harness Standards
When building custom wiring harnesses, ribbon cables, or terminal block pigtails for the Pi, relying on random Dupont wire colors leads to disastrous debugging sessions. Professional harness builders follow regional low-voltage DC standards. Here is how the standards map to Pi GPIO wiring.
| Function | IEC 60204-1 (EU / UK / Global) | NEC NFPA 79 (US / Canada) | Legacy / Old UK (Pre-2004) | Hobbyist Standard |
|---|---|---|---|---|
| DC Power (+5V) | Red | Red | Red | Red |
| Logic Power (+3.3V) | Orange | Orange | Orange | Orange |
| DC Ground (0V / GND) | Black or Blue | Black or White (if grounded) | Black | Black |
| I2C SDA / SPI MISO | Yellow | Yellow | Yellow | Blue |
| I2C SCL / SPI SCLK | Green | Green | Green | Yellow |
| UART TX / RX | Grey / Violet | Grey / Violet | - | Green / White |
Which standard should you use? If you are building an enclosure that will be inspected under CE marking (EU) or UL standards (US), strictly follow IEC 60204-1 or NFPA 79 respectively. For bench prototypes, the "Hobbyist Standard" (Red=5V, Orange=3.3V, Black=GND, Blue=SDA, Yellow=SCL) is universally understood in the maker community and matches the color coding used by Adafruit and SparkFun breakout boards.
Safe Interpretation When Markings Are Faded or Missing
On older Pi boards, or when using bare Compute Module 4 (CM4) breakout boards, the silkscreen pin numbers may be missing, worn off, or obscured by a HAT. Here is how to safely identify your pins without guessing.
1. The Physical Pin 1 Indicators
Physical Pin 1 is always located on the corner closest to the SD card slot (or eMMC on CM4). If you cannot see the top silkscreen, flip the board over. Pin 1 is the only pad on the GPIO header that is square; all other solder pads are circular. Furthermore, Pin 1 is always the outermost pin on the row closest to the edge of the PCB.
2. Verifying with a Multimeter
Before connecting sensitive logic, power the Pi and use a digital multimeter (DMM) to verify the power rails. Set your DMM to DC Voltage. Place the black probe on a known chassis ground or the metal shield of a USB port. Probe the suspected 3.3V pin (Physical 1 or 17); it should read between 3.28V and 3.32V. Probe the 5V pin (Physical 2 or 4); it should read between 4.9V and 5.1V. If your 5V rail reads below 4.7V, you have excessive voltage drop on your USB-C power supply or cable—do not attach high-draw peripherals until you resolve the brownout risk.
3. The Software Verification Trick
If the board is booted and you have SSH access, the Raspberry Pi OS includes a built-in terminal utility. Simply type:
pinout
This renders a color-coded ASCII diagram of the exact pinout for your specific board model directly in the terminal, including the board revision, RAM, and SoC type, eliminating any hardware ambiguity.






