AI agents & screen readers: for a machine-readable, text-only catalogue, start at /llms.txt. Products are available as Markdown (/products.md, /products/{handle}.md) and JSON (/products.json, /products/{handle}.json).
Store

The Raspberry Pi GPIO header

What each of the 40 GPIO pins does, which pins carry I2C, SPI and UART, how much the pins can safely handle, and how to look the layout up on the Pi itself.

Which boards have it

Every current Raspberry Pi computer has the same 40-pin GPIO header, two rows of 20 pins at the standard 2.54 mm (0.1 inch) spacing:

  • Raspberry Pi 5, 4, 3, 2 and the Pi 1 Model A+ and B+;
  • Raspberry Pi 400 and 500, where the header sits along the back edge of the keyboard;
  • Raspberry Pi Zero, Zero W and Zero 2 W, where the holes are there but no header is fitted. Either solder one on, or buy the "WH" version, which comes with the header already soldered;
  • Compute Modules, which bring their GPIO out through the module's connectors. The official Compute Module 4 and 5 IO boards carry a standard 40-pin header.

The very first Model A and Model B had a shorter 26-pin header. Raspberry Pi Pico boards are microcontrollers with a completely different pinout, so this guide doesn't apply to them.

Two ways to number a pin

There are two numbering schemes, and mixing them up is the most common wiring mistake:

  • Physical pin numbers (1 to 40) count across the header itself. Pin 1 is on the inner row; odd numbers run along the inner row and even numbers along the board edge. On full-size boards, pin 1 is at the end furthest from the USB ports.
  • GPIO numbers (also called BCM numbers) are the names the processor gives each pin, such as GPIO17. They don't follow the physical order. Almost all software, including gpiozero, uses these.

So "GPIO17" is physical pin 11. The table below gives both.

The 40-pin layout

Each row of the table is one pair of pins, so it matches the board when you turn it so the header runs down the right-hand side with pin 1 at the top. Pins marked "General purpose" have no fixed job and are free for your own use (most can also take on other functions when enabled).

Function GPIO Pin Pin GPIO Function
3.3 V power – 1 2 – 5 V power
I2C SDA 2 3 4 – 5 V power
I2C SCL 3 5 6 – Ground
General purpose (GPCLK0) 4 7 8 14 UART TX
Ground – 9 10 15 UART RX
General purpose 17 11 12 18 PCM CLK, hardware PWM
General purpose 27 13 14 – Ground
General purpose 22 15 16 23 General purpose
3.3 V power – 17 18 24 General purpose
SPI0 MOSI 10 19 20 – Ground
SPI0 MISO 9 21 22 25 General purpose
SPI0 SCLK 11 23 24 8 SPI0 CE0
Ground – 25 26 7 SPI0 CE1
ID EEPROM data (ID_SD) 0 27 28 1 ID EEPROM clock (ID_SC)
General purpose 5 29 30 – Ground
General purpose 6 31 32 12 Hardware PWM
Hardware PWM 13 33 34 – Ground
PCM FS, hardware PWM 19 35 36 16 General purpose
General purpose 26 37 38 20 PCM DIN
Ground – 39 40 21 PCM DOUT

In short: 3.3 V on pins 1 and 17, 5 V on pins 2 and 4, and ground on pins 6, 9, 14, 20, 25, 30, 34 and 39.

The buses at a glance

Interface Signal GPIO Physical pin
I2C SDA (data) 2 3
I2C SCL (clock) 3 5
UART (serial) TX 14 8
UART (serial) RX 15 10
SPI0 MOSI 10 19
SPI0 MISO 9 21
SPI0 SCLK 11 23
SPI0 CE0 / CE1 8 / 7 24 / 26
SPI1 MOSI 20 38
SPI1 MISO 19 35
SPI1 SCLK 21 40
SPI1 CE0 / CE1 / CE2 18 / 17 / 16 12 / 11 / 36
Hardware PWM – 12, 13, 18, 19 32, 33, 12, 35
PCM / I2S audio CLK, FS, DIN, DOUT 18, 19, 20, 21 12, 35, 38, 40

Any GPIO can do software PWM; the four pins above do it in hardware, which is steadier for servos and audio.

I2C, SPI and the serial port are switched off by default. Turn them on with sudo raspi-config under Interface Options, then reboot.

Pins 27 and 28: leave them alone

GPIO0 and GPIO1 are reserved for the ID EEPROM on a HAT. At boot the Pi reads that chip over these two pins to learn which HAT is fitted and how to set it up. Don't use them for your own wiring unless you're building a HAT. See What makes a HAT for more.

3.3 V logic and current limits

The GPIO pins work at 3.3 V. An output is either 3.3 V (high) or 0 V (low), and inputs expect the same. Never put 5 V on a GPIO pin: the pins aren't 5 V tolerant and you can damage the Pi. If a sensor or module runs at 5 V, use a level shifter or a voltage divider on its output.

The pins can only supply small currents:

  • On the Pi 1, 2, 3 and Zero boards a pin is set to drive 8 mA by default and can be set as high as 16 mA. On the Pi 4 family it's 4 mA by default, 8 mA at most. These are the currents at which the pin still holds its voltage, not safe limits.
  • The 3.3 V supply behind the pins was sized for roughly 3 mA per pin. Pulling large currents from many pins at once can drag it down.
  • An LED always needs a series resistor. Motors, relays and solenoids need a driver board or transistor, never a direct connection.

The 5 V pins are connected to the Pi's own 5 V supply, so what's available there depends on your power supply and what else is plugged in.

Two other details worth knowing:

  • GPIO2 and GPIO3 (the I2C pins) have pull-up resistors fitted on the board, so they read high when nothing is connected.
  • Every pin starts up as an input after power-on, with its default pull-up or pull-down applied.

On a Pi 5 the header is driven by the RP1 input/output chip rather than the main processor. The pin layout and functions are the same, but some older Python libraries don't work; see Controlling GPIO from Python with gpiozero.

Look it up on the Pi

Raspberry Pi OS includes a pinout command (part of the gpiozero library). Run it in a terminal and it draws your board, marks where the header is, and prints the pin layout:

pinout

If it's missing on a minimal install, add it with:

sudo apt install python3-gpiozero

On current Raspberry Pi OS, this shows what each pin is set to right now (input, output or an alternate function):

pinctrl get

Your user needs to be in the gpio group to control the pins. The default user on Raspberry Pi OS already is.

Parts in this guide

Maddy from the Pi Australia team

Need help? We're here for you!

Hi, I'm Maddy. My team and I are ready to help with your order or any questions.