The Raspberry Pi 4 Model B features a 40-pin GPIO header operating at 3.3V logic. The universal software standard for modern Pi development is BCM (Broadcom) numbering, though physical pin counting remains necessary for hardware wiring. Below is the complete mapping, followed by the specific trap pins you must avoid and a decision matrix for assigning your peripherals.
The Complete 40-Pin Raspi 4 GPIO Pinout Table
Read this table by looking at the physical header with the USB ports facing you and the GPIO pins extending away. The left column represents the odd-numbered pins (closest to the board edge), and the right column represents the even-numbered pins.
| Phys (Left) | BCM | Function / Name | BCM | Phys (Right) |
|---|---|---|---|---|
| 1 | - | 3.3V Power | - | 2 (5V Power) |
| 3 | 2 | SDA1 (I2C) | - | 4 (5V Power) |
| 5 | 3 | SCL1 (I2C) | - | 6 (Ground) |
| 7 | 4 | GPIO 4 (GPCLK0) | 14 | 8 (UART TXD) |
| 9 | - | Ground | 15 | 10 (UART RXD) |
| 11 | 17 | GPIO 17 | 18 | 12 (PCM_CLK / PWM0) |
| 13 | 27 | GPIO 27 | - | 14 (Ground) |
| 15 | 22 | GPIO 22 | 23 | 16 (GPIO 23) |
| 17 | - | 3.3V Power | 24 | 18 (GPIO 24) |
| 19 | 10 | MOSI (SPI) | - | 20 (Ground) |
| 21 | 9 | MISO (SPI) | 25 | 22 (GPIO 25) |
| 23 | 11 | SCLK (SPI) | 8 | 24 (CE0 / SPI) |
| 25 | - | Ground | 7 | 26 (CE1 / SPI) |
| 27 | 0 | ID_SD (I2C EEPROM) | 1 | 28 (ID_SC) |
| 29 | 5 | GPIO 5 | - | 30 (Ground) |
| 31 | 6 | GPIO 6 | 12 | 32 (GPIO 12 / PWM0) |
| 33 | 13 | GPIO 13 / PWM1 | - | 34 (Ground) |
| 35 | 19 | MISO (SPI1) / PWM1 | 16 | 36 (GPIO 16) |
| 37 | 26 | GPIO 26 | 20 | 38 (MOSI / SPI1) |
| 39 | - | Ground | 21 | 40 (SCLK / SPI1) |
Source: Raspberry Pi Official Documentation
Numbering Standards and Wiring Color Codes
When working with the Raspi 4 GPIO pinout, confusion usually stems from mixing up the three competing numbering standards. Here is which standard applies to your workflow:
- BCM (Broadcom SOC Channel): The default for Python (
RPi.GPIOandgpiozero) and modern C/C++ libraries. You use the Broadcom chip pin numbers (e.g., GPIO 17). Always use this for software. - Physical (Board): Simply counts the pins 1 through 40. Used exclusively when physically wiring headers or using a multimeter to probe for continuity.
- WiringPi: An older, deprecated standard created by Gordon Henderson. It uses its own arbitrary mapping (e.g., WiringPi pin 0 is BCM GPIO 17). Avoid this entirely in 2026; the library is unmaintained and causes severe mapping errors on newer Pi OS releases.
Standard Maker Wire Color Conventions
While the Pi header itself uses no color codes, adopting standard wire colors on your breadboard prevents catastrophic miswiring when debugging:
- Power: Red (5V), Orange (3.3V), Black (Ground).
- I2C: Yellow (SDA), Blue (SCL).
- SPI: Green (MOSI), Purple (MISO), Gray (SCLK), White (Chip Enable).
- UART: Brown (TX), Yellow (RX).
Rows People Get Wrong (The Trap Pins)
Not all pins on the 40-pin header are created equal. Misinterpreting these specific rows in the table above is the leading cause of fried sensors and boot failures.
Unlike the Arduino Uno (ATmega328P), the Raspberry Pi 4 Broadcom BCM2711 chip is strictly 3.3V. Feeding a 5V signal into any BCM GPIO pin will permanently destroy the SoC. If you are interfacing with 5V sensors (like the HC-SR04 ultrasonic or standard Arduino shields), you must use a bidirectional logic level converter (e.g., BSS138 MOSFET-based modules, ~$2 USD).
- GPIO 2 & 3 (Pins 3 & 5): These are the primary I2C bus pins. They have hardcoded 1.8kΩ pull-up resistors tied to 3.3V on the Pi board. Do not use these for standard digital inputs or active-low interrupts unless your circuit accounts for this pull-up.
- GPIO 14 & 15 (Pins 8 & 10): These are the hardware UART pins. By default, the Pi outputs kernel boot logs to GPIO 14 (TXD) at 115200 baud. If you wire a motor driver or sensitive actuator to these pins, it will receive garbage PWM-like signals during boot, potentially triggering unsafe hardware movement. Disable the serial console in
raspi-configif using these for general GPIO. - ID_SD & ID_SC (Pins 27 & 28): Reserved for the HAT (Hardware Attached on Top) EEPROM I2C bus. The Pi queries these pins on boot to auto-configure hardware. Never wire standard sensors here; it will cause boot delays or hardware misidentification.
- Pin 1 (3.3V) vs Pin 2 (5V): Reversing your power rails here is fatal. Plugging a 5V sensor VCC into Pin 1 will brownout the Pi's onboard 3.3V regulator (which maxes out around 50mA for external use). Plugging 3.3V logic into Pin 2 won't fry the Pi, but your sensor won't power on.
Peripheral Decision Path: Choose Your Pin
Stop guessing which pin to use. Follow this decision tree to select the optimal, hardware-supported pin for your specific peripheral. This terminates in a concrete BCM pick every time.
| Peripheral Type | Condition / Requirement | Concrete Pin Pick (BCM) | Why This Pick? |
|---|---|---|---|
| I2C Sensor | Standard address (e.g., BME280, OLED) | GPIO 2 (SDA) / GPIO 3 (SCL) | Hardware I2C1 bus; includes onboard 1.8k pull-ups. |
| SPI Device | High speed (e.g., TFT Display, RFID RC522) | GPIO 10 (MOSI), 9 (MISO), 11 (SCLK), 8 (CE0) | Hardware SPI0 bus; handles DMA transfers without CPU blocking. |
| Hardware PWM | Motor control or LED dimming (needs stable freq) | GPIO 18 (Pin 12) | The only pin that reliably routes to PWM0 channel without audio subsystem conflicts. |
| UART / GPS | Serial telemetry (e.g., NEO-6M GPS) | GPIO 14 (TX) / GPIO 15 (RX) | Hardware UART (/dev/ttyAMA0 or serial0); requires disabling serial console in OS. |
| Simple Button | Momentary switch to ground | GPIO 17 (Pin 11) | No alternate functions, no pull-up conflicts; safe for software-defined pull-ups. |
| 1-Wire (Temp) | DS18B20 temperature sensor | GPIO 4 (Pin 7) | Default kernel overlay pin for w1-gpio; requires external 4.7k pull-up to 3.3V. |
Safe Interpretation When Silk-Screen Markings Fade
On older Pi 4 boards, or when using third-party compute module carrier boards, the physical pin numbering silk-screen often wears off or is entirely absent. Guessing Pin 1 incorrectly and applying 5V to a data line will instantly kill the board. Use these three physical verification methods to safely identify Pin 1:
- The USB-C Proximity Rule: On the Raspberry Pi 4 Model B, Pin 1 is always the pin physically closest to the USB-C power connector. (Note: On the older Pi 3, it was closest to the SD card slot. Do not mix up these mental models).
- The Square Pad Rule (Underside): Flip the board over and look at the solder joints for the GPIO header. Pin 1 is the only pad that is square. All other 39 pins have round solder pads.
- The Multimeter Continuity Test: Set your multimeter to continuity mode. Probe the metal shielding of the USB ports (which is grounded) against the pins on the header. Pins 6, 9, 14, 20, 25, 30, 34, and 39 will beep. Pin 1 will not beep, but it will read exactly 3.3V relative to those ground pins when the board is powered.
For interactive visual mapping and to verify specific alternate pin functions (like I2S audio or DPI displays), cross-reference your physical wiring with the interactive diagrams at pinout.xyz before applying power.






