Skip to main content

Raspberry Pi GPIO Pinout

Raspberry Pi 40-pin header · 40-pin 2.54 mm header

Every 40-pin Pi (2, 3, 4, 5, Zero) puts power, ground and each GPIO on the same pins. Physical pin numbers and BCM GPIO numbers are different schemes — mixing them up is the usual cause of a circuit that does nothing.

Checked against the KiCad library and datasheet on

Raspberry Pi 40-pin header pinout: KiCad footprint Connector_PinHeader_2.54mm:PinHeader_2x20_P2.54mm_Vertical seen from the top, beside the KiCad library symbol Connector:Raspberry_Pi_2_3 with every pin number and name
Left, the 2×20 header footprint: odd pins down one row, even pins down the other, pin 1 the square pad. Right, KiCad's Raspberry Pi symbol, which groups the pins by function and numbers each by its physical position. Exported from the KiCad 9 libraries (Connector:Raspberry_Pi_2_3, Connector_PinHeader_2.54mm:PinHeader_2x20_P2.54mm_Vertical). Open full size

Pin by pin

PinNameFunction
13V33.3 V power from the Pi's regulator
25V5 V power, straight from the supply
3GPIO2I²C1 SDA (1.8 kΩ pull-up on the board)
45V5 V power
5GPIO3I²C1 SCL (1.8 kΩ pull-up on the board)
6GNDGround
7GPIO4GPCLK0; default 1-Wire pin
8GPIO14UART TXD
9GNDGround
10GPIO15UART RXD
11GPIO17General purpose
12GPIO18PWM0, PCM clock
13GPIO27General purpose
14GNDGround
15GPIO22General purpose
16GPIO23General purpose
173V33.3 V power
18GPIO24General purpose
19GPIO10SPI0 MOSI
20GNDGround
21GPIO9SPI0 MISO
22GPIO25General purpose
23GPIO11SPI0 SCLK
24GPIO8SPI0 CE0
25GNDGround
26GPIO7SPI0 CE1
27GPIO0ID_SD: HAT ID EEPROM data. Reserved
28GPIO1ID_SC: HAT ID EEPROM clock. Reserved
29GPIO5GPCLK1
30GNDGround
31GPIO6GPCLK2
32GPIO12PWM0
33GPIO13PWM1
34GNDGround
35GPIO19SPI1 MISO, PWM1, PCM frame sync
36GPIO16SPI1 CE2
37GPIO26General purpose
38GPIO20SPI1 MOSI, PCM data in
39GNDGround
40GPIO21SPI1 SCLK, PCM data out

Things that catch people out

  • GPIO is 3.3 V only. 5 V on any GPIO pin will damage the SoC — there is no tolerance.
  • Pins 3 and 5 already carry 1.8 kΩ pull-ups; do not add your own.
  • Ground is on pins 6, 9, 14, 20, 25, 30, 34 and 39.
  • Pins 27 and 28 belong to a HAT's ID EEPROM. Leave them free unless you are building that EEPROM.
  • The Pi 5 drives the header through its RP1 chip. The pins are the same, but libraries that write the old SoC's registers directly, such as RPi.GPIO, do not work on it; gpiozero (through its lgpio pin factory) and libgpiod do.
  • The PWM channels in the table are the Pi 2, 3, 4 and Zero's. On the Pi 5, GPIO12, 13, 18 and 19 are four separate PWM0 channels, and some other alternate functions differ too.

Putting the Raspberry Pi 40-pin header on a PCB

  • A HAT-sized board is 65 × 56 mm (65 × 56.5 mm with a surface-mount header) with the header along one long edge and four M2.5 holes, drilled 2.75 mm, on a 58 × 49 mm pattern. The original HAT specification has since been superseded by HAT+.
  • Use a 2×20 female header on your board. Pin 1 is the square pad; check that it lands at the corner the Pi's pin 1 does, or the board plugs in mirrored.
  • Drawing power from pins 2 and 4 takes it straight from the Pi's supply. Budget the Pi's own draw before hanging motors or LED strips off them.

Common questions

What is the difference between BCM and physical pin numbers?
Physical numbers count the header's pins 1 to 40. BCM numbers are the GPIO names the software uses. GPIO17 is physical pin 11, for example. Most libraries, gpiozero included, take BCM numbers.
Which Raspberry Pi pins are I²C, SPI and UART?
I²C1 is GPIO2 and GPIO3 (pins 3 and 5). SPI0 is GPIO10, 9 and 11 with chip selects on GPIO8 and GPIO7 (pins 19, 21, 23, 24, 26). The UART is GPIO14 and GPIO15 (pins 8 and 10).
Is the Raspberry Pi 5 GPIO pinout the same as the Pi 4?
Power, ground and every GPIO number sit on the same pins, and I²C1, SPI0 and the UART are where they were. Some alternate functions differ (GPIO12 and GPIO18 are separate PWM channels on the Pi 5), and software needs libraries that support its RP1 I/O chip: gpiozero through lgpio, or libgpiod. RPi.GPIO does not work.

Making a HAT? Describe what sits on top of the 40-pin header and PCBEditor builds the board with the 2x20 header in place.

Design a Pi add-on board →

Sources

Other pinouts