The Raspberry Pi 40-pin GPIO header is the physical bridge between your compute module and the real world. Whether you are wiring an I2C sensor, driving a relay, or debugging a UART console, you need exact pin functions, voltage tolerances, and physical locations. Below is the definitive hardware reference for the pinout raspberry pi 40-pin header, applicable to Pi 3, Pi 4, and Pi 5 models, with critical power delivery updates for the latest silicon.

The Complete 40-Pin Raspberry Pi Pinout Reference Table

This table maps the physical pin numbers (1-40) to the Broadcom (BCM) GPIO naming convention used by Python, C, and modern OS overlays. WiringPi is deprecated and should not be used for new designs.

Function / Alt BCM / Name Pin (L) Pin (R) BCM / Name Function / Alt
3.3V Power-12-5V Power
I2C1 SDAGPIO 234-5V Power
I2C1 SCLGPIO 356-Ground
GPIOGPIO 478GPIO 14UART0 TXD
Ground-910GPIO 15UART0 RXD
GPIOGPIO 171112GPIO 18PCM CLK / PWM0
GPIOGPIO 271314-Ground
GPIOGPIO 221516GPIO 23GPIO
3.3V Power-1718GPIO 24GPIO
SPI0 MOSIGPIO 101920-Ground
SPI0 MISOGPIO 92122GPIO 25GPIO
SPI0 SCLKGPIO 112324GPIO 8SPI0 CE0
Ground-2526GPIO 7SPI0 CE1
HAT ID SDAGPIO 02728GPIO 1HAT ID SCL
GPIOGPIO 52930-Ground
GPIOGPIO 63132GPIO 12PWM0
GPIOGPIO 133334-Ground
PCM FSGPIO 193536GPIO 16GPIO
GPIOGPIO 263738GPIO 20PCM DIN
Ground-3940GPIO 21PCM DOUT

Source: Raspberry Pi Official GPIO Documentation and Pinout.xyz hardware reference.

Decoding the Pinout: Functions, Gotchas, and Faded Silkscreen Recovery

Reading a pinout table is only half the battle. Understanding the electrical realities behind the silicon—especially the architectural shifts introduced with the Raspberry Pi 5's RP1 southbridge—is what prevents fried boards and ghost-in-the-machine I2C errors.

Rows People Get Wrong (And How to Fix Them)

  • Pins 3 & 5 (I2C1 SDA/SCL): These pins have onboard 1.8kΩ pull-up resistors tied to the 3.3V rail (1.5kΩ on Pi 5). The mistake: Adding external 5V pull-ups or connecting a 5V I2C device without a level shifter. This back-feeds 5V into the 3.3V rail, potentially destroying the SoC or RP1 chip.
  • Pins 27 & 28 (ID_SD / ID_SC): These are strictly reserved for the HAT EEPROM I2C bus. The mistake: Using them for general-purpose sensors. They have specific 2.2kΩ pull-ups and are polled by the firmware at boot. If you load them down, your Pi will fail to auto-configure HATs.
  • Pins 8 & 10 (UART TX/RX): The mistake: Wiring TX to TX. It must be TX to RX. Furthermore, on the Pi 5, the primary UART is routed through the RP1 chip. You must ensure enable_uart=1 is set in config.txt, and be aware that the Pi 5 UART operates at 3.3V logic but is driven by the RP1, altering some low-level timing characteristics compared to the Pi 4's BCM2711 UART.
  • Pins 1 & 17 (3.3V Power): On the Pi 4, the 3.3V rail is practically limited to ~500mA total draw. On the Pi 5, the new DA9098 PMIC can supply up to 1.6A on the 3.3V rail. If you are upgrading a high-draw sensor array from Pi 4 to Pi 5, the 3.3V rail will no longer be your bottleneck.
WARNING: Never feed 5V into any GPIO pin (Pins 3-40, excluding the dedicated 5V power pins 2 and 4). The Pi's GPIOs are strictly 3.3V tolerant. A 5V signal will cause immediate, irreversible latch-up and thermal failure of the input protection diodes.

Safe Interpretation When Markings Are Faded or Missing

On older Pi 1/2 boards, or heavily used clone boards, the silkscreen 'P1' marker and the square Pin 1 pad can wear off. Here is how to safely identify Pin 1 without guessing:

  1. The Physical Landmark Rule: Pin 1 is always located in the corner closest to the SD card slot and the metal shielding of the USB ports. It is never on the side closest to the Ethernet port or the composite audio jack.
  2. The Multimeter Ground Test: Set your multimeter to continuity mode. Probe the outer metal shell of any of the four USB ports—this is tied directly to the board's main ground plane. Probe the header pins until you find a ground pin (Pins 6, 9, 14, 20, 25, 30, 34, or 39). Once you have a confirmed ground, Pin 1 is the 3.3V pin situated diagonally across from Pin 9 (GND) or adjacent to Pin 2 (5V).
  3. The Voltage Verification: Power the board. Set your meter to DC Voltage. Place the black probe on a known ground (USB shield). Probe the suspected Pin 1. It must read exactly 3.3V. If it reads 5V, you are on Pin 2 and your orientation is flipped.

GPIO Wiring Color Codes: IEC, US Ribbon, and Legacy Standards

When building custom wire harnesses, breakout cables, or permanent installations for your Raspberry Pi, adhering to a recognized color code standard prevents catastrophic miswiring. The standard you choose depends on your region and the type of cable you are terminating.

Wire Function US / EIA-TIA-568 (Ribbon) IEC 60445 / EU DC Standard Old UK (Pre-2004 Legacy)
5V Power (Pins 2, 4) Red (or Red Stripe) Brown Red
Ground (Pins 6, 9, etc.) Black (or Brown) Blue (or Black for DC common) Black
3.3V Power (Pins 1, 17) Orange Orange (or Violet) Yellow
Data / GPIO (Standard) Green, Blue, Yellow Grey, White, Green Green, Blue
I2C SDA / SCL White / Grey Green / Yellow-Green (Shield) White / Grey

Which Standard Applies to Your Region?

North America (US/Canada): If you are using flat IDC (Insulation Displacement Connector) ribbon cables, the EIA-TIA-568 10-color sequence is the undisputed standard. Pin 1 is always the wire with the red stripe (usually brown in the sequence, but the red edge marker dictates Pin 1). For discrete wires in a custom loom, red for 5V and black for ground is universal practice, heavily influenced by NEC low-voltage Class 2 wiring norms.

Europe / UK (Modern): The IEC 60445 standard (which superseded IEC 60446) dictates that for DC power circuits, Brown is positive (L+) and Blue is negative/ground (L-). However, IEC is primarily designed for higher-voltage DC and AC power. For low-voltage data lines (GPIO, I2C, SPI), IEC defers to manufacturer or industry-specific norms. In EU industrial control panels, grey is standard for 24V/low-voltage control signals, making it an excellent choice for Pi GPIO data lines.

Legacy / Old UK (Pre-2004): You will still encounter old UK wiring where Red is positive and Black is negative. While fine for simple 5V/GND connections, avoid mixing old UK color codes with modern IEC harnesses in the same enclosure, as a modern IEC Blue wire (which means ground) might be mistakenly spliced to an old UK Blue wire (which was a live phase).

Bench Tip: When crimping Dupont connectors for Pi GPIO headers, always use a 1-to-1 color mapping on both ends. If you must cross wires (e.g., TX to RX), do it at the breadboard or use a custom PCB breakout. Crossing wires inside a crimped housing is the leading cause of 'ghost' UART errors during field deployment.