The Raspberry Pi 4 Model B uses a standard 40-pin GPIO header featuring 26 usable GPIO pins, 8 ground pins, and 6 power pins. Below is the exact physical raspberry pi 4 model b pinout, followed by the decision framework required to wire external sensors and power supplies safely without frying the BCM2711 SoC.

The 40-Pin GPIO Physical Reference Table

Read this table looking down at the Pi with the USB ports facing you and the GPIO header on the top right. Pin 1 is the top-left pin (closest to the USB-C power connector). Pins are numbered odd on the left column, even on the right.

Left (Odd) Function / BCM Function / BCM Right (Even)
13.3V Power5V Power2
3GPIO 2 (SDA1 / I2C)5V Power4
5GPIO 3 (SCL1 / I2C)Ground6
7GPIO 4 (GPCLK0)GPIO 14 (TXD / UART)8
9GroundGPIO 15 (RXD / UART)10
11GPIO 17GPIO 18 (PCM_CLK / PWM0)12
13GPIO 27Ground14
15GPIO 22GPIO 2316
173.3V PowerGPIO 2418
19GPIO 10 (MOSI / SPI0)Ground20
21GPIO 9 (MISO / SPI0)GPIO 2522
23GPIO 11 (SCLK / SPI0)GPIO 8 (CE0 / SPI0)24
25GroundGPIO 7 (CE1 / SPI0)26
27GPIO 0 (ID_SD / I2C)GPIO 1 (ID_SC / I2C)28
29GPIO 5Ground30
31GPIO 6GPIO 12 (PWM0)32
33GPIO 13 (PWM1)Ground34
35GPIO 19 (MISO1 / SPI1)GPIO 16 (CE2 / SPI1)36
37GPIO 26GPIO 20 (MOSI1 / SPI1)38
39GroundGPIO 21 (SCLK1 / SPI1)40

Source: Raspberry Pi Official Hardware Documentation. BCM refers to the Broadcom SoC channel number used in Python/C++ libraries.

Regional Wire Color Standards for Sensor Integration

While the physical raspberry pi 4 model b pinout is identical globally, the wire colors you use to connect it to external power supplies, industrial M12 sensors, or relay boards must follow your region's electrical code. Feeding a Pi from a custom 5V buck converter or wiring 24V industrial sensors through optocouplers requires strict adherence to these standards to prevent lethal cross-wiring.

Wire Function IEC 60446 (EU / Global Standard) NEC (US / Canada) Old UK (Pre-2006)
AC Line / DC Positive (+) Brown Black (AC) / Red (DC) Red
AC Neutral / DC Negative (-) Blue White (AC) / Black (DC) Black
Earth Ground / Chassis Green/Yellow Stripe Green or Bare Copper Green/Yellow Stripe
Standard Sensor Signal (JST/Molex) Typically Yellow, Orange, or White (Check specific sensor datasheet)

Practical Application: If you are building a custom 5V power harness to back-power the Pi via Pins 2/4 (5V) and Pin 6 (GND) using a Mean Well IRM-10-5 module, use Red for 5V and Black for GND in the US (NEC DC standard), or Brown for 5V and Blue for GND in the EU (IEC DC standard). Never use Green/Yellow for anything other than earth ground.

Rows People Get Wrong (And How They Brick the Pi)

