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.
| Pin | Name | Direction | UART | I2C | SPI | PWM | I2S (PCM) | Note |
|---|---|---|---|---|---|---|---|---|
| 1 | 3V3 | output | 3.3 V output – only for smaller loads (sensors) | |||||
| 2 | 5V | input/output | 5 V directly from the Pi's power supply – can also power the Pi (unprotected) | |||||
| 3 | GPIO2 | input/output | I2C1 SDA | I2C1 SDA; 1.8 kΩ pull-up on the board | ||||
| 4 | 5V | input/output | 5 V directly from the Pi's power supply – can also power the Pi (unprotected) | |||||
| 5 | GPIO3 | input/output | I2C1 SCL | I2C1 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) | ||||
| 6 | GND | – | ||||||
| 7 | GPIO4 | input/output | GPCLK0; default 1-Wire pin (dtoverlay=w1-gpio) | |||||
| 8 | GPIO14 | input/output | UART TX | UART TX – serial console | ||||
| 9 | GND | – | ||||||
| 10 | GPIO15 | input/output | UART RX | UART RX – serial console | ||||
| 11 | GPIO17 | input/output | SPI1 CE1 | |||||
| 12 | GPIO18 | input/output | SPI1 CE0 | PWM0 | PCM CLK | PWM0; PCM CLK (I2S); SPI1 CE0 | ||
| 13 | GPIO27 | input/output | ||||||
| 14 | GND | – | ||||||
| 15 | GPIO22 | input/output | ||||||
| 16 | GPIO23 | input/output | ||||||
| 17 | 3V3 | output | 3.3 V output – only for smaller loads (sensors) | |||||
| 18 | GPIO24 | input/output | ||||||
| 19 | GPIO10 | input/output | SPI0 MOSI | |||||
| 20 | GND | – | ||||||
| 21 | GPIO9 | input/output | SPI0 MISO | |||||
| 22 | GPIO25 | input/output | ||||||
| 23 | GPIO11 | input/output | SPI0 SCLK | |||||
| 24 | GPIO8 | input/output | SPI0 CE0 | |||||
| 25 | GND | – | ||||||
| 26 | GPIO7 | input/output | SPI0 CE1 | |||||
| 27 | GPIO0 | input/output | ID_SD | I2C0 SDA for the HAT EEPROM – do not use | ||||
| 28 | GPIO1 | input/output | ID_SC | I2C0 SCL for the HAT EEPROM – do not use | ||||
| 29 | GPIO5 | input/output | GPCLK1 | |||||
| 30 | GND | – | ||||||
| 31 | GPIO6 | input/output | GPCLK2 | |||||
| 32 | GPIO12 | input/output | PWM0 | PWM0 | ||||
| 33 | GPIO13 | input/output | PWM1 | PWM1 | ||||
| 34 | GND | – | ||||||
| 35 | GPIO19 | input/output | SPI1 MISO | PWM1 | PCM FS | PWM1; PCM FS (I2S); SPI1 MISO | ||
| 36 | GPIO16 | input/output | SPI1 CE2 | |||||
| 37 | GPIO26 | input/output | ||||||
| 38 | GPIO20 | input/output | SPI1 MOSI | PCM DIN | PCM DIN (I2S); SPI1 MOSI | |||
| 39 | GND | – | ||||||
| 40 | GPIO21 | input/output | SPI1 SCLK | PCM DOUT | PCM 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/:
- Controlling GPIO from a website – switching Raspberry Pi pins via PHP, Python and MySQL
- Raspberry Shake – a seismograph with geophones built on the Raspberry Pi for the ShakeNet network
More pinouts
See all pinouts on the Pinouts page.