40-pin GPIO header
All current classic single-board computers (SBCs), Zero models, and keyboard computers include a 40-pin general-purpose input/output (GPIO) header, distributed across two rows of 20 pins, with standard 2.54 mm pin pitch. On some Zero models, the GPIO header doesn’t come with pins attached. For more information about these variants, see Zero models.
| Earlier models of classic Raspberry Pi SBCs that are no longer in production had a 26-pin GPIO header. |
The GPIO header is the primary hardware bridge between your Raspberry Pi’s processor and external electronic components. Programs running on your Raspberry Pi use these pins to perform two core actions:
-
Receive input. Read digital states from connected sensors, switches, and buttons.
-
Send output. Transmit electrical signals to control external hardware like LEDs, motors, and displays.
Pin layout
The 40-pin GPIO header is located along the top edge of standard circuit boards (classic SBCs and Zero models) and on the rear of keyboard-integrated models (keyboard computers).
The following figure shows the standard Raspberry Pi pin layout for Raspberry Pi B+ and later, and for all Zero models. On classic SBCs and Zero models, Pin 1 is located in the lower-left corner of the header; pin 40 is located at the diagonally opposite, upper-right corner of the header.
The GPIO header on keyboard computers has an inverted orientation; the header is rotated 180 degrees compared to a standard board layout, but pins 1 and 40 are labelled to help reduce confusion.
| When connecting external hardware to the GPIO header, check the orientation and alignment of the GPIO header before applying power. Incorrect wiring can result in circuit failure, erratic behaviour, permanent thermal or overcurrent damage to connected peripherals, and irreversible electrical damage to your Raspberry Pi device’s SoC. |
GPIO pin labels and positions
Physical pin numbers (1 to 40) don’t match the logical GPIO identifiers used in code. For example, GP17 is physically located at pin 11 on a Raspberry Pi board.
The pin labels in the following figure correspond to the logical GPIO identifiers used in code rather than their sequential physical position on the board. This means that the GPIO pin numbering scheme, represented in yellow, isn’t in numerical order.
GPIO pinout map
Raspberry Pi OS includes the GPIO Zero Python library, which allows you to display a map of the GPIO pins on your Raspberry Pi from the Terminal with the following command:
$ pinout
This command displays a pinout map showing the physical pin positions, logical GPIO identifiers, and pin functions.
Pin types
Each pin is mapped to a specific function categorised into four primary types, summarised in the following table.
| Pin type | Quantity | Labelling | Voltage | Primary purpose |
|---|---|---|---|---|
Power |
4 |
|
3.3 V DC |
Provide power to compatible, low-current peripherals |
Ground |
8 |
|
0 V |
Provide a ground connection (0 volts), used to complete electrical circuits across the header. |
GPIO |
26 |
|
3.3 V logic |
General-purpose digital input and output pins, customisable through software; supports communication protocols (SPI, I2C, UART, PWM, and PCM). |
ID EEPROM |
2 |
|
3.3 V logic |
Reserved for use with Hardware Attached on Top (HAT) boards. |
GPIO pins 0 and 1, sometimes named GPIO 0 (ID_SD) and GPIO 1 (ID_SC), respectively, are reserved for special-purpose use. Physically, these pins correspond with pins 27 and 28 on a Raspberry Pi board.
|
GPIO pin inputs, outputs, and communication protocols
GPIO pins can operate in two modes: inputs and outputs. Some GPIO pins can also control connected components using specific communication protocols, including SPI, I2C, UART, PWM, and PCM.
Inputs
A GPIO pin designated as an input is read as high when connected to 3.3 V, and low when connected to 0 V. Internal pull-up or pull-down resistors help establish a defined input state when no external signal is being applied.
| Raspberry Pi GPIO pins operate at 3.3 V and aren’t 5 V tolerant. Only the 5 V power pins are designed to supply 5 V power. Never apply 5 V directly to a GPIO pin because this can cause permanent damage to your Raspberry Pi’s SoC. |
GP2 (SDA) and GP3 (SCL) have fixed 1.8 kΩ resistors. You can control pull-up or pull-down configuration for other pins through software.
Outputs
A GPIO pin designated as an output can be set to high (3.3 V) or low (0 V) to control connected electronic components.
An individual GPIO pin can supply up to 16 mA to an attached device, and all GPIO pins combined can supply a maximum total current of 50 mA.
| While connecting simple components to GPIO pins is generally safe when wired correctly, take care when connecting electronic components to your Raspberry Pi. For LEDs, use a suitable current-limiting resistor. For motors, use a suitable motor driver, such as an H-bridge or motor controller board; never connect motors directly to GPIO pins. |
Communication protocols (alternative functions)
Some GPIO pins can control connected components using specific communication protocols, including the following:
-
SPI (Serial Peripheral Interface), used to communicate with external SPI devices, such as sensors, displays, and other peripherals.
-
UART (Universal Asynchronous Receiver/Transmitter), used to send and receive serial data with devices such as microcontrollers.
-
PWM (Pulse Width Modulation), used to control the amount of power delivered to devices such as motors and LEDs.
-
PCM (Pulse Code Modulation), used for digital audio input and output.
-
I2C (Inter-Integrated Circuit), used to communicate with external I2C devices, such as sensors, displays, and other peripherals.
Pin functions
The following table summarises the typical functions of each of the pins. Some functions are available on all pins; other functions are available on specific pins.
Most of the GPIO pins in this table have multiple alternative functions. GPIO pins with alternative functions allow peripheral hardware within the SoC to connect to selected GPIO pins instead of using them as general-purpose inputs or outputs. For example, I2C signals can be assigned to different supported GPIO pin locations.
-
For more detailed information about the functions available on the Raspberry Pi 5 family of devices, see Alternative function assignments in the Compute Module 5 datasheet.
-
For more detailed information about the functions available on the Raspberry Pi 4 family of devices, see Alternative function assignments in the Compute Module 4 datasheet.
-
For more detailed information about the functions available on earlier Raspberry Pi families of devices and Raspberry Pi Zero models, see Alternative Function Assignments in the BCM2835 peripherals datasheet.
| Pad control settings, such as output drive strength and Schmitt-trigger filtering, still apply when a pin is configured for an alternative function. |
| Pin | Name | Type | Typical function |
|---|---|---|---|
1 |
|
Power |
Transmits power as output to attached peripherals at 3.3 V |
2 |
|
Power |
Provides 5 V power output to peripherals, or accepts 5 V power input to power a Raspberry Pi (for example, through a PoE+ HAT or third-party HAT) |
3 |
|
GPIO |
Serial Data Line (SDA); transmits data to and from an I2C device; this pin has a 1.8 kΩ on-board pull-up resistor to 3.3 V |
4 |
|
Power |
Provides 5 V power output to peripherals, or accepts 5 V power input to power a Raspberry Pi (for example, through a PoE+ HAT or third-party HAT) |
5 |
|
GPIO |
Serial Clock Line (SCL); provides a clock signal that synchronises communication between your Raspberry Pi and an I2C device; this pin has a 1.8 kΩ on-board pull-up resistor to 3.3 V |
6 |
|
Ground |
Completes an electrical circuit connected to power |
7 |
|
GPIO |
|
8 |
|
GPIO |
Transmit Data (TXD); sends serial (UART) data to a connected device |
9 |
|
Ground |
Completes an electrical circuit connected to power |
10 |
|
GPIO |
Receive Data (RXD); receives serial (UART) data from a connected device |
11 |
|
GPIO |
SPI chip enable ( |
12 |
|
GPIO |
PCM clock or SPI chip enable (CE0) |
13 |
|
GPIO |
|
14 |
|
Ground |
Completes an electrical circuit connected to power |
15 |
|
GPIO |
|
16 |
|
GPIO |
|
17 |
|
Power |
Transmits power as output to attached peripherals at 3.3 V |
18 |
|
GPIO |
|
19 |
|
GPIO |
MOSI; sends data from your Raspberry Pi to a SPI device |
20 |
|
Ground |
Completes an electrical circuit connected to power |
21 |
|
GPIO |
MISO; receives data from a SPI device |
22 |
|
GPIO |
|
23 |
|
GPIO |
Serial clock ( |
24 |
|
GPIO |
SPI chip enable ( |
25 |
|
Ground |
Completes an electrical circuit connected to power |
26 |
|
GPIO |
SPI chip enable ( |
27 |
|
GPIO |
I2C ( |
28 |
|
GPIO |
I2C ( |
29 |
|
GPIO |
|
30 |
|
Ground |
Completes an electrical circuit connected to power |
31 |
|
GPIO |
|
32 |
|
GPIO |
Pulse Width Modulation ( |
33 |
|
GPIO |
Pulse Width Modulation ( |
34 |
|
Ground |
Completes an electrical circuit connected to power |
35 |
|
GPIO |
PCM frame sync ( |
36 |
|
GPIO |
SPI chip enable ( |
37 |
|
GPIO |
|
38 |
|
GPIO |
PCM ( |
39 |
|
Ground |
Completes an electrical circuit connected to power |
40 |
|
GPIO |
PCM ( |
GPIO configuration
This section covers the underlying architecture and low-level configuration of the GPIO hardware.
GPIO permissions
To access GPIO ports, a user must be a member of the appropriate gpio group. The primary user account in Raspberry Pi OS is a member of the gpio group by default. Other users must be added to this group manually using the following command, replacing <username> with the actual username of the user:
$ sudo usermod -a -G gpio <username>
GPIO pads
The external GPIO connections on the SoC are sometimes referred to as 'pads' in the BCM2835 peripherals datasheet. In semiconductor terminology, pads are the chip’s electrical connection points to the outside world.
The GPIO pads include configurable CMOS push-pull output drivers and input buffers. Register-based settings can control the following:
-
Internal pull-up and pull-down resistors (enable or disable).
-
Output drive strength.
-
Input Schmitt-trigger filtering.
Power-on states
Following a power-on reset, GPIO pins are generally configured as inputs. The default pull states are also applied, which are detailed in the Alternative Function Assignments table in the BCM2835 peripherals datasheet. Most GPIOs have a default pull applied.
Interrupts
Each GPIO pin configured as a general-purpose input can be configured as an interrupt source for the Arm processor. The following interrupt-generation modes are available:
-
Level-sensitive interrupts, initiated when the input signal is high or low. These interrupts maintain the interrupted state until the level has been cleared by system software, for example, by servicing the attached peripheral generating the interrupt.
-
Edge-sensitive interrupts, initiated with rising or falling signal transitions. Rising and falling edge detection has some synchronisation built into the detection. At the system clock frequency, the input is sampled, and an interrupt is generated when the transition meets the detection criteria within a three-cycle window. For example,
1, 0, 0(high, low, low) and0, 1, 1(low, high, high) represent qualifying transitions. -
Asynchronous edge detection, which bypasses the synchronisation involved in edge-sensitive interrupts, allowing the hardware to detect narrower input events.
Voltage specifications
There are two 5 V pins and two 3.3 V pins in the 40-pin GPIO header, as well as a number of ground (GND) pins. These pins can’t be reconfigured. The remaining pins are general-purpose 3.3 V pins, high outputs are set to 3.3 V and inputs are 3.3 V-tolerant.
BCM2835, BCM2836, BCM2837, and RP3A0
The following table gives the voltage specifications for the GPIO pins for BCM2835, BCM2836, BCM2837, and RP3A0 products (for example, Raspberry Pi Zero or Raspberry Pi 3B+). For information about Compute Modules, see the relevant Compute Module datasheets.
| Symbol | Parameter | Conditions | Min | Typical | Max | Unit |
|---|---|---|---|---|---|---|
VIL |
Input low voltage |
- |
- |
- |
0.9 |
V |
VIH |
Input high voltagea |
- |
1.6 |
- |
- |
V |
IIL |
Input leakage current |
TA = +85◦C |
- |
- |
5 |
µA |
CIN |
Input capacitance |
- |
- |
5 |
- |
pF |
VOL |
Output low voltageb |
IOL = -2 mA |
- |
- |
0.14 |
V |
VOH |
Output high voltageb |
IOH = 2 mA |
3.0 |
- |
- |
V |
IOL |
Output low currentc |
VO = 0.4 V |
18 |
- |
- |
mA |
IOH |
Output high currentc |
VO = 2.3 V |
17 |
- |
- |
mA |
RPU |
Pullup resistor |
- |
50 |
- |
65 |
kΩ |
RPD |
Pulldown resistor |
- |
50 |
- |
65 |
kΩ |
a Hysteresis enabled
b Default drive strength (8 mA)
c Maximum drive strength (16 mA)
BCM2711 products
The following table gives the voltage specifications for the GPIO pins on BCM2711 products (Raspberry Pi 4 and 400). For information about Compute Module 4, see the relevant Compute Module datasheet.
| Symbol | Parameter | Conditions | Min | Typical | Max | Unit |
|---|---|---|---|---|---|---|
VIL |
Input low voltage |
- |
- |
- |
0.8 |
V |
VIH |
Input high voltagea |
- |
2.0 |
- |
- |
V |
IIL |
Input leakage current |
TA = +85◦C |
- |
- |
10 |
µA |
VOL |
Output low voltageb |
IOL = -4 mA |
- |
- |
0.4 |
V |
VOH |
Output high voltageb |
IOH = 4 mA |
2.6 |
- |
- |
V |
IOL |
Output low currentc |
VO = 0.4 V |
7 |
- |
- |
mA |
IOH |
Output high currentc |
VO = 2.6 V |
7 |
- |
- |
mA |
RPU |
Pullup resistor |
- |
33 |
- |
73 |
kΩ |
RPD |
Pulldown resistor |
- |
33 |
- |
73 |
kΩ |
a Hysteresis enabled
b Default drive strength (4 mA)
c Maximum drive strength (8 mA)
RP1 products
The following table gives the voltage specifications for the GPIO pins on RP1-based products (Raspberry Pi 5, 500, and 500+). For information about Compute Module 5, see the relevant Compute Module datasheet.
| Symbol | Parameter | Conditions | Min | Typical | Max | Unit |
|---|---|---|---|---|---|---|
VIL |
Input low voltage |
- |
0 |
- |
0.8 |
V |
VIH |
Input high voltage |
- |
2.0 |
- |
3.3 |
V |
IIL |
Input leakage current |
- |
- |
- |
3 |
µA |
VOL |
Output low voltage |
- |
- |
- |
0.4 |
V |
VOH |
Output high voltage |
- |
2.9 |
- |
- |
V |
IOL |
Output current |
Drive strength = 2 mA |
6.1 |
9.6 |
13.5 |
mA |
IOL |
Output current |
Drive strength = 4 mA |
9.2 |
14.3 |
20.2 |
mA |
IOL |
Output current |
Drive strength = 8 mA |
15.3 |
23.9 |
33.7 |
mA |
IOL |
Output current |
Drive strength = 12 mA |
18.4 |
28.7 |
40.5 |
mA |
IOH |
Output current |
Drive strength = 2 mA |
4.5 |
6.3 |
8.4 |
mA |
IOH |
Output current |
Drive strength = 4 mA |
6.8 |
9.5 |
12.6 |
mA |
IOH |
Output current |
Drive strength = 8 mA |
11.4 |
15.8 |
21 |
mA |
IOH |
Output current |
Drive strength = 12 mA |
13.6 |
19 |
25.2 |
mA |
RPU |
Pull-up resistor |
- |
37 |
55 |
86 |
kΩ |
RPD |
Pulldown resistor |
- |
35 |
55 |
98 |
kΩ |