The 40-pin GPIO header on the Raspberry Pi 3, 4, 5, and 400 is physically and electrically identical. Pin 1 (3.3V) is always located closest to the SD card slot, and Pin 2 (5V) sits on the outer edge. If you are wiring sensors, relays, or HATs, you need to know both the physical layout and the Broadcom (BCM) software mapping. Below is the complete bench reference.

The 40-Pin GPIO Header Reference Table

Read this table as you look down at the Pi with the USB ports facing you and the GPIO header on the top right. The left column is the odd-numbered physical pins (closest to the board edge), and the right column is the even-numbered pins.

Phys (Odd) BCM (Odd) Function / Name BCM (Even) Phys (Even)
1-3.3V Power-2
32GPIO 2 (SDA1 / I2C)-4
53GPIO 3 (SCL1 / I2C)-6
74GPIO 4 (GPCLK0)148
9-Ground1510
1117GPIO 171812
1327GPIO 27-14
1522GPIO 222316
17-3.3V Power2418
1910GPIO 10 (MOSI / SPI)-20
219GPIO 9 (MISO / SPI)2522
2311GPIO 11 (SCLK / SPI)824
25-Ground726
270GPIO 0 (ID_SD / I2C)128
295GPIO 5-30
316GPIO 61232
3313GPIO 13 (PWM1)-34
3519GPIO 19 (MISO / PCM)1636
3726GPIO 262038
39-Ground2140

Note: Pins 27 and 28 (ID_SD and ID_SC) are reserved for HAT EEPROM communication. Pins 1, 17 (3.3V) and 2, 4 (5V) are power rails, not software-controllable GPIOs. For a visual, interactive map, the community-standard Pinout.xyz remains the most reliable digital reference.

Numbering Standards & External Wire Color Codes

When reading a raspberry pi pinout diagram, the first hurdle is software numbering. The Pi ecosystem uses two primary standards:

  • BCM (Broadcom): Maps to the internal SoC pin numbers (e.g., Physical Pin 3 = BCM 2). This is the default for modern Python libraries like gpiozero and RPi.GPIO.
  • BOARD (Physical): Maps to the physical pin number on the header (1 through 40). Useful when wiring with a multimeter, as you just count the pins.

Regional Wire Color Standards for Pi HATs

While the Pi’s silicon pinout is a global standard, the wire color codes you use when building external relay boards, sensor arrays, or mains-interfacing HATs must follow your region's electrical codes. Mixing these up when wiring a Pi-controlled AC contactor can be lethal.

Wire Function US (NEC / AWG Standard) EU/UK/AU (IEC 60446) Old UK (Pre-2004)
DC Positive (e.g., 5V/12V to Relay)RedBrown (or Red)Red
DC Negative / GroundBlackBlue (or Black)Black
AC Line (Mains Hot)Black (or Red)BrownRed
AC NeutralWhite (or Gray)BlueBlack
AC Earth GroundGreen / Bare / Green-YellowGreen-YellowGreen
⚠️ Warning: If you are retrofitting an older UK relay HAT (pre-2004 colors) to a modern Pi setup, the black wire is Neutral, not DC Ground. Always verify with a multimeter before applying power. For official Raspberry Pi hardware design guidelines, consult the Raspberry Pi Compute Module and HAT specifications.

Safe Interpretation When Markings are Faded or Missing

On older Pi models, third-party HATs, or ribbon cables where the silkscreen has rubbed off, you must identify Pin 1 safely:

  1. The Square Pad Rule: Look at the solder joints on the underside of the Pi or HAT. Pin 1 always has a square copper pad. All other pins have round pads.
  2. The Ribbon Cable Stripe: If using a 40-pin GPIO ribbon cable, the wire with the distinct color stripe (usually red or blue) is always Pin 1.
  3. Continuity Testing: If all visual cues are gone, set your multimeter to continuity mode. Probe the metal USB port shielding (which is tied to ground) and test the header pins. The pins that beep are your Grounds (6, 9, 14, 20, 25, 30, 34, 39). Pin 1 is the 3.3V pin immediately adjacent to the Ground pin closest to the SD card slot.

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

The Raspberry Pi GPIO operates at strictly 3.3V logic levels. The most common way hobbyists destroy their Pi is by misinterpreting the pinout diagram and feeding 5V into a 3.3V pin.

  • The 5V Trap (Pins 2 & 4 vs Pins 3 & 5): Pins 2 and 4 output 5V from the USB power supply. Pins 3 and 5 are I2C data lines (BCM 2 and 3) which are pulled up to 3.3V. If you accidentally wire a 5V sensor output to Pin 3, you will back-feed the 3.3V regulator and likely fry the SoC. Always use a logic level shifter or a voltage divider when connecting 5V Arduino-style sensors to the Pi.
  • The UART Swap (Pins 8 & 10): Pin 8 is GPIO 14 (TXD) and Pin 10 is GPIO 15 (RXD). When wiring a serial console cable or an ESP32, remember that TX must connect to RX, and RX to TX. Furthermore, the Pi’s UART is 3.3V; connecting it directly to an RS-232 port (which swings ±12V) will instantly destroy the pin.
  • The "Do Not Connect" Pins (27 & 28): On Pi 3 and newer, physical pins 27 and 28 are reserved for the HAT ID EEPROM (I2C0). Do not use these for general-purpose GPIO or attach external pull-up resistors to them, as they are actively used during the boot sequence to configure the board.

Raspberry Pi Pinout Diagram FAQs

How do I read a Raspberry Pi pinout diagram if the silkscreen is faded?

Flip the board over and look at the solder pads for the header. Pin 1 is universally designated by a square solder pad, while pins 2 through 40 use round pads. If you are looking at a HAT with faded markings, use a multimeter in continuity mode to find the ground pins (they will beep when touched to the metal USB shielding), then count backward to locate Pin 1.

What is the difference between BCM and BOARD in a Raspberry Pi pinout diagram?

BOARD refers to the physical pin number on the 40-pin header (1-40), which is what you count with your eyes. BCM refers to the Broadcom SoC internal GPIO number (e.g., Physical Pin 3 is BCM 2). In Python, GPIO.setmode(GPIO.BOARD) uses the physical count, while GPIO.setmode(GPIO.BCM) uses the chip-level mapping. BCM is the modern standard for Pi software development.

Can I use the Raspberry Pi pinout diagram for the Pi Zero 2 W?

Yes, the electrical mapping is identical. The Pi Zero series uses the exact same BCM-to-Physical 40-pin mapping as the full-sized Pi 4 and 5. The only physical difference is that the Zero often ships with unpopulated header pins, requiring you to solder them on. Ensure you solder the headers with the square pad aligned to Pin 1 (closest to the SD card edge).

Which pins are safe to use for standard GPIO input/output?

Out of the 40 pins, 8 are power/ground, 2 are reserved for HAT ID, and several have default boot behaviors. The safest, completely "clean" GPIO pins with no default pull-ups or boot-state conflicts are: BCM 4, 5, 6, 12, 13, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, and 27. Avoid BCM 2 and 3 (I2C pull-ups), BCM 14 and 15 (UART console), and BCM 0 and 1 (HAT ID) unless you are specifically using those protocols.