Learn
Raspberry Pi 4B GPIO Pinout: An Interactive Guide
The 40-pin GPIO header
The Raspberry Pi 4 Model B (Raspberry Pi 4B) has a standard 40-pin GPIO header used to connect sensors, LEDs, buttons, displays, motors, and other electronic components.
The header includes 28 GPIO pins available through the BCM2711, along with 3.3V power, 5V power, ground connections, and dedicated identification pins. Several GPIO pins can also be configured for interfaces such as I2C, SPI, and UART.
Understanding the difference between the physical pin number and the BCM GPIO number is important when writing Raspberry Pi programs. The physical number refers to the position of the pin on the 40-pin header, while the BCM number identifies the GPIO controller pin used by software.
Raspberry Pi 4B GPIO Pinout
The table below shows the standard Raspberry Pi 4 Model B 40-pin header.
| Physical Pin | Function | BCM GPIO | Common Alternate Function |
|---|---|---|---|
| 1 | 3.3V Power | — | Power |
| 2 | 5V Power | — | Power |
| 3 | GPIO | GPIO2 | I2C1 SDA |
| 4 | 5V Power | — | Power |
| 5 | GPIO | GPIO3 | I2C1 SCL |
| 6 | Ground | — | GND |
| 7 | GPIO | GPIO4 | GPCLK0 |
| 8 | GPIO | GPIO14 | UART0 TXD |
| 9 | Ground | — | GND |
| 10 | GPIO | GPIO15 | UART0 RXD |
| 11 | GPIO | GPIO17 | — |
| 12 | GPIO | GPIO18 | PWM0 / PCM CLK |
| 13 | GPIO | GPIO27 | — |
| 14 | Ground | — | GND |
| 15 | GPIO | GPIO22 | — |
| 16 | GPIO | GPIO23 | — |
| 17 | 3.3V Power | — | Power |
| 18 | GPIO | GPIO24 | — |
| 19 | GPIO | GPIO10 | SPI0 MOSI |
| 20 | Ground | — | GND |
| 21 | GPIO | GPIO9 | SPI0 MISO |
| 22 | GPIO | GPIO25 | — |
| 23 | GPIO | GPIO11 | SPI0 SCLK |
| 24 | GPIO | GPIO8 | SPI0 CE0 |
| 25 | Ground | — | GND |
| 26 | GPIO | GPIO7 | SPI0 CE1 |
| 27 | ID_SD | GPIO0 | HAT ID I2C SDA |
| 28 | ID_SC | GPIO1 | HAT ID I2C SCL |
| 29 | GPIO | GPIO5 | — |
| 30 | Ground | — | GND |
| 31 | GPIO | GPIO6 | — |
| 32 | GPIO | GPIO12 | PWM0 |
| 33 | GPIO | GPIO13 | PWM1 |
| 34 | Ground | — | GND |
| 35 | GPIO | GPIO19 | PCM FS / SPI1 MISO |
| 36 | GPIO | GPIO16 | — |
| 37 | GPIO | GPIO26 | — |
| 38 | GPIO | GPIO20 | PCM DIN / SPI1 MOSI |
| 39 | Ground | — | GND |
| 40 | GPIO | GPIO21 | PCM DOUT / SPI1 SCLK |
The physical pin assignments and GPIO mappings are based on the official Raspberry Pi 4 Model B documentation.
Physical Pin Number vs. BCM GPIO Number
One of the most common sources of confusion when learning Raspberry Pi programming is that physical pin numbers and GPIO numbers are not the same thing.
For example:
- Physical pin 11 corresponds to GPIO17
- Physical pin 13 corresponds to GPIO27
- Physical pin 15 corresponds to GPIO22
- Physical pin 16 corresponds to GPIO23
- Physical pin 18 corresponds to GPIO24
- Physical pin 22 corresponds to GPIO25
- Physical pin 37 corresponds to GPIO26
The Raspberry Pi software can refer to these pins using the BCM GPIO numbering scheme or, depending on the library and configuration, the physical board numbering scheme.
This distinction is especially important when using Python libraries such as RPi.GPIO.
BCM Numbering and Physical Numbering
With the RPi.GPIO Python library on real hardware, you can select which numbering scheme your program uses: BCM numbering (the GPIO number assigned by the Broadcom SoC) or physical/BOARD numbering (the pin's position on the 40-pin header).
BCM numbering (real hardware)
On a physical Raspberry Pi, BCM numbering looks like this:
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM)GPIO.setup(17, GPIO.OUT)Here, 17 means BCM GPIO17, which is physical pin 11 on the Raspberry Pi 4B.
The ZOLB Raspberry Pi 4B Simulator does not currently support BCM numbering mode. Every example on this site — and every component tutorial in Learn — uses physical/BOARD numbering instead, which the simulator does support fully.
Physical (BOARD) numbering — what the ZOLB simulator uses
You can also use the physical pin numbers on the 40-pin header:
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD)GPIO.setup(11, GPIO.OUT)Here, 11 refers to physical pin 11, which is GPIO17. This is the numbering mode to use in the ZOLB simulator.
Both examples refer to the same physical GPIO connection on real hardware — they just use different numbering systems.
Which numbering system should you use?
On real hardware, the most important thing is to understand which numbering system your code is using and remain consistent throughout your project.
In the ZOLB simulator specifically, always use GPIO.setmode(GPIO.BOARD) with physical pin numbers — BCM mode isn't supported yet. When following a tutorial from elsewhere, check whether its GPIO numbers refer to BCM GPIO numbers or physical pin numbers before wiring anything up.
Raspberry Pi 4B Power Pins
Not every pin on the 40-pin header is a GPIO pin.
The header includes dedicated power and ground connections.
3.3V power
The Raspberry Pi 4B provides 3.3V power on:
- Physical pin 1
- Physical pin 17
These pins provide a 3.3V supply for compatible components.
5V power
The 5V supply is available on:
- Physical pin 2
- Physical pin 4
These pins provide the Raspberry Pi's 5V supply.
Ground
Ground connections are available on:
- Physical pin 6
- Physical pin 9
- Physical pin 14
- Physical pin 20
- Physical pin 25
- Physical pin 30
- Physical pin 34
- Physical pin 39
Ground provides the common electrical reference needed to complete many circuits.
The Raspberry Pi 4 Model B documentation specifies the 3.3V, 5V, and ground positions on the 40-pin header.
Raspberry Pi GPIO Pins
GPIO stands for General-Purpose Input/Output.
A GPIO pin can generally be configured as an input or output, allowing software to interact with electronic components.
GPIO as an output
An output GPIO pin can be driven high or low.
For example, a Python program can use a GPIO output to control an LED:
GPIO.output(17, GPIO.HIGH)The output state can then be changed:
GPIO.output(17, GPIO.LOW)This basic input/output behavior is one of the most important concepts when learning Raspberry Pi GPIO programming. Raspberry Pi documentation describes GPIO outputs as being capable of being set high or low, with high corresponding to approximately 3.3V and low to 0V.
GPIO as an input
GPIO pins can also be configured as inputs.
For example, a button or sensor can provide a signal that your program reads:
GPIO.setup(17, GPIO.IN)Your program can then read the state of the pin:
state = GPIO.input(17)This allows Raspberry Pi projects to respond to buttons, switches, sensors, and other external signals.
Raspberry Pi 4B GPIO Alternate Functions
Many GPIO pins can perform functions other than basic digital input and output.
Depending on the pin and configuration, GPIO pins can be multiplexed for interfaces such as:
- I2C
- SPI
- UART
- PWM
- PCM
- Clock signals
For example:
GPIO2 and GPIO3
are commonly used for I2C1 SDA and SCL.
GPIO7, GPIO8, GPIO9, GPIO10, and GPIO11
are associated with the primary SPI interface.
GPIO14 and GPIO15
are associated with UART0 TXD and RXD.
The BCM2711 provides additional peripheral functions that can be selected through GPIO multiplexing, giving Raspberry Pi 4B projects considerable flexibility when connecting external hardware.
I2C Pins
I2C is commonly used for connecting sensors, displays, ADCs, RTC modules, and other devices that communicate over a two-wire bus.
The commonly used I2C1 pins on the Raspberry Pi 4B are:
| Function | Physical Pin | BCM GPIO |
|---|---|---|
| SDA | 3 | GPIO2 |
| SCL | 5 | GPIO3 |
The two signals are:
- SDA — Serial Data
- SCL — Serial Clock
Multiple I2C devices can share the same bus when they have appropriate addresses.
SPI Pins
SPI is commonly used for devices that require faster synchronous communication.
The primary SPI0 interface commonly uses:
| SPI Function | Physical Pin | BCM GPIO |
|---|---|---|
| MOSI | 19 | GPIO10 |
| MISO | 21 | GPIO9 |
| SCLK | 23 | GPIO11 |
| CE0 | 24 | GPIO8 |
| CE1 | 26 | GPIO7 |
SPI is commonly used with displays, ADCs, memory devices, and other peripherals.
UART Pins
UART provides serial communication between the Raspberry Pi and another device.
The commonly used UART0 pins are:
| UART Function | Physical Pin | BCM GPIO |
|---|---|---|
| TXD | 8 | GPIO14 |
| RXD | 10 | GPIO15 |
UART can be useful when communicating with microcontrollers, serial devices, and other embedded systems.
GPIO Safety
GPIO pins are connected directly to the Raspberry Pi's SoC, so they should be treated carefully.
The Raspberry Pi GPIO interface operates at 3.3V logic. Do not connect a 5V signal directly to a GPIO input unless the circuit has been designed to safely interface the two voltage levels.
When connecting LEDs, use an appropriate current-limiting resistor. When connecting sensors or other modules, check their voltage requirements and electrical specifications before connecting them to the Raspberry Pi.
The GPIO header also includes 5V and 3.3V power pins, which should not be confused with ordinary GPIO signal pins.
Always check the component's documentation before connecting it to a Raspberry Pi.
Raspberry Pi 4B GPIO Pinout in the ZOLB Simulator
You don't need a physical Raspberry Pi 4B to start learning how the GPIO header works.
The ZOLB Raspberry Pi 4B Simulator includes the Raspberry Pi 4B's 40-pin GPIO header so you can experiment with connections directly in your browser.
Hover over the pins on the simulated board to identify their functions, then connect GPIO, power, and ground pins to components and build a circuit.
This makes it possible to learn the relationship between the physical pin number, BCM GPIO number, and circuit behavior before working with physical hardware.
Try the Raspberry Pi 4B GPIO Pinout Yourself
The best way to understand the GPIO header is to use it.
Open the Raspberry Pi 4B Simulator and experiment with GPIO connections directly in your browser.
You can start with a simple LED circuit and then move on to buttons, sensors, and other components as you become more comfortable with Raspberry Pi GPIO programming.
Raspberry Pi 4B GPIO Examples
Once you understand the pinout, try this project:
Blink an LED
Learn how to configure a GPIO pin as an output and control an LED.
Blink an LED on a Raspberry Pi 4B →
Learn Raspberry Pi Without Hardware
If you don't currently own a Raspberry Pi, you can still begin learning Raspberry Pi programming and GPIO concepts using the ZOLB simulator.
Learn Raspberry Pi Without Hardware →
Raspberry Pi 4B GPIO Pinout FAQ
How many pins does the Raspberry Pi 4B have?
The Raspberry Pi 4 Model B has a standard 40-pin GPIO header. The header includes power, ground, GPIO, and identification connections. The Pi 4B makes 28 BCM2711 GPIOs available through this header.
Which pin is GPIO17 on the Raspberry Pi 4B?
GPIO17 is physical pin 11 on the Raspberry Pi 4B 40-pin header.
Which pin is GPIO27?
GPIO27 is physical pin 13.
Which pin is GPIO22?
GPIO22 is physical pin 15.
Which pin is GPIO23?
GPIO23 is physical pin 16.
Which pin is GPIO24?
GPIO24 is physical pin 18.
Which pin is GPIO25?
GPIO25 is physical pin 22.
Which pin is GPIO26?
GPIO26 is physical pin 37.
Which Raspberry Pi 4B pins are 5V?
Physical pins 2 and 4 provide 5V power.
Which Raspberry Pi 4B pins are 3.3V?
Physical pins 1 and 17 provide 3.3V power.
Which Raspberry Pi 4B pins are ground?
Ground is available on physical pins 6, 9, 14, 20, 25, 30, 34, and 39.
What is the difference between BCM and physical pin numbering?
Physical numbering refers to the position of a pin on the 40-pin header. BCM numbering refers to the GPIO number assigned by the Broadcom SoC. For example, physical pin 11 is GPIO17. The ZOLB simulator currently supports physical (BOARD) numbering only.
Can I use the Raspberry Pi 4B GPIO pinout in the ZOLB simulator?
Yes. The ZOLB Raspberry Pi 4B Simulator provides a simulated 40-pin GPIO header that you can use to practice wiring and GPIO programming directly in your browser, using physical (BOARD) pin numbering.
Start Building With Raspberry Pi GPIO
The Raspberry Pi 4B's 40-pin GPIO header gives you a direct way to connect software with the physical world.
Once you understand the pinout, you can begin building projects with LEDs, buttons, sensors, displays, and other electronic components.
If you don't have a Raspberry Pi available yet, start with the ZOLB Raspberry Pi 4B Simulator and practice the same fundamental GPIO concepts in your browser.
Learn the pins. Build the circuit. Write the code. See what happens.