The Raspberry Pi 4B features a 40-pin header mapping to 26 usable Broadcom (BCM) GPIOs, alongside dedicated I2C, SPI, UART, and hardware PWM channels. Physical Pin 1 supplies 3.3V and is located closest to the USB-C power port and SD card slot. When writing Python scripts, always default to BCM numbering unless you are manually wiring a physical harness.
The Complete Raspberry Pi 4B Pinout Table
The table below maps the physical header layout (left and right columns) to the BCM GPIO numbers and primary functions. Use this as your bench reference when wiring sensors or debugging HATs. For a visual overlay, cross-reference with the official Pinout.xyz interactive diagram.
| Phys | BCM | Function | Phys | BCM | Function |
|---|---|---|---|---|---|
| 1 | - | 3.3V Power | 2 | - | 5V Power |
| 3 | 2 | GPIO2 (SDA1) | 4 | - | 5V Power |
| 5 | 3 | GPIO3 (SCL1) | 6 | - | Ground |
| 7 | 4 | GPIO4 (GPCLK0) | 8 | 14 | GPIO14 (TXD) |
| 9 | - | Ground | 10 | 15 | GPIO15 (RXD) |
| 11 | 17 | GPIO17 | 12 | 18 | GPIO18 (PWM0) |
| 13 | 27 | GPIO27 | 14 | - | Ground |
| 15 | 22 | GPIO22 | 16 | 23 | GPIO23 |
| 17 | - | 3.3V Power | 18 | 24 | GPIO24 |
| 19 | 10 | GPIO10 (MOSI) | 20 | - | Ground |
| 21 | 9 | GPIO9 (MISO) | 22 | 25 | GPIO25 |
| 23 | 11 | GPIO11 (SCLK) | 24 | 8 | GPIO8 (CE0) |
| 25 | - | Ground | 26 | 7 | GPIO7 (CE1) |
| 27 | 0 | GPIO0 (ID_SD) | 28 | 1 | GPIO1 (ID_SC) |
| 29 | 5 | GPIO5 | 30 | - | Ground |
| 31 | 6 | GPIO6 | 32 | 12 | GPIO12 (PWM0) |
| 33 | 13 | GPIO13 (PWM1) | 34 | - | Ground |
| 35 | 19 | GPIO19 (MISO1) | 36 | 16 | GPIO16 (CE2) |
| 37 | 26 | GPIO26 | 38 | 20 | GPIO20 (MOSI1) |
| 39 | - | Ground | 40 | 21 | GPIO21 (SCLK1) |
Rows People Get Wrong (And How They Brick Your Pi)
Misinterpreting the pinout table is the leading cause of dead Raspberry Pi boards on the workbench. Here are the specific rows that cause hardware failures:
- Physical Pin 1 vs. BCM 1: Physical Pin 1 outputs 3.3V power. BCM GPIO 1 is actually Physical Pin 28 (ID_SC). If you wire a 5V component to Physical Pin 1 expecting a data line, you will short the 3.3V regulator. Always declare
GPIO.setmode(GPIO.BCM)in Python to avoid this confusion. - Pins 3 & 5 (I2C SDA/SCL): These pins have hardwired 1.8kΩ pull-up resistors to 3.3V on the Pi PCB. Do not use them for standard digital inputs or open-drain outputs that require 5V pull-ups, as the onboard resistors will fight your external circuit.
- Pins 27 & 28 (ID_SD / ID_SC): Reserved exclusively for HAT EEPROM identification. Using these for general I/O can cause boot failures if a HAT is attached, as the Pi reads these pins during the early boot sequence to configure the device tree.
Wiring Color Standards: IEC vs. US Conventions
When crimping custom JST-XH harnesses or wiring terminal blocks to the Pi's GPIOs, regional standards dictate your wire colors. Mixing these up leads to reversed polarity and fried sensors.
| Wire Function | IEC 60446 / DIN (EU/Global DC) | US Hobbyist / EIA Standard | Standard 40-Pin Ribbon |
|---|---|---|---|
| Positive (VCC / 3.3V or 5V) | Brown | Red | Red Stripe (Pin 1) |
| Negative (Ground) | Blue | Black | Black / Dark Grey |
| Signal / Data | Black or White | Yellow, White, or Orange | Color-coded per pin |
Which standard applies to you? If you are building industrial enclosures or exporting to Europe, strictly adhere to IEC 60446 (Brown/Blue). If you are prototyping with standard Adafruit/SparkFun sensor breakout boards, they almost universally use the US EIA convention (Red/Black/Yellow). Never assume a pre-crimped cable follows IEC; always verify with a multimeter before applying power.
Safe Identification When Markings Are Faded
On older Pi 4B boards, or when the board is mounted in a cramped enclosure, the silkscreen pin numbers wear off or become hidden. Here is how to safely identify your pins without guessing:
- Find Ground First: Set your multimeter to continuity mode. Probe the metal shield of the USB-C port or any of the four mounting holes (which are tied to ground). Probe the header pins; the ones that beep are your GND pins (Physical 6, 9, 14, 20, 25, 30, 34, 39).
- Verify the Rails: Power the Pi via USB-C. Set the meter to DC Voltage. Place the black probe on a confirmed GND pin. Probe Physical Pin 2 (should read 4.9V–5.1V) and Physical Pin 1 (should read 3.28V–3.32V). If Pin 1 reads 0V, your onboard 3.3V polyfuse has tripped or the PMIC is dead.
- Identify Pin 1 Orientation: Pin 1 is always the corner pin closest to the SD card slot and the USB-C power jack. Pin 2 is directly across from it on the inner row.
GPIO Selection Decision Tree
Not all GPIOs are created equal. Some have boot-time conflicts, while others are tied to specific hardware controllers. Use this decision matrix to select the exact pin for your next component.
| Application Need | Required Feature | Concrete Pick (BCM) | Why This Pin Wins |
|---|---|---|---|
| Servo / Motor Control | Hardware PWM | BCM 18 | True hardware PWM0 channel. Zero software jitter compared to software PWM on other pins. |
| Temperature / OLED Sensor | I2C Bus | BCM 2 & 3 | The primary I2C1 bus with onboard 1.8kΩ pull-ups. No external resistors needed. |
| RFID / High-Speed Display | SPI Bus | BCM 10, 9, 11, 8 | Primary SPI0 bus. BCM 8 is Chip Enable 0 (CE0), BCM 7 is CE1. Maximum hardware throughput. |
| GPS Module / Console | Hardware UART | BCM 14 & 15 | Primary UART (TX/RX). Note: You must disable the serial console in raspi-config to free these pins. |
| Limit Switches / Buttons | Safe General I/O | BCM 17, 27, 22 | Completely safe. No boot-strapping conflicts, no default pull-ups/downs that fight external circuits. |
Default Recommendation: If you just need a generic digital output to trigger a relay module and have no specific protocol requirements, wire it to BCM 17 (Physical Pin 11). It has no alternate boot functions, no hardware pull-ups, and will not cause the Pi to hang during the boot sequence if held low.






