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 Power5V Power-2
32SDA1 (I2C1)5V Power-4
53SCL1 (I2C1)GND-6
74GPIO4 (GPCLK0)TXD (UART)148
9-GNDRXD (UART)1510
1117GPIO17GPIO18 (PWM0)1812
1327GPIO27GND-14
1522GPIO22GPIO232316
17-3.3V PowerGPIO242418
1910MOSI (SPI0)GND-20
219MISO (SPI0)GPIO252522
2311SCLK (SPI0)CE0 (SPI0)824
25-GNDCE1 (SPI0)726
270SDA0 (I2C0 / ID)SCL0 (I2C0 / ID)128
295GPIO5GND-30
316GPIO6GPIO12 (PWM0)1232
3313GPIO13 (PWM1)GND-34
3519MISO (SPI1 / PWM1)GPIO161636
3726GPIO26GPIO20 (SPI1)2038
39-GNDMOSI (SPI1)2140

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 5V Trap (Pins 2 & 4 vs. Pins 1 & 17): Pins 2 and 4 supply 5V directly from the USB-C power input. The GPIO pins (like BCM 2 on Pin 3) are strictly 3.3V tolerant. Feeding a 5V signal into BCM 2 will instantly destroy that GPIO bank and can back-feed into the PMIC (Power Management IC), killing the board. Always use a logic level shifter (like the TXB0108 or BSS138) when interfacing with 5V Arduino peripherals.

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 PowerRedRedPin 1 Red Stripe (if 5V on Pin 1)
3.3V PowerRed (causes confusion)OrangeN/A
Ground (GND)BlackBlack or Blue (IEC DC)Black / Dark Grey
I2C / SPI SignalsYellow / GreenYellow (Data), Green (Clock)Multi-color rainbow
Pro Tip: Never use standard IEC 60446 mains colors (Brown for Line, Blue for Neutral) for low-voltage DC logic on the Pi. While technically legal in some low-voltage DC contexts, it creates severe confusion if the project later integrates a mains-powered relay module. Stick to Orange for 3.3V, Red for 5V, and Black for GND.

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:

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