The Raspberry Pi 40-pin header uses the Broadcom (BCM) numbering scheme natively in Python and C, but physical pin numbers (1-40) dictate your actual bench wiring. Pin 1 is always the 3.3V supply closest to the microSD card slot. Below is the definitive hardware mapping for modern boards, updated for the architectural shifts introduced in the Pi 5.

The Complete 40-Pin Raspberry GPIO Pinout Table

This table maps the physical header layout to the BCM GPIO numbers used in your code. While the physical footprint remains identical from the Pi 1B+ through the Pi 5, the internal routing and alternate functions have evolved. Reference the Pinout.xyz interactive diagram for exhaustive alternate multiplexing options.

Physical Pin BCM GPIO Function / Interface Voltage / Notes
1-3.3V PowerMax 50mA draw. Do not use for motors.
2-5V PowerDirect from USB-C input. High current.
32SDA1 (I2C)3.3V logic. Has onboard 1.8k pull-up.
4-5V PowerDirect from USB-C input.
53SCL1 (I2C)3.3V logic. Has onboard 1.8k pull-up.
6-GroundCommon ground reference.
74GPIO 4 (GPCLK0)3.3V. Often used for 1-Wire (DHT11/22).
814TXD (UART)3.3V logic. Pi 5 requires dtoverlay tweak.
9-GroundCommon ground reference.
1015RXD (UART)3.3V logic. Do not connect to 5V RS232.
1117GPIO 173.3V general purpose.
1218GPIO 18 (PWM0)3.3V. Hardware PWM available.
1910MOSI (SPI0)3.3V logic. Master Out Slave In.
219MISO (SPI0)3.3V logic. Master In Slave Out.
2311SCLK (SPI0)3.3V logic. SPI Clock.
25-GroundCommon ground reference.
270SDA0 (I2C ID)Reserved for HAT EEPROM identification.
295GPIO 53.3V general purpose.
316GPIO 63.3V general purpose.
3313GPIO 13 (PWM1)3.3V. Hardware PWM available.
3519MISO (SPI1)3.3V. Alternate SPI bus.
3726GPIO 263.3V general purpose.
39-GroundCommon ground reference.

Note: Even-numbered pins on the right rail (e.g., 2, 4, 6... 40) and remaining odd pins follow standard ground and 5V distribution, or secondary GPIOs (BCM 20, 21, 22, 23, 24, 25, 27). Consult the official Raspberry Pi compute documentation for the full 40-pin matrix.

Rows People Get Wrong (And How to Avoid Bricking Your Board)

When wiring up a new sensor or relay board, misinterpreting the pinout table usually results in immediate, irreversible silicon damage. Here are the most common bench mistakes and how to avoid them.

The 5V vs 3.3V Logic Trap

Pins 2 and 4 supply 5V directly from the USB-C power input. Pins 1 and 17 supply 3.3V from the onboard regulator. The Broadcom SoC's GPIO ring is strictly 3.3V tolerant. If you accidentally wire a 5V sensor output (like an unregulated HC-SR04 ultrasonic echo pin) into BCM 2 (Physical Pin 3), you will forward-bias the internal ESD protection diodes. This typically destroys the ARM core's IO ring, permanently killing the I2C bus or the entire chip. Always use a logic level shifter or a simple voltage divider (e.g., 2k and 3.3k resistors) when interfacing 5V sensors.

The UART Boot Loop

Physical pins 8 and 10 (BCM 14 and 15) are the primary UART TX/RX lines. On the Pi 4, these map to /dev/ttyAMA0 or /dev/serial0. On the Pi 5, the UART routing was redesigned to support the new RP1 southbridge chip. If you are migrating a Pi 4 serial console project to a Pi 5, you must update your /boot/firmware/config.txt with the correct dtoverlay=uart0 parameters, or the board will hang during boot waiting for a serial console that is no longer mapped to those physical pins.

I2C Pull-Up Conflicts

