Skip to content
Guide
15 min read
July 13, 2026

Raspberry Pi GPIO Pinout: The Ultimate Reference

A comprehensive map of the 40-pin GPIO header on Raspberry Pi 4, 5, and Zero.

Raspberry Pi GPIO Pinout: The Ultimate Reference

Introduction

The GPIO (General Purpose Input/Output) pins are the heart of what makes the Raspberry Pi so powerful as a maker platform. Unlike a regular computer, the Pi gives you direct, programmable access to hardware — sensors, motors, LEDs, displays, relays, and virtually any electronic component you can imagine.

Whether you're a beginner blinking your first LED or an advanced maker building a home automation system, this guide is your go-to reference for every single pin on the 40-pin GPIO header found on the Raspberry Pi 2, 3, 4, 5, and Zero series.


The 40-Pin Header at a Glance

All modern Raspberry Pi models share the same 40-pin GPIO header layout, making your projects portable across generations.

Image

Pin Numbering Systems

This is one of the most common sources of confusion. There are two ways to refer to GPIO pins:

SystemAlso CalledExample
BCMGPIO numberingGPIO17 = the 17th Broadcom GPIO
BOARDPhysical numberingPin 11 = the 11th physical pin on the header

In Python with the RPi.GPIO library:

import RPi.GPIO as GPIO

# Use BCM numbering (recommended)
GPIO.setmode(GPIO.BCM)

# OR use physical board pin numbers
GPIO.setmode(GPIO.BOARD)
Physical PinBCM GPIONameFunction
13.3V Power3.3V supply (max 50mA total)
25V Power5V supply direct from USB
3GPIO2SDA1I²C Data
45V Power5V supply
5GPIO3SCL1I²C Clock
6GNDGround
7GPIO4GPCLK0General Purpose Clock
8GPIO14TXD0UART Transmit
9GNDGround
10GPIO15RXD0UART Receive
11GPIO17General Purpose
12GPIO18PCM_CLKPWM0 / PCM Clock
13GPIO27General Purpose
14GNDGround
15GPIO22General Purpose
16GPIO23General Purpose
173.3V Power3.3V supply
18GPIO24General Purpose
19GPIO10SPI0_MOSISPI Data (Master Out)
20GNDGround
21GPIO9SPI0_MISOSPI Data (Master In)
22GPIO25General Purpose
23GPIO11SPI0_SCLKSPI Clock
24GPIO8SPI0_CE0_NSPI Chip Enable 0
25GNDGround
26GPIO7SPI0_CE1_NSPI Chip Enable 1
27GPIO0ID_SDEEPROM I²C Data (HAT ID)
28GPIO1ID_SCEEPROM I²C Clock (HAT ID)
29GPIO5General Purpose
30GNDGround
31GPIO6General Purpose
32GPIO12PWM0PWM Channel 0
33GPIO13PWM1PWM Channel 1
34GNDGround
35GPIO19SPI1_MISOSPI1 / PCM FS
36GPIO16SPI1_CE0_NSPI1 Chip Enable
37GPIO26General Purpose
38GPIO20SPI1_MOSISPI1 Data In
39GNDGround
40GPIO21SPI1_SCLKSPI1 Clock

Pin Categories Explained

🔴 Power Pins

The Pi provides two voltage rails on the header:

  • 3.3V (Pins 1, 17) — All GPIO pins operate at 3.3V logic. Total current limit is ~50mA across all 3.3V pins combined.
  • 5V (Pins 2, 4) — Directly connected to your USB power supply. Useful for powering 5V peripherals, but bypasses the Pi's protection circuitry.
  • GND (Pins 6, 9, 14, 20, 25, 30, 34, 39) — Multiple ground pins distributed across the header for convenience.

🚨 Danger: GPIO pins are 3.3V logic only. Applying 5V to a GPIO pin will damage your Pi permanently. Always use a logic level shifter when interfacing with 5V devices.

🟡 General Purpose Pins

Most GPIO pins can be configured as either input or output in software:

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

# Configure GPIO17 as output (e.g. an LED)
GPIO.setup(17, GPIO.OUT)

# Configure GPIO27 as input with internal pull-up resistor
GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP)

# Blink an LED
try:
while True:
GPIO.output(17, GPIO.HIGH)
time.sleep(0.5)
GPIO.output(17, GPIO.LOW)
time.sleep(0.5)
except KeyboardInterrupt:
GPIO.cleanup()

💡 Always call GPIO.cleanup() at the end of your script to reset all pins to their default state. Skipping this can cause issues with your next script run.


🔵 I²C — Pins 3 (SDA) and 5 (SCL)

I²C (Inter-Integrated Circuit) is a two-wire serial protocol that lets you chain multiple devices on the same two wires using unique addresses.

Enable I²C on the Pi:

sudo raspi-config
# Navigate to: Interface Options → I2C → Enable

Scan for connected I²C devices:

sudo i2cdetect -y 1

Common I²C devices:

DeviceDefault I²C AddressUse
MPU-60500x68Gyroscope + Accelerometer
BMP2800x76 or 0x77Temperature + Pressure
SSD1306 OLED0x3C128×64 Display
PCF85740x20–0x27GPIO Expander
DS3231 RTC0x68Real-Time Clock

