Opens in a new tab

Raspberry Pi 5, 4 and Zero GPIO Pinout

The 40-pin GPIO header has been the same on the Raspberry Pi since the B+ model – you’ll find it on the Raspberry Pi 5, 4, 3, Zero 2 W and older boards. That’s why HATs and add-on boards work across generations.

The diagram shows both GPIO (BCM) numbers and physical pin numbers 1–40. Mixing them up is the most common wiring mistake.

Specifications

  • 28 GPIO with 3.3 V logic (GPIO0–27)
  • power: 2× 5 V and 2× 3.3 V, 8× GND
  • UART (GPIO14/15), I2C1 (GPIO2/3), SPI0 and SPI1
  • hardware PWM on GPIO12, 13, 18 and 19
  • PCM/I2S on GPIO18–21, 1-Wire on any GPIO (default GPIO4)
  • GPIO0/1 (ID_SD/ID_SC) are reserved for the HAT EEPROM
  • on the Raspberry Pi 5 the header is handled by the RP1 chip, on older models directly by the Broadcom SoC

On the Raspberry Pi 5, control GPIO with the gpiozero or libgpiod library – the popular RPi.GPIO doesn’t work because of the RP1 chip (the rpi-lgpio package serves as a replacement).

Pinout and pin table

How to read the diagram: the pin layout, power and default buses (UART on GPIO14/15, I2C1, SPI0/1, PWM) are the same on all models from the B+ to the Pi 5 – and that is exactly what the diagram shows. The Pi 4 and Pi 5 have additional UART, I2C and SPI on the same pins, but each numbered differently (see the Pi 4 and Pi 5 pinouts). In code, use GPIO (BCM) numbers, not physical numbers 1–40. RPi.GPIO and pigpio don’t work on the Pi 5 – use gpiozero or libgpiod. Hover over a pin in the diagram or a table row; use the filter to highlight a bus. You can download the pinout as PNG or SVG.

Raspberry Pi 5, 4, 3 and Zero – GPIO pinout (40 pins)Raspberry Pi 5, 4, 3 and Zero – GPIO pinout (40 pins)chiptron.eu · CC BY 4.0Raspberry Pi is a trademark of Raspberry Pi Ltd. 1 3V3 ← 3.3 V output – only for smaller loads (sensors) 3 GPIO2 I2C1 SDA 5 GPIO3 I2C1 SCL 7 GPIO4 GPCLK0 9 GND 11 GPIO17 SPI1 CE1 13 GPIO27 15 GPIO22 17 3V3 ← 19 GPIO10 SPI0 MOSI 21 GPIO9 SPI0 MISO 23 GPIO11 SPI0 SCLK 25 GND 27 GPIO0 ID_SD 29 GPIO5 GPCLK1 31 GPIO6 GPCLK2 33 GPIO13 PWM1 35 GPIO19 PWM1 PCM FS SPI1 MISO 37 GPIO26 39 GND 2 5V ↔ 5 V directly from the Pi's power supply – can also power the Pi (unprotected) 4 5V ↔ 6 GND 8 GPIO14 UART TX 10 GPIO15 UART RX 12 GPIO18 PWM0 PCM CLK SPI1 CE0 14 GND 16 GPIO23 18 GPIO24 20 GND 22 GPIO25 24 GPIO8 SPI0 CE0 26 GPIO7 SPI0 CE1 28 GPIO1 ID_SC 30 GND 32 GPIO12 PWM0 34 GND 36 GPIO16 SPI1 CE2 38 GPIO20 PCM DIN SPI1 MOSI 40 GPIO21 PCM DOUT SPI1 SCLK GPIO UART I2C SPI PWM I2S (PCM) Power Ground (GND)
Download:PNGSVG
Pin table – Raspberry Pi GPIO (40pin)
PinNameDirectionUARTI2CSPIPWMI2S (PCM)Note
13V3output3.3 V output – only for smaller loads (sensors)
25Vinput/output5 V directly from the Pi's power supply – can also power the Pi (unprotected)
3GPIO2input/outputI2C1 SDAI2C1 SDA; 1.8 kΩ pull-up on the board
45Vinput/output5 V directly from the Pi's power supply – can also power the Pi (unprotected)
5GPIO3input/outputI2C1 SCLI2C1 SCL; 1.8 kΩ pull-up on the board. Shorting to GND turns on a powered-off Pi (Pi 4 and earlier; Pi 5 only via button)
6GND–
7GPIO4input/outputGPCLK0; default 1-Wire pin (dtoverlay=w1-gpio)
8GPIO14input/outputUART TXUART TX – serial console
9GND–
10GPIO15input/outputUART RXUART RX – serial console
11GPIO17input/outputSPI1 CE1
12GPIO18input/outputSPI1 CE0PWM0PCM CLKPWM0; PCM CLK (I2S); SPI1 CE0
13GPIO27input/output
14GND–
15GPIO22input/output
16GPIO23input/output
173V3output3.3 V output – only for smaller loads (sensors)
18GPIO24input/output
19GPIO10input/outputSPI0 MOSI
20GND–
21GPIO9input/outputSPI0 MISO
22GPIO25input/output
23GPIO11input/outputSPI0 SCLK
24GPIO8input/outputSPI0 CE0
25GND–
26GPIO7input/outputSPI0 CE1
27GPIO0input/outputID_SDI2C0 SDA for the HAT EEPROM – do not use
28GPIO1input/outputID_SCI2C0 SCL for the HAT EEPROM – do not use
29GPIO5input/outputGPCLK1
30GND–
31GPIO6input/outputGPCLK2
32GPIO12input/outputPWM0PWM0
33GPIO13input/outputPWM1PWM1
34GND–
35GPIO19input/outputSPI1 MISOPWM1PCM FSPWM1; PCM FS (I2S); SPI1 MISO
36GPIO16input/outputSPI1 CE2
37GPIO26input/output
38GPIO20input/outputSPI1 MOSIPCM DINPCM DIN (I2S); SPI1 MOSI
39GND–
40GPIO21input/outputSPI1 SCLKPCM DOUTPCM DOUT (I2S); SPI1 SCLK

What to watch out for

  • GPIO are not 5V tolerant. 5 V on an input can destroy the Raspberry Pi.
  • The 5V pins are connected directly to the power rail – powering the board through them bypasses the protection, so watch the polarity.
  • Draw only small currents from the 3.3 V pins (sensors); use your own regulator for larger loads.
  • GPIO2/3 (I2C1) have 1.8 kΩ pull-ups on the board – as general-purpose inputs they behave differently from the other pins.
  • Code uses GPIO (BCM) numbers, not the physical pin numbers on the header.

Raspberry Pi projects on chiptron.eu/

Projects and guides on chiptron.eu/:

More pinouts

See all pinouts on the Pinouts page.

Related Articles