The Raspberry Pi 4 Model B uses a standard 40-pin GPIO header. Pin 1 is the 3.3V power output located at the top-left corner (nearest the USB-C power connector), identifiable by its square copper solder pad. The Pi 4 logic level is strictly 3.3V; never plug a 5V signal directly into any GPIO pin without a level shifter, or you will permanently destroy the BCM2711 SoC.
The 40-Pin GPIO Reference Table
Below is the complete physical pinout for the Raspberry Pi 4. This table uses the modern BCM (Broadcom) GPIO numbering scheme. Note that the legacy WiringPi library was deprecated in 2019; always write your Python (RPi.GPIO / gpiozero) or C++ (pigpio / libgpiod) code using the BCM numbers listed here.
| Pin | Function | BCM GPIO | Pin | Function | BCM GPIO |
|---|---|---|---|---|---|
| 1 | 3.3V Power | - | 2 | 5V Power | - |
| 3 | I2C SDA1 | 2 | 4 | 5V Power | - |
| 5 | I2C SCL1 | 3 | 6 | Ground | - |
| 7 | General I/O | 4 | 8 | UART TXD | 14 |
| 9 | Ground | - | 10 | UART RXD | 15 |
| 11 | General I/O | 17 | 12 | Hardware PWM0 | 18 |
| 13 | General I/O | 27 | 14 | Ground | - |
| 15 | General I/O | 22 | 16 | General I/O | 23 |
| 17 | 3.3V Power | - | 18 | General I/O | 24 |
| 19 | SPI MOSI | 10 | 20 | Ground | - |
| 21 | SPI MISO | 9 | 22 | General I/O | 25 |
| 23 | SPI SCLK | 11 | 24 | SPI CE0 | 8 |
| 25 | Ground | - | 26 | SPI CE1 | 7 |
| 27 | HAT ID_SD | 0 | 28 | HAT ID_SC | 1 |
| 29 | General I/O | 5 | 30 | Ground | - |
| 31 | General I/O | 6 | 32 | Hardware PWM0 | 12 |
| 33 | Hardware PWM1 | 13 | 34 | Ground | - |
| 35 | Hardware PCM | 19 | 36 | General I/O | 16 |
| 37 | General I/O | 26 | 38 | General I/O | 20 |
| 39 | Ground | - | 40 | General I/O | 21 |
Source: Raspberry Pi Official Documentation and the community-maintained Pinout.xyz database.
Rows People Get Wrong (And How to Avoid Bricking Your Pi)
The 3.3V vs 5V Trap (Pins 1/17 vs Pins 2/4)
Pins 1 and 17 output 3.3V, while Pins 2 and 4 output 5V. The 3.3V rail on the Pi 4 is generated by an onboard LDO regulator and is strictly limited to about 50mA of continuous draw for external peripherals. If you try to power a 5V relay module or a high-draw LED strip from Pin 1, you will brownout the SoC or burn out the regulator. Use the 5V pins (2 or 4) for external power, provided your power supply can handle the current (the USB-C port is rated for 3A total board draw).
The HAT EEPROM Pins (Pins 27 & 28)
BCM GPIO 0 (Pin 27) and GPIO 1 (Pin 28) are reserved for the HAT (Hardware Attached on Top) identification EEPROM. They feature onboard 1.8kΩ pull-up resistors to 3.3V. While you can technically use them as standard I/O in a pinch, doing so will break HAT auto-configuration on boot. Leave them alone unless you are designing a custom HAT.
Hardware PWM Illusions
The Pi 4 only has two true hardware PWM channels, mapped to four physical pins: GPIO 12, 13, 18, and 19. If you need clean, jitter-free PWM for motor control or audio DACs, you must use one of these four pins. All other GPIO pins can only perform software PWM, which introduces CPU-load-dependent jitter that will cause servos to twitch or LEDs to flicker.
Wire Color Standards: Ribbon Cables vs. IEC/NEC Discrete Wiring
While the Pi's physical pinout is universal, the wires you use to connect it to the outside world should follow standardized color codes to prevent catastrophic cross-wiring. The standard you follow depends on your cable type and region.
| Function | IDC Ribbon Cable (Universal) | IEC 60446 / EU DC Standard | NEC / US DC Adaptation |
|---|---|---|---|
| Ground (GND) | Black (or Wire 1 if reversed) | Blue or Black | Black or White/Green |
| 5V Power | Red | Brown | Red |
| 3.3V Power | Orange | Orange | Orange or Yellow |
| I2C SDA / SPI MISO | Yellow | Blue | Blue |
| I2C SCL / SPI SCLK | Green | Yellow | Yellow |
| Signal / GPIO | Blue / Purple / Gray | Black (with numbered ferrule) | Any distinct color |
Note: For discrete low-voltage DC wiring, we adapt the IEC and NEC mains standards to safe DC equivalents. Never use green/yellow (earth ground) for a 3.3V signal line, as it will cause dangerous confusion if the project is later integrated with mains-powered equipment.
Peripheral Decision Tree: Which Pin Should You Use?
Stop guessing which GPIO to assign in your Python script. Use this decision matrix to select the exact pin for your peripheral.
| If your peripheral requires... | Then use this Physical Pin | BCM GPIO | Required Hardware / Config |
|---|---|---|---|
| Standard I2C Sensor (e.g., BME280) | Pins 3 & 5 | 2 & 3 | Enable I2C in raspi-config. Add 4.7kΩ pull-ups if sensor lacks them. |
| Hardware PWM (Servo / DC Motor) | Pin 12 | 18 | Use pigpio library for hardware PWM. Do not use RPi.GPIO. |
| 5V Logic Sensor (e.g., HC-SR04) | Pin 11 (via Level Shifter) | 17 | Mandatory: Use a TXB0108 or BSS138 level shifter to drop 5V echo to 3.3V. |
| Serial Console / GPS Module | Pins 8 & 10 | 14 & 15 | Disable serial console in raspi-config to free the UART hardware. |
| SPI Display (e.g., ILI9341) | Pins 19, 21, 23, 24 | 10, 9, 11, 8 | Enable SPI. Keep wires under 10cm to avoid signal reflection at high clock speeds. |
Safe Verification When Silkscreen is Missing or Faded
If you are working with a cloned board, a heavily used Pi, or a custom carrier board where the GPIO silkscreen has rubbed off, do not guess pin locations. A single 5V miswire will instantly fry the BCM2711 power domain.
- Disconnect all power from the Pi.
- Set your multimeter to continuity mode (the diode/beep setting).
- Place the black probe on one of the four metal mounting holes (these are hard-tied to the ground plane).
- Probe the header pins with the red probe. Every pin that beeps is a Ground pin (Pins 6, 9, 14, 20, 25, 30, 34, 39).
- Locate the top-left corner of the header (nearest the USB-C port). The pin diagonally adjacent to the top-left Ground pin is Pin 1 (3.3V). You can verify this by flipping the board over; Pin 1 is the only pad in that corner that is perfectly square, while all others are round.
By strictly adhering to the BCM numbering, respecting the 3.3V logic ceiling, and mapping your wire colors to established DC standards, you eliminate the most common hardware failure modes in Raspberry Pi embedded projects.






