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.

PinFunctionBCM GPIOPinFunctionBCM GPIO
13.3V Power-25V Power-
3I2C SDA1245V Power-
5I2C SCL136Ground-
7General I/O48UART TXD14
9Ground-10UART RXD15
11General I/O1712Hardware PWM018
13General I/O2714Ground-
15General I/O2216General I/O23
173.3V Power-18General I/O24
19SPI MOSI1020Ground-
21SPI MISO922General I/O25
23SPI SCLK1124SPI CE08
25Ground-26SPI CE17
27HAT ID_SD028HAT ID_SC1
29General I/O530Ground-
31General I/O632Hardware PWM012
33Hardware PWM11334Ground-
35Hardware PCM1936General I/O16
37General I/O2638General I/O20
39Ground-40General I/O21

Source: Raspberry Pi Official Documentation and the community-maintained Pinout.xyz database.

Rows People Get Wrong (And How to Avoid Bricking Your Pi)

Warning: Misidentifying power rails is the number one cause of dead Pi 4 boards. Always verify with a multimeter before applying power to a custom HAT or breadboard.

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.

FunctionIDC Ribbon Cable (Universal)IEC 60446 / EU DC StandardNEC / US DC Adaptation
Ground (GND)Black (or Wire 1 if reversed)Blue or BlackBlack or White/Green
5V PowerRedBrownRed
3.3V PowerOrangeOrangeOrange or Yellow
I2C SDA / SPI MISOYellowBlueBlue
I2C SCL / SPI SCLKGreenYellowYellow
Signal / GPIOBlue / Purple / GrayBlack (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 PinBCM GPIORequired Hardware / Config
Standard I2C Sensor (e.g., BME280)Pins 3 & 52 & 3Enable I2C in raspi-config. Add 4.7kΩ pull-ups if sensor lacks them.
Hardware PWM (Servo / DC Motor)Pin 1218Use pigpio library for hardware PWM. Do not use RPi.GPIO.
5V Logic Sensor (e.g., HC-SR04)Pin 11 (via Level Shifter)17Mandatory: Use a TXB0108 or BSS138 level shifter to drop 5V echo to 3.3V.
Serial Console / GPS ModulePins 8 & 1014 & 15Disable serial console in raspi-config to free the UART hardware.
SPI Display (e.g., ILI9341)Pins 19, 21, 23, 2410, 9, 11, 8Enable 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.

The Multimeter Continuity Method:
  1. Disconnect all power from the Pi.
  2. Set your multimeter to continuity mode (the diode/beep setting).
  3. Place the black probe on one of the four metal mounting holes (these are hard-tied to the ground plane).
  4. 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).
  5. 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.