🟢 SPI — Pins 19, 21, 23, 24, 26

SPI (Serial Peripheral Interface) is faster than I²C but uses more wires. It's ideal for high-speed peripherals like displays and ADCs.

PinBCMSPI Role
19GPIO10MOSI — Master sends data
21GPIO9MISO — Pi receives data
23GPIO11SCLK — Clock signal
24GPIO8CE0 — Chip select device 0
26GPIO7CE1 — Chip select device 1

Enable SPI:

sudo raspi-config
# Navigate to: Interface Options → SPI → Enable

🟠 UART — Pins 8 (TX) and 10 (RX)

UART is used for serial communication — connecting GPS modules, Bluetooth adapters, or another microcontroller like an Arduino.

⚠️ Warning: On Raspberry Pi 3 and 4, the primary UART is used by Bluetooth by default. You may need to disable Bluetooth or use the mini UART (ttyS0) instead of the full UART (ttyAMA0).

Disable Bluetooth to free up the full UART (Pi 3/4 only):

# Add to /boot/config.txt
dtoverlay=disable-bt
sudo systemctl disable hciuart
sudo reboot

🟣 PWM — Pins 12 (GPIO18) and 33 (GPIO13)

PWM (Pulse Width Modulation) lets you simulate analog output — perfect for dimming LEDs, controlling servo motors, or generating audio tones.

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)

# Create PWM instance: pin 18, frequency 1000Hz
pwm = GPIO.PWM(18, 1000)
pwm.start(0)  # Start with 0% duty cycle

# Fade an LED from 0% to 100% brightness
for duty in range(0, 101, 5):
pwm.ChangeDutyCycle(duty)
time.sleep(0.05)

pwm.stop()
GPIO.cleanup()

Electrical Limits — Don't Fry Your Pi

These are hard limits. Exceeding them risks permanent damage:

SpecLimit
GPIO voltage (input/output)3.3V max
Max current per GPIO pin16mA
Max total GPIO current50mA
5V pin currentLimited by your PSU
3.3V rail total current~800mA (Pi 4)

Always use a current-limiting resistor with LEDs:

R = (Vsupply - Vled) / Iled
R = (3.3V - 2.0V) / 0.01A = 130Ω → use 150Ω or 220Ω

Python Quick-Start Cheat Sheet

import RPi.GPIO as GPIO
import time

# ── Setup ──────────────────────────────────────────
GPIO.setmode(GPIO.BCM)          # Use BCM pin numbering
GPIO.setwarnings(False)

# ── Output ─────────────────────────────────────────
GPIO.setup(17, GPIO.OUT)        # Set GPIO17 as output
GPIO.output(17, GPIO.HIGH)      # Turn on
GPIO.output(17, GPIO.LOW)       # Turn off

# ── Input ──────────────────────────────────────────
GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP)
state = GPIO.input(27)          # Read: 1 = HIGH, 0 = LOW

# ── Interrupt / Event ──────────────────────────────
def button_pressed(channel):
print(f"Button on GPIO{channel} pressed!")

GPIO.add_event_detect(27, GPIO.FALLING,
callback=button_pressed,
bouncetime=200)

# ── PWM ────────────────────────────────────────────
GPIO.setup(18, GPIO.OUT)
pwm = GPIO.PWM(18, 50)          # 50Hz (good for servos)
pwm.start(7.5)                  # Neutral position

# ── Cleanup ────────────────────────────────────────
GPIO.cleanup()

Useful Tools & Commands

# Show GPIO status (requires raspi-gpio package)
raspi-gpio get

# Read a single pin's state
raspi-gpio get 17

# Set a pin high/low from the terminal
raspi-gpio set 17 op dh    # output, drive high
raspi-gpio set 17 op dl    # output, drive low

# Interactive pinout reference in the terminal
pinout

Recommended Libraries

LibraryLanguageInstallBest For
RPi.GPIOPythonpip install RPi.GPIOGeneral GPIO, beginners
gpiozeroPythonpip install gpiozeroHigh-level, readable API
pigpioPython/Csudo apt install pigpioPrecise PWM, remote GPIO
wiringPiC/C++sudo apt install wiringpiC projects
lgpioPythonpip install lgpioPi 5 recommended

💡 Pi 5 users: The Pi 5 uses a new GPIO chip (gpiochip4). Use lgpio or gpiozeroRPi.GPIO may not be fully compatible yet.


Common Wiring Mistakes to Avoid

  1. Connecting 5V directly to a GPIO pin — always use a logic level converter
  2. Forgetting a resistor on an LED — will draw too much current and damage the pin
  3. Not calling GPIO.cleanup() — leaves pins in undefined states
  4. Confusing BCM and BOARD numbering — double-check before wiring
  5. Powering the Pi from the 5V GPIO pin without protection — bypasses the polyfuse

Signal In

Built from what makers search for

The lookups piling up in SolderHub's search bar every day shape what we publish next — new component pages, board guides, and firmware notes, sent out as they go live.

By subscribing you agree to our Privacy Policy. Unsubscribe anytime.