The Raspberry Pi 4 Model B features a 40-pin GPIO header containing 26 usable general-purpose I/O pins, 4 power pins, and 8 ground pins. The most critical specification for any bench setup: the BCM2711 SoC operates on a strict 3.3V logic level. Feeding 5V into any GPIO pin will permanently destroy the processor. Below is the complete physical and BCM mapping, followed by the exact decision paths you need to wire peripherals safely.
The Complete Raspberry Pi 4 B 40-Pin Header Table
This table maps the physical pin number (counting from the corner nearest the SD card) to the Broadcom (BCM) GPIO number used in Python/C code. Read it left-to-right, matching the physical layout of the board.
| Pin | BCM | Name / Function | Pin | BCM | Name / Function |
|---|---|---|---|---|---|
| 1 | - | 3.3V Power | 2 | - | 5V Power |
| 3 | 2 | GPIO2 (I2C1 SDA) | 4 | - | 5V Power |
| 5 | 3 | GPIO3 (I2C1 SCL) | 6 | - | Ground |
| 7 | 4 | GPIO4 (GPCLK0) | 8 | 14 | GPIO14 (UART0 TX) |
| 9 | - | Ground | 10 | 15 | GPIO15 (UART0 RX) |
| 11 | 17 | GPIO17 | 12 | 18 | GPIO18 (PWM0) |
| 13 | 27 | GPIO27 | 14 | - | Ground |
| 15 | 22 | GPIO22 | 16 | 23 | GPIO23 |
| 17 | - | 3.3V Power | 18 | 24 | GPIO24 |
| 19 | 10 | GPIO10 (SPI0 MOSI) | 20 | - | Ground |
| 21 | 9 | GPIO9 (SPI0 MISO) | 22 | 25 | GPIO25 |
| 23 | 11 | GPIO11 (SPI0 SCLK) | 24 | 8 | GPIO8 (SPI0 CE0) |
| 25 | - | Ground | 26 | 7 | GPIO7 (SPI0 CE1) |
| 27 | 0 | ID_SD (I2C ID) | 28 | 1 | ID_SC (I2C ID) |
| 29 | 5 | GPIO5 | 30 | - | Ground |
| 31 | 6 | GPIO6 | 32 | 12 | GPIO12 (PWM0) |
| 33 | 13 | GPIO13 (PWM1) | 34 | - | Ground |
| 35 | 19 | GPIO19 (SPI1 MISO) | 36 | 16 | GPIO16 |
| 37 | 26 | GPIO26 | 38 | 20 | GPIO20 (SPI1 MOSI) |
| 39 | - | Ground | 40 | 21 | GPIO21 (SPI1 SCLK) |
Source: Pinout.xyz and Raspberry Pi Official Hardware Docs.
Rows People Get Wrong (And How They Fry Their Pi)
When troubleshooting a dead Pi 4 B, the failure almost always traces back to one of these specific pin misinterpretations:
Pin 1 outputs 3.3V (max draw ~50mA total across the rail). Pin 2 outputs 5V (limited only by your USB-C power supply). If you accidentally backfeed 5V into Pin 1, or wire a 5V sensor output directly to a 3.3V GPIO, the BCM2711 silicon will instantly latch up and die. Always use a logic level shifter (like the BSS138 MOSFET bi-directional shifter) when interfacing with 5V Arduino-style sensors.
- Pins 3 & 5 (I2C1 SDA/SCL): These pins have 1.8kΩ pull-up resistors hardwired to the 3.3V rail on the Pi board itself. If your sensor breakout board also has pull-ups, you will create a parallel resistance that pulls the line too low, causing I2C bus lockups. Furthermore, never connect a 5V I2C device here; the 1.8kΩ pull-ups will feed 5V back into the Pi's 3.3V rail.
- Pins 27 & 28 (ID_SD / ID_SC): These are reserved exclusively for reading the EEPROM on official Raspberry Pi HATs. They are connected to a separate I2C bus used only during boot. Do not use them for general-purpose I2C sensors.
- Pins 8 & 10 (UART0 TX/RX): By default, the Pi routes the Linux serial console to these pins. If you connect a GPS module or microcontroller here without disabling the serial console in
raspi-config, your device will be flooded with boot logs and kernel panics.
Wiring Color Codes & Logic Standards
While the Raspberry Pi is a global platform, the wiring color codes you use to connect it to the outside world depend on your region's electrical standards and the specific DC conventions of the maker community. Mixing these up on a crowded workbench leads to catastrophic shorts.
| Standard / Region | Line / VCC | Neutral / GND | Earth / Signal | Application |
|---|---|---|---|---|
| Maker DC Convention (Global) | Red (5V) / Orange (3.3V) | Black (GND) | Yellow / Blue (Signal) | Breadboards, Dupont wires, JST connectors |
| IEC 60446 (EU/UK Mains) | Brown (Line) | Blue (Neutral) | Green/Yellow (Earth) | AC Mains wiring, relay terminal blocks |
| NEC / US (AC Mains) | Black (Hot) | White (Neutral) | Green/Bare (Ground) | AC Mains wiring, relay terminal blocks |
| Old UK (Pre-2004) | Red (Line) | Black (Neutral) | Green/Yellow (Earth) | Legacy AC panels (High confusion risk!) |
Peripheral Decision Tree: Which Pin Do I Actually Use?
Stop guessing which GPIO to assign in your Python script. Use this decision path to select the correct hardware-backed pins for your specific peripheral. This terminates the 'it depends' loop and gives you a concrete wiring target.
| Peripheral Need | Decision Condition | Concrete Pick (Physical Pins) | BCM GPIOs |
|---|---|---|---|
| I2C Sensor (e.g., BME280) | Standard 3.3V logic, addressable | Pins 3 (SDA) & 5 (SCL) | GPIO 2, 3 |
| SPI Display (e.g., ILI9341) | High-speed data, requires chip enable | Pins 19, 21, 23, 24 | GPIO 10, 9, 11, 8 |
| Hardware PWM (e.g., LED dimming) | Needs jitter-free analog simulation | Pins 12 or 32 (PWM0), Pin 33 (PWM1) | GPIO 18, 12, 13 |
| 5V Analog Servo Motor | Pi cannot output 5V analog PWM safely | Use PCA9685 Driver via I2C (Pins 3 & 5) | N/A (I2C controlled) |
| UART GPS Module | 3.3V logic serial, console disabled | Pins 8 (TX) & 10 (RX) | GPIO 14, 15 |
Safe Interpretation When Markings Are Faded or Missing
If you are working with a heavily used Pi 4 B where the white silkscreen pin labels have worn off, or you are using a third-party carrier board that obscures the header, do not guess. Follow this physical and software verification sequence:
- The Square Pad Rule: Look closely at the solder pads on the underside (or top, if unboxed) of the GPIO header. Physical Pin 1 is the only square solder pad. All other 39 pins are perfectly round. Pin 1 is located at the corner closest to the microSD card slot and furthest from the USB-C power port.
- The Silkscreen Triangle: On the top side of the PCB, near the base of the header, there is a small white triangle printed on the silkscreen. The point of this triangle always indicates Pin 1.
- Software Verification: If the board is powered and booted into Raspberry Pi OS, open the terminal and type
pinout. This built-in command (part of thegpiozerolibrary) will render an ASCII-art diagram of your exact board revision, confirming the BCM-to-Physical mapping without needing to read the board. - Multimeter Continuity Test: With the Pi completely powered off and unplugged, set your multimeter to continuity mode. Probe the metal shielding of the USB ports (which is tied to ground) and test the header pins. The pins that beep are your Ground pins (6, 9, 14, 20, 25, 30, 34, 39). This immediately eliminates 20% of the header from your guessing game.
By strictly adhering to the 3.3V logic limit, respecting the onboard I2C pull-ups, and using standardized DC color codes, you will eliminate the most common hardware failure modes associated with the Raspberry Pi 4 B GPIO header.






