Home / Reference

Raspberry Pi GPIO pinout: the 40-pin header explained

A Raspberry Pi board with its 40-pin GPIO header highlighted along the top edge
Beginner

Every Raspberry Pi with a 40-pin header, from the Pi 2 and Zero to the Pi 4, Pi 5 and Pi 500, uses the same layout. This page shows every pin, what it can do, and the rules that keep your Pi safe.

The two rules that matter most. The GPIO pins work at 3.3 V and are not 5 V tolerant: connecting 5 V to a GPIO pin can destroy the chip. And never connect a 5 V pin straight to a 3V3 or GPIO pin, even for a moment.

Physical pins and GPIO numbers

There are two ways to number the pins. Physical (or board) numbers count the header itself: pin 1 is the square pad nearest the corner of the board, odd numbers run along the inner row and even numbers along the outer edge. GPIO (or BCM) numbers are the chip's own names, and they are what almost all code uses. So "GPIO 17" is physical pin 11.

Power Ground GPIO / signal Control

Also used forFunctionPinPinFunctionAlso used for
3V3125V
I²C1 SDAGPIO 2345V
I²C1 SCLGPIO 356GND
GPCLK0GPIO 478GPIO 14UART TX
GND910GPIO 15UART RX
GPIO 171112GPIO 18PWM0, PCM CLK
GPIO 271314GND
GPIO 221516GPIO 23
3V31718GPIO 24
SPI0 MOSIGPIO 101920GND
SPI0 MISOGPIO 92122GPIO 25
SPI0 SCLKGPIO 112324GPIO 8SPI0 CE0
GND2526GPIO 7SPI0 CE1
ID_SD (HAT EEPROM)GPIO 02728GPIO 1ID_SC (HAT EEPROM)
GPIO 52930GND
GPIO 63132GPIO 12PWM0
PWM1GPIO 133334GND
PWM1, PCM FSGPIO 193536GPIO 16
GPIO 263738GPIO 20PCM DIN
GND3940GPIO 21PCM DOUT

On a Pi with gpiozero installed, which includes Raspberry Pi OS, run pinout in a terminal to print this map for the exact board in front of you.

Power pins

  • 5V (pins 2 and 4) connect straight to the Pi's power input. What they can supply depends on your power supply, minus what the Pi itself is using. They're fine for a few sensors or a small fan. For motors, LED strips or servos, give those their own supply and share only ground.
  • 3V3 (pins 1 and 17) come from the Pi's on-board regulator. Use them for 3.3 V sensors and modules, but keep the load modest. Anything hungry needs its own regulator.
  • GND: there are eight ground pins. Any of them will do, and every external circuit you connect must share a ground with the Pi.

The special-purpose pins

  • I²C (GPIO 2 and 3) already have 1.8 kΩ pull-up resistors to 3.3 V on the board. That's handy for I²C, but it means these two pins read high when nothing is connected.
  • UART (GPIO 14 and 15) are the serial port. Connect TX to the other device's RX and RX to its TX. Turn the serial port on in raspi-config under Interface Options.
  • SPI0 (GPIO 7 to 11) handles fast devices such as displays and ADCs. CE0 and CE1 are two chip selects, so two SPI devices can share the bus.
  • Hardware PWM (GPIO 12, 13, 18 and 19) gives steady PWM for servos and dimming. There are two PWM channels, so GPIO 12 and 18 share one, and 13 and 19 share the other.
  • ID_SD and ID_SC (GPIO 0 and 1) are reserved for the identity EEPROM on HAT add-on boards. Leave them alone unless you are designing a HAT.

Any GPIO pin can also be a plain input or output. The extra functions only matter when you turn them on.

How much current can a GPIO pin give?

Very little. A GPIO pin is a signal, not a power source. It can light a small LED through a resistor (see the LED resistor calculator), but for anything more, such as a relay, motor, buzzer or bright LED, switch it with a transistor or MOSFET. Our guide to transistors as switches shows how.

Wire GPIO 17 (physical pin 11) to an LED's long leg through a 330 Ω resistor, and the LED's short leg to any GND pin. Then run:

from gpiozero import LED
from signal import pause

led = LED(17)      # GPIO number, not physical pin number
led.blink()        # on for 1 second, off for 1 second, forever
pause()

gpiozero works on every Pi model including the Pi 5. The older RPi.GPIO library does not work on the Pi 5, because the Pi 5's GPIO pins are driven by a different chip (RP1).

Common mistakes

  • Mixing up physical and GPIO numbers. If nothing happens, check which numbering your code uses.
  • Connecting 5 V signals. Arduino boards and many older modules output 5 V. Use a level shifter or a voltage divider on any signal going into the Pi.
  • Powering motors from the header. The voltage dip can crash or reset the Pi. Use a separate supply.
  • Wiring with the power on. A slipped jumper wire can short 5 V to 3V3. Shut down and unplug first.

Sources

The main references behind this guide. Numbers we worked out ourselves, such as the code outputs, come from running the code.