The Raspberry Pi 4 Model B features a 40-pin GPIO header that serves as the physical bridge between your Python or C++ code and the real world. The most critical standard for modern coding is BCM (Broadcom SOC channel) numbering, while Physical (Board) numbering (1-40) is used for hardware wiring. Feeding 5V into a 3.3V logic pin will instantly destroy the SoC. Use this reference to map your hardware safely.
The Complete Raspberry Pi 4 Pinout Reference Table
Below is the definitive 40-pin mapping for the Raspberry Pi 4. This table aligns the physical header layout with the BCM GPIO numbers your code will actually use. Read the 'Notes' column carefully—several pins have hidden hardware behaviors that will cause logic errors if ignored.
| Phys | BCM | Name / Function | Notes & Hardware Hazards |
|---|---|---|---|
| 1 | - | 3.3V Power | Max draw ~50mA. Do not use for motors. |
| 2 | - | 5V Power | Direct from USB-C input. Unregulated. |
| 3 | 2 | GPIO 2 (SDA1 / I2C) | Has 1.8k physical pull-up to 3.3V on board. |
| 4 | - | 5V Power | Direct from USB-C input. |
| 5 | 3 | GPIO 3 (SCL1 / I2C) | Has 1.8k physical pull-up to 3.3V on board. |
| 6 | - | Ground (GND) | Common ground for all circuits. |
| 7 | 4 | GPIO 4 (GPCLK0) | Standard digital I/O. |
| 8 | 14 | GPIO 14 (TXD / UART) | Shared with Bluetooth if not disabled in config. |
| 9 | - | Ground (GND) | Common ground. |
| 10 | 15 | GPIO 15 (RXD / UART) | Shared with Bluetooth if not disabled. |
| 11 | 17 | GPIO 17 | Standard digital I/O. |
| 12 | 18 | GPIO 18 (PWM0) | Hardware PWM capable. Great for servos/LEDs. |
| 13 | 27 | GPIO 27 | Standard digital I/O. |
| 14 | - | Ground (GND) | Common ground. |
| 15 | 22 | GPIO 22 | Standard digital I/O. |
| 16 | 23 | GPIO 23 | Standard digital I/O. |
| 17 | - | 3.3V Power | Max draw ~50mA. |
| 18 | 24 | GPIO 24 | Standard digital I/O. |
| 19 | 10 | GPIO 10 (MOSI / SPI) | SPI0 Master Out Slave In. |
| 20 | - | Ground (GND) | Common ground. |
| 21 | 9 | GPIO 9 (MISO / SPI) | SPI0 Master In Slave Out. |
| 22 | 25 | GPIO 25 | Standard digital I/O. |
| 23 | 11 | GPIO 11 (SCLK / SPI) | SPI0 Clock. |
| 24 | 8 | GPIO 8 (CE0 / SPI) | SPI0 Chip Select 0. |
| 25 | - | Ground (GND) | Common ground. |
| 26 | 7 | GPIO 7 (CE1 / SPI) | SPI0 Chip Select 1. |
| 27 | 0 | GPIO 0 (ID_SD) | Reserved for HAT EEPROM. Do not use. |
| 28 | 1 | GPIO 1 (ID_SC) | Reserved for HAT EEPROM. Do not use. |
| 29 | 5 | GPIO 5 | Standard digital I/O. |
| 30 | - | Ground (GND) | Common ground. |
| 31 | 6 | GPIO 6 | Standard digital I/O. |
| 32 | 12 | GPIO 12 (PWM0) | Hardware PWM capable. |
| 33 | 13 | GPIO 13 (PWM1) | Hardware PWM capable. |
| 34 | - | Ground (GND) | Common ground. |
| 35 | 19 | GPIO 19 (MISO / SPI1) | SPI1 MISO (Auxiliary SPI). |
| 36 | 16 | GPIO 16 (CE2 / SPI1) | SPI1 Chip Select 2. |
| 37 | 26 | GPIO 26 | Standard digital I/O. |
| 38 | 20 | GPIO 20 (MOSI / SPI1) | SPI1 MOSI. |
| 39 | - | Ground (GND) | Common ground. |
| 40 | 21 | GPIO 21 (SCLK / SPI1) | SPI1 Clock. |
For interactive visual mapping and HAT (Hardware Attached on Top) compatibility checks, the community-maintained pinout.xyz remains the gold standard reference for Pi hardware.
Navigating GPIO Numbering Standards: BCM vs. Physical vs. WiringPi
Just as mains wiring relies on regional standards (NEC in the US, IEC in Europe), Raspberry Pi GPIO programming relies on software numbering standards. Using the wrong standard in your code is the #1 cause of 'my LED won't blink' support tickets. Here is which standard applies to your environment:
| Standard | Where it Applies | Example: Physical Pin 3 | Verdict |
|---|---|---|---|
| BCM (Broadcom) | Python (RPi.GPIO, gpiozero), modern C/C++ libraries, Raspberry Pi OS. | BCM 2 | Use this. The official, future-proof standard. |
| Physical (BOARD) | Hardware wiring diagrams, breadboarding, RPi.GPIO (when explicitly set). | Pin 3 | Use for wiring. Count from the SD card edge. |
| WiringPi | Legacy C/C++ tutorials, old Arduino-ported code. | WiringPi 8 | Avoid. Deprecated as of 2019; fails on Pi 4/5. |
How to set the standard in Python:
If you are using the classic RPi.GPIO library, you must declare your numbering scheme in the first few lines of your script, or the library will throw a runtime warning and default to an unpredictable state.
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM) # Use Broadcom SOC channel numbers
# GPIO.setup(2, GPIO.OUT) # This targets Physical Pin 3Modern Python development heavily favors the gpiozero library, which defaults to BCM numbering automatically and handles cleanup gracefully, eliminating the need for manual GPIO.cleanup() calls.
Rows People Get Wrong: Bricked Boards and Fried Pins
When mapping the Raspberry Pi 4 pinout, certain rows in the table above carry hidden hardware traps. I have replaced multiple Pi 4 SoCs because builders assumed all GPIO pins behave identically. Here are the specific rows you must treat with caution:
The Power Trap: Pin 1 vs. Pin 2
Physical Pin 1 outputs 3.3V, while Physical Pin 2 outputs 5V. The Raspberry Pi 4's SoC operates strictly at 3.3V logic. If you are reading a 5V sensor (like an HC-SR04 ultrasonic module), you must use a voltage divider or a logic level shifter. Feeding 5V directly into any BCM GPIO pin will destroy the silicon instantly. The board's polyfuse protects against overcurrent on the 5V rail, but it offers zero protection against overvoltage on the GPIO data lines.
The I2C Pull-Up Reality: Pins 3 and 5
BCM GPIO 2 (SDA) and GPIO 3 (SCL) are the default I2C bus pins. On the Pi 4 PCB, these lines have physical 1.8kΩ pull-up resistors tied to the 3.3V rail. If you attempt to use these pins as standard digital inputs with external buttons, the internal pull-ups will fight your external circuitry, causing ghost readings. Reserve Pins 3 and 5 exclusively for I2C devices (like BME280 sensors or OLED displays).
The UART Bluetooth Conflict: Pins 8 and 10
BCM 14 (TXD) and BCM 15 (RXD) are the primary UART serial pins. However, on the Pi 4, the primary UART is routed to the onboard Bluetooth module by default. If you plug a GPS module or serial console into Pins 8 and 10 and get no data, you must disable the Bluetooth UART mapping in your /boot/config.txt (or /boot/firmware/config.txt in modern Bookworm releases) by adding dtoverlay=disable-bt.
The HAT EEPROM Reserved Pins: 27 and 28
Physical Pins 27 and 28 (BCM 0 and 1) are reserved for the HAT identification EEPROM. The Pi queries these pins on boot to automatically configure GPIO states for official add-on boards. Do not wire external components to these pins, or you risk corrupting the boot sequence or causing I2C address collisions.
Safe Interpretation: Faded Markings and Enclosed Boards
On a bare Pi 4, Pin 1 is usually marked with a silkscreen triangle or a 'P1' label. But what happens when the silkscreen is faded, or the board is mounted inside an aluminum passive-cooling case where only the pin tips are visible?
The Square Pad Rule:
Flip the board over (or look closely at the base of the header pins). Pin 1 is the only pin on the entire 40-pin header that has a square copper solder pad on the PCB. Every other pin (2 through 40) has a perfectly round solder pad. If you are working blind on an enclosed board, use a multimeter in continuity mode: probe the metal shielding of the USB ports (which is grounded) and tap the top row pins until you find a Ground pin (like Pin 6 or 9). From there, you can count backward to Pin 1 based on the standard layout.
Verifying Dead Circuits:
Before writing code to debug a 'dead' GPIO, verify the physical connection. Set your multimeter to DC Voltage. Place the black probe on Pin 6 (GND) and the red probe on Pin 1 or 17. You should read between 3.25V and 3.35V. If you read 0V, your Pi's 3.3V regulator has failed (often due to a previous 5V short), and the board must be replaced. For official hardware specifications and tolerance thresholds, always defer to the Raspberry Pi Foundation's official documentation.






