The Raspberry Pi 4 Model B features a 40-pin GPIO header operating strictly at 3.3V logic. It provides 26 general-purpose I/O pins, two 5V power pins, two 3.3V power pins, and eight ground pins. While the physical header layout is identical to the Pi 3B+, the underlying Broadcom (BCM) chip mappings dictate how you address these pins in Python, C, or Node-RED. Feeding 5V into any of the 26 GPIO pins will permanently destroy the SoC.
The 40-Pin Header Map: Physical vs. BCM
The table below maps the physical pin numbers (looking at the Pi with USB ports facing you and the GPIO header on the top right) to their Broadcom (BCM) names and primary alternate functions. Always use BCM numbering in your code, as physical pin numbering changes across different Raspberry Pi compute modules and zero variants.
| Left (Odd) | Function / BCM | Function / BCM | Right (Even) |
|---|---|---|---|
| 1 | 3.3V Power | 5V Power | 2 |
| 3 | BCM 2 (I2C SDA1) | 5V Power | 4 |
| 5 | BCM 3 (I2C SCL1) | Ground | 6 |
| 7 | BCM 4 (GPCLK0) | BCM 14 (UART TXD) | 8 |
| 9 | Ground | BCM 15 (UART RXD) | 10 |
| 11 | BCM 17 | BCM 18 (Hardware PWM0) | 12 |
| 13 | BCM 27 | Ground | 14 |
| 15 | BCM 22 | BCM 23 | 16 |
| 17 | 3.3V Power | BCM 24 | 18 |
| 19 | BCM 10 (SPI0 MOSI) | Ground | 20 |
| 21 | BCM 9 (SPI0 MISO) | BCM 25 | 22 |
| 23 | BCM 11 (SPI0 SCLK) | BCM 8 (SPI0 CE0) | 24 |
| 25 | Ground | BCM 7 (SPI0 CE1) | 26 |
| 27 | BCM 0 (I2C ID_SD) | BCM 1 (I2C ID_SC) | 28 |
| 29 | BCM 5 | Ground | 30 |
| 31 | BCM 6 | BCM 12 (Hardware PWM0) | 32 |
| 33 | BCM 13 (Hardware PWM1) | Ground | 34 |
| 35 | BCM 19 (SPI1 MISO) | BCM 16 (SPI1 CE2) | 36 |
| 37 | BCM 26 | BCM 20 (SPI1 MOSI) | 38 |
| 39 | Ground | BCM 21 (SPI1 SCLK) | 40 |
For official hardware specifications and silicon-level multiplexing details, refer to the Raspberry Pi Foundation hardware documentation.
Rows People Get Wrong (And How to Avoid Bricking Your Pi)
Even experienced makers fry their Pi 4B boards by misinterpreting specific rows on the header. Here are the most common traps and how to navigate them.
The I2C Pull-Up Trap (Pins 3 and 5)
Pins 3 (BCM 2) and 5 (BCM 3) are the primary I2C bus. The Raspberry Pi board includes 1.8kΩ physical pull-up resistors tying these pins to the 3.3V rail. If you connect a 5V I2C sensor directly to these pins without a bidirectional logic level shifter, the 5V sensor will backfeed voltage through the pull-ups and into the 3.3V regulator, often destroying the SoC. Always use a level shifter like the BSS138 or TXB0104 for 5V I2C devices.
Hardware PWM vs. Software Jitter (Pins 12, 32, 33, 35)
While you can generate software PWM on almost any GPIO pin using Python's RPi.GPIO library, software PWM is timed by the OS and suffers from severe jitter due to Linux kernel interrupts. If you are driving servos, dimming LEDs smoothly, or generating audio tones, you must use the true hardware PWM pins. On the Pi 4B, hardware PWM is only available on BCM 12, 13, 18, and 19 (Physical pins 12, 32, 33, and 35).
The HAT EEPROM Pins (Pins 27 and 28)
BCM 0 and BCM 1 (Physical pins 27 and 28) are reserved exclusively for I2C communication with Hardware Attached on Top (HAT) EEPROMs. The Pi uses these during boot to automatically configure GPIO states and load device tree overlays. Do not use these pins for general I/O, or you will cause boot conflicts and HAT recognition failures.
Wire Color Standards: NEC, IEC, and Pi Logic
The Raspberry Pi itself does not enforce wire colors for its low-voltage Dupont or ribbon cables. However, the moment your Pi project interfaces with external power supplies, mains-voltage relays, or industrial 24V DC sensors, the wiring leaving your enclosure must comply with regional electrical codes. Using standard Pi jumper colors (like red for 120V AC hot) is a severe safety hazard.
Here is how regional standards apply to external circuits controlled by your Pi:
| Function | US / Canada (NEC / NFPA 70) | EU / UK / AU (IEC 60446) | Pi Internal DC (Convention) |
|---|---|---|---|
| AC Line / Hot | Black (or Red for 240V) | Brown | N/A |
| AC Neutral | White (or Grey) | Blue | N/A |
| AC Earth / Ground | Green, Green/Yellow, or Bare | Green/Yellow | Black (Signal GND) |
| DC Positive (+) | Red | Brown | Red (5V) / Orange (3.3V) |
| DC Negative (-) | Black | Blue | Black |
When wiring a Pi GPIO to an external opto-isolated relay board, use standard low-voltage colors (e.g., Blue for GPIO signal, Black for GND) inside the enclosure, but ensure the relay's output side strictly follows your local AC/DC color code. For deeper code compliance, consult the NFPA 70 National Electrical Code or your local Authority Having Jurisdiction (AHJ).
Frequently Asked Questions
Can I power the Raspberry Pi 4B through the 5V GPIO pins?
Yes, but with strict caveats. You can inject 5V directly into Physical Pin 2 or 4 (and Ground to Pin 6) to power the board, bypassing the USB-C port. However, this route bypasses the onboard polyfuse and the dedicated power management IC (PMIC) brownout protection. Your external 5V supply must be perfectly regulated to 5.1V and capable of delivering at least 3A. If the voltage sags under load, the Pi will experience random kernel panics or SD card corruption.
What happens if I connect a 5V sensor to a Raspberry Pi 4B GPIO pin?
The Broadcom BCM2711 SoC on the Pi 4B is not 5V tolerant. If you drive a 5V logic HIGH into a standard GPIO pin (like BCM 17), you will forward-bias the internal ESD protection diodes. This dumps excess current into the 3.3V rail. In the best-case scenario, the Pi will read a constant HIGH and the SoC will overheat. In the worst-case scenario, the silicon will permanently short, bricking the board. Always use a voltage divider, an optocoupler, or a logic level shifter for 5V signals.
How do I safely identify GPIO pins if the silkscreen is faded or missing?
If you are working with a third-party clone board or a heavily used Pi where the silkscreen is gone, do not guess. First, locate Pin 1: it is always the pin closest to the corner of the SD card slot and the USB-C power port, and it typically features a square solder pad instead of a round one. Next, set your multimeter to continuity mode. Touch one probe to the metal shielding of the USB ports and use the other probe to map the header. Any pin that beeps is a Ground pin (Pins 6, 9, 14, 20, 25, 30, 34, 39). Once you have mapped the grounds and Pin 1, the rest of the 40-pin layout follows the standard alternating grid.
Are the Raspberry Pi 4B GPIO pinouts identical to the Pi 3B+ and Pi 5?
The physical 40-pin header layout and BCM mappings for the primary GPIOs (like I2C, SPI, and UART) are identical between the Pi 3B+ and the Pi 4B. However, the Raspberry Pi 5 uses a completely different silicon architecture (BCM2712) and a dedicated RP1 southbridge chip. While the Pi 5 maintains backward compatibility for basic Python GPIO scripts, the underlying hardware addresses, PWM routing, and pin multiplexing have changed. A HAT designed specifically for the Pi 4B's hardware PWM or specific I2C bus routing may not function correctly on a Pi 5 without software updates.