The BCM2711 chip on the Pi 4 operates at 3.3V logic. It is not 5V tolerant. Injecting 5V into a standard GPIO pin will instantly destroy the silicon. Here are the specific rows where makers make fatal mistakes:

  • Pin 1 (3.3V) vs. Pin 2 (5V): These are physically adjacent. If you plug a 5V sensor VCC wire into Pin 1, you will back-feed 5V into the Pi's internal 3.3V regulator, bypassing its protection and killing the SoC. Always verify Pin 1 with a multimeter before applying power.
  • Pins 8 (TXD) and 10 (RXD): Hardware UART requires a crossover. Pin 8 (Pi TX) must connect to the sensor's RX. Pin 10 (Pi RX) must connect to the sensor's TX. Wiring TX-to-TX will result in silent communication failure.
  • Pins 3 (SDA) and 5 (SCL): The Pi 4 includes onboard 1.8kΩ pull-up resistors to 3.3V on these pins. If you connect an I2C sensor module that also has onboard pull-ups to 5V, you create a voltage divider that pulls the Pi's I2C lines above 3.3V, risking long-term degradation. Check your sensor module's schematic and cut the pull-up jumper if necessary.
  • Pins 27 (ID_SD) and 28 (ID_SC): These are reserved for the HAT EEPROM. Do not use them for general I2C sensors; they are pulled to 3.3V and used exclusively during boot to identify attached HATs.

Decision Path: Selecting the Right Pin for Your Peripheral

Stop guessing which GPIO to use. Follow this decision tree to select the optimal pin for your hardware. This path terminates in a concrete default for generic use cases.

If your peripheral requires... Then use these Physical Pins (BCM) Why this is the optimal pick
I2C Communication (Sensors, OLEDs) Pins 3 & 5 (BCM 2 & 3) Dedicated hardware I2C1 bus with built-in 3.3V pull-ups.
SPI Communication (Displays, ADCs) Pins 19, 21, 23, 24 (BCM 10, 9, 11, 8) Primary SPI0 bus. Pin 26 (BCM 7) is available for a second Chip Enable (CE1).
Hardware PWM (Motor control, LED dimming) Pin 12 or 32 (BCM 18 or 12) These are the only pins connected to PWM channel 0, providing stable, jitter-free hardware timing.
Hardware UART (GPS, Serial Console) Pins 8 & 10 (BCM 14 & 15) Primary PL011 UART. (Note: Must disable Bluetooth in config.txt to free this from the mini-UART).
Generic Digital I/O (Buttons, Relays) Default: Pins 11, 13, 15 (BCM 17, 27, 22) CONCRETE PICK: These three pins are physically clustered together, sit right next to a Ground pin (Pin 9), and have no conflicting alternate boot functions. Always default to this block for generic digital I/O.

Safe Interpretation When Markings Are Faded or Missing

On older Pi 4 boards, or boards housed in tight enclosures where the silkscreen is obscured, guessing pin identities is unacceptable. If the white silkscreen markings are faded, missing, or covered by a HAT, use this multimeter verification sequence to safely map the header:

  1. Identify Pin 1 physically: Pin 1 is always the square solder pad on the underside of the board. On the top side, it is the pin closest to the USB-C power connector edge, and usually marked by a tiny silkscreen triangle pointing to it.
  2. Verify Ground (0V): Set your multimeter to continuity mode. Place the black probe on the metal shield of any USB port (which is tied to system ground). Probe the header pins with the red probe. The 8 ground pins (6, 9, 14, 20, 25, 30, 34, 39) will beep.
  3. Verify 5V Power: Power the Pi via USB-C. Set the multimeter to DC Voltage. Place the black probe on a verified Ground pin. Probe the remaining power pins. Pins 2 and 4 will read between 4.9V and 5.1V.
  4. Verify 3.3V Power: Keeping the black probe on Ground, probe Pin 1 and Pin 17. They will read exactly 3.3V (±0.05V). If you read 5V here, your Pi's onboard regulator has failed—do not connect any 3.3V sensors.
⚠️ SAFETY WARNING: Never back-power the Raspberry Pi 4 by injecting 5V into Pins 2 or 4 unless your external power supply is strictly regulated to 5.0V ± 5% and current-limited. The Pi 4's USB-C power input circuit includes polyfuses and overvoltage protection that are completely bypassed when feeding power directly through the GPIO header.

By anchoring your wiring to the physical pin layout, respecting regional wire color codes for external harnesses, and defaulting to the BCM 17/27/22 block for generic I/O, you eliminate 90% of the hardware faults seen in Pi 4 embedded projects.