Pins 3 and 5 (SDA1/SCL1) already have 1.8kΩ pull-up resistors to 3.3V on the Pi PCB. If you connect an external sensor module that also has onboard 4.7kΩ pull-ups, the parallel resistance drops to roughly 1.3kΩ. This creates a stronger pull-up, which can cause signal ringing and I2C bus lockups at 400kHz (Fast Mode). If your I2C bus is dropping packets, check for duplicate pull-ups before blaming the code.

Wiring Standards: Ribbon Colors, IEC Power, and Faded Markings

While the GPIO header itself operates on low-voltage DC logic, the physical wiring standards you use to connect it—and the mains power feeding it—must adhere to established industry conventions to ensure safety and maintainability.

Standard 40-Pin Ribbon Cable Color Codes

If you are using a standard 40-pin IDE-style ribbon cable to break out the GPIO header to a perfboard or HAT, the industry standard dictates that Pin 1 is always the red-striped wire. The remaining wires follow a standard rainbow sequence or alternating black/grey pattern. Never assume Pin 1 based on the connector's physical orientation; always trace the red stripe to the square pad on your breakout board.

Regional Mains Standards for the Power Supply

The Pi itself doesn't connect to mains, but your custom enclosure's power supply does. When wiring the AC input to your project's internal AC/DC converter (like a Mean Well IRM-10-5), you must follow your regional wiring color codes:

  • IEC 60446 (UK/EU/AU): Brown = Live (Hot), Blue = Neutral, Green/Yellow = Earth Ground.
  • NEC (US/Canada): Black = Hot, White = Neutral, Bare/Green = Earth Ground.

Mixing these up when sourcing surplus power supplies from overseas vendors is a frequent cause of dead shorts and tripped AFCI breakers. Always verify the internal wiring of imported AC/DC modules with a multimeter before applying mains power.

Safe Interpretation When Markings are Faded or Missing

On older Pi 1 or Pi 2 boards, or boards that have seen heavy field use, the silkscreen pin numbers often wear off. If you lose your visual reference, use these physical hardware tells to re-orient yourself:

  1. The Square Pad: Flip the board over. Pin 1 is the only pad on the GPIO header that is square. All other pads are circular.
  2. The Silkscreen Triangle: Look closely at the PCB surface near the microSD card slot. There is almost always a tiny white silkscreen triangle pointing directly at Pin 1.
  3. The Multimeter Ground Test: If the board is completely unmarked and you cannot see the bottom pads, set your multimeter to continuity mode. Place one probe on the metal USB port shield (which is tied to ground). Probe the header pins with the other lead. The pins that beep are your Ground pins (6, 9, 14, 20, 25, 30, 34, 39). Once you map the grounds, you can deduce the 5V and 3.3V rails by measuring voltage with the board powered on.

Pi 4 vs Pi 5: Hardware Differences You Must Know

The physical 40-pin footprint hasn't changed, but the silicon driving it has. The Pi 5 introduced the RP1 I/O controller, which shifted how certain pins behave at the hardware level. Review the Raspberry Pi 5 hardware guide for deep-dive schematics.

Feature Raspberry Pi 4 Raspberry Pi 5
I/O Controller Directly on BCM2711 SoC Offloaded to RP1 Southbridge
Hardware PWM Available on GPIO 12, 13, 18, 19 Expanded routing, but requires updated device tree overlays
Dedicated Power Button None (requires external circuit on GPIO 3) Dedicated J2 header pins for physical power switch
Real Time Clock (RTC) None (requires external I2C module like DS3231) Built-in RTC (requires external CR2032 battery on dedicated pads)
3.3V Rail Current ~50mA max safe draw Substantially higher capacity via new PMIC, but still not for motors
Bench Warning: Never use the 3.3V pins (1 or 17) to power servos, relays, or high-draw LED strips. Even on the Pi 5, the 3.3V rail is designed for logic signaling and low-power I2C/SPI sensors. Exceeding the current limit will cause a brownout, resetting the SoC and potentially corrupting your microSD card filesystem. Always use an external 5V or 3.3V buck converter for actuators, tying only the control signal and ground back to the Pi header.