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 | - | 1 | 2 | - | 5V Power |
| I2C1 SDA | GPIO 2 | 3 | 4 | - | 5V Power |
| I2C1 SCL | GPIO 3 | 5 | 6 | - | Ground |
| GPIO | GPIO 4 | 7 | 8 | GPIO 14 | UART0 TXD |
| Ground | - | 9 | 10 | GPIO 15 | UART0 RXD |
| GPIO | GPIO 17 | 11 | 12 | GPIO 18 | PCM CLK / PWM0 |
| GPIO | GPIO 27 | 13 | 14 | - | Ground |
| GPIO | GPIO 22 | 15 | 16 | GPIO 23 | GPIO |
| 3.3V Power | - | 17 | 18 | GPIO 24 | GPIO |
| SPI0 MOSI | GPIO 10 | 19 | 20 | - | Ground |
| SPI0 MISO | GPIO 9 | 21 | 22 | GPIO 25 | GPIO |
| SPI0 SCLK | GPIO 11 | 23 | 24 | GPIO 8 | SPI0 CE0 |
| Ground | - | 25 | 26 | GPIO 7 | SPI0 CE1 |
| HAT ID SDA | GPIO 0 | 27 | 28 | GPIO 1 | HAT ID SCL |
| GPIO | GPIO 5 | 29 | 30 | - | Ground |
| GPIO | GPIO 6 | 31 | 32 | GPIO 12 | PWM0 |
| GPIO | GPIO 13 | 33 | 34 | - | Ground |
| PCM FS | GPIO 19 | 35 | 36 | GPIO 16 | GPIO |
| GPIO | GPIO 26 | 37 | 38 | GPIO 20 | PCM DIN |
| Ground | - | 39 | 40 | GPIO 21 | PCM 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=1is set inconfig.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.
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:
- 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.
- 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).
- 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).






