The Raspberry Pi 4 Model B features a 40-pin GPIO header operating strictly at 3.3V logic. Pin 1 (top-left when USB ports face you) supplies 3.3V, while Pin 2 supplies 5V. For all software development in Python, C, or Node.js, always use the BCM (Broadcom) numbering scheme, as physical pin numbers do not map sequentially to the internal BCM2711 SoC registers. Below is the definitive reference for hardware wiring, protocol selection, and safe interpretation of the Pi 4 header.
The Complete 40-Pin Raspberry Pi 4 GPIO Pinout Table
This table maps the physical header layout directly to the Broadcom (BCM) GPIO numbers used in software libraries like RPi.GPIO and gpiozero. Read the left column for the left-hand row of pins, and the right column for the right-hand row.
| Phys | BCM | Function / Name | Function / Name | BCM | Phys |
|---|---|---|---|---|---|
| 1 | - | 3.3V Power | 5V Power | - | 2 |
| 3 | 2 | SDA1 (I2C1) | 5V Power | - | 4 |
| 5 | 3 | SCL1 (I2C1) | GND | - | 6 |
| 7 | 4 | GPIO4 (GPCLK0) | TXD (UART) | 14 | 8 |
| 9 | - | GND | RXD (UART) | 15 | 10 |
| 11 | 17 | GPIO17 | GPIO18 (PWM0) | 18 | 12 |
| 13 | 27 | GPIO27 | GND | - | 14 |
| 15 | 22 | GPIO22 | GPIO23 | 23 | 16 |
| 17 | - | 3.3V Power | GPIO24 | 24 | 18 |
| 19 | 10 | MOSI (SPI0) | GND | - | 20 |
| 21 | 9 | MISO (SPI0) | GPIO25 | 25 | 22 |
| 23 | 11 | SCLK (SPI0) | CE0 (SPI0) | 8 | 24 |
| 25 | - | GND | CE1 (SPI0) | 7 | 26 |
| 27 | 0 | SDA0 (I2C0 / ID) | SCL0 (I2C0 / ID) | 1 | 28 |
| 29 | 5 | GPIO5 | GND | - | 30 |
| 31 | 6 | GPIO6 | GPIO12 (PWM0) | 12 | 32 |
| 33 | 13 | GPIO13 (PWM1) | GND | - | 34 |
| 35 | 19 | MISO (SPI1 / PWM1) | GPIO16 | 16 | 36 |
| 37 | 26 | GPIO26 | GPIO20 (SPI1) | 20 | 38 |
| 39 | - | GND | MOSI (SPI1) | 21 | 40 |
Rows People Get Wrong (And How to Avoid Bricking Your Pi)
The BCM2711 SoC on the Pi 4 is highly capable but unforgiving of voltage abuse. These are the most common pinout mistakes that lead to permanent hardware failure:
The EEPROM Reserve (Pins 27 & 28): These map to BCM 0 (SDA0) and BCM 1 (SCL0). While they look like standard I2C pins, they are connected to the I2C0 bus, which the Pi's bootloader uses to probe the ID EEPROM on attached HATs (Hardware Attached on Top). Using these for general-purpose I/O or attaching external pull-up resistors to them can cause boot failures or prevent HAT auto-configuration.
The UART Cross (Pins 8 & 10): Pin 8 is TXD (Transmit) and Pin 10 is RXD (Receive). Beginners frequently wire TX to TX and RX to RX. Remember: the Pi's TX must connect to the peripheral's RX, and the Pi's RX must connect to the peripheral's TX. Furthermore, you must disable the Linux serial console via sudo raspi-config (Interface Options > Serial Port > Login shell: No, Hardware: Yes) before using these pins for external devices.
Wire Color Standards: Pi HATs vs. General Electronics
When wiring custom harnesses or designing PCBs that mate with the Pi 4, adhering to a strict color code prevents catastrophic misalignment. Standard DC electronics and US/UK hobbyist norms generally dictate Red for VCC and Black for GND. However, the official Raspberry Pi HAT Design Guide and industrial control conventions require more granularity.
| Signal Type | Standard Hobbyist Jumper | Industrial / HAT Harness Standard | IDC Ribbon Cable (40-pin) |
|---|---|---|---|
| 5V Power | Red | Red | Pin 1 Red Stripe (if 5V on Pin 1) |
| 3.3V Power | Red (causes confusion) | Orange | N/A |
| Ground (GND) | Black | Black or Blue (IEC DC) | Black / Dark Grey |
| I2C / SPI Signals | Yellow / Green | Yellow (Data), Green (Clock) | Multi-color rainbow |
Safe Interpretation When Silkscreen Markings Are Faded or Missing
If you are working with a heavily used Pi 4, a cloned board, or a custom compute module carrier board where the "P1" silkscreen and pin numbers have worn off, do not guess. Use these physical and electrical verification steps to safely map the header:
- The Square Pad Rule: Flip the board over or look closely at the solder joints on the top. Pin 1 is universally designated by a square through-hole pad, while all other pins (2 through 40) have circular pads. This is an IPC-7351 PCB design standard that virtually all manufacturers follow.
- The USB Shield Continuity Test: Set your multimeter to continuity mode (the diode/beep setting). Place one probe on the metal shield of the USB ports (which is tied to system ground). Probe the header pins. Pins 6, 9, 14, 20, 25, 30, 34, and 39 will beep, confirming they are GND. This anchors your orientation.
- Voltage Verification (Live Testing): If the board is powered, set your multimeter to DC Voltage. Place the black probe on a confirmed GND pin. Probe the top row (adjacent to the USB ports). You will read ~5.0V on Pins 2 and 4, and ~3.3V on Pin 1. This definitively confirms the top-left orientation.
Protocol Decision Path: Which Pins Should You Use?
The BCM2711 supports multiple alternate functions (ALT modes) for many pins, meaning a single pin can sometimes act as UART, SPI, or PWM depending on software configuration. To avoid conflicts, use this decision tree to select your default hardware interfaces. For deeper visual mapping, cross-reference your physical layout with the interactive Pinout.xyz database.
| If you need... | Then use these BCM Pins (Physical) | Concrete Default Pick | Software / OS Prerequisite |
|---|---|---|---|
| I2C (Sensors, OLEDs) | BCM 2 (Pin 3) & BCM 3 (Pin 5) | Use I2C1 bus. Add 4.7kΩ pull-ups to 3.3V if module lacks them. | Enable I2C in raspi-config. |
| SPI (High-speed ADCs, Displays) | BCM 10, 9, 11, 8 (Pins 19, 21, 23, 24) | Use SPI0. BCM 8 is CE0, BCM 7 (Pin 26) is CE1. | Enable SPI in raspi-config. |
| Hardware PWM (Motor control, LEDs) | BCM 12, 13, 18, 19 | Use BCM 18 (Pin 12). It is the most universally supported PWM pin across all Pi OS audio configurations. | None, but disable onboard audio if using PCM pins. |
| UART (GPS, Serial Console) | BCM 14 (Pin 8) & BCM 15 (Pin 10) | Use PL011 UART (BCM 14/15). Avoid mini-UART (BCM 14/15 ALT5) due to baud rate clock drift. | Disable serial login shell in raspi-config. |
When designing a permanent installation, always default to the primary hardware buses (I2C1, SPI0, PL011 UART, and BCM 18 for PWM). Bit-banging these protocols on arbitrary GPIO pins in Python introduces severe timing jitter and CPU overhead, which will cause intermittent failures in industrial or high-throughput sensor environments.






