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 PinFunctionBCM GPIOCommon Alternate Function
13.3V PowerPower
25V PowerPower
3GPIOGPIO2I2C1 SDA
45V PowerPower
5GPIOGPIO3I2C1 SCL
6GroundGND
7GPIOGPIO4GPCLK0
8GPIOGPIO14UART0 TXD
9GroundGND
10GPIOGPIO15UART0 RXD
11GPIOGPIO17
12GPIOGPIO18PWM0 / PCM CLK
13GPIOGPIO27
14GroundGND
15GPIOGPIO22
16GPIOGPIO23
173.3V PowerPower
18GPIOGPIO24
19GPIOGPIO10SPI0 MOSI
20GroundGND
21GPIOGPIO9SPI0 MISO
22GPIOGPIO25
23GPIOGPIO11SPI0 SCLK
24GPIOGPIO8SPI0 CE0
25GroundGND
26GPIOGPIO7SPI0 CE1
27ID_SDGPIO0HAT ID I2C SDA
28ID_SCGPIO1HAT ID I2C SCL
29GPIOGPIO5
30GroundGND
31GPIOGPIO6
32GPIOGPIO12PWM0
33GPIOGPIO13PWM1
34GroundGND
35GPIOGPIO19PCM FS / SPI1 MISO
36GPIOGPIO16
37GPIOGPIO26
38GPIOGPIO20PCM DIN / SPI1 MOSI
39GroundGND
40GPIOGPIO21PCM DOUT / SPI1 SCLK

The physical pin assignments and GPIO mappings are based on the official Raspberry Pi 4 Model B documentation.

Important: GPIO0 (physical pin 27) and GPIO1 (physical pin 28) are associated with the HAT identification interface. Raspberry Pi documentation identifies these pins as being reserved for HAT ID EEPROM use, so they should not be treated like ordinary GPIO pins in typical projects.

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:

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:

These pins provide a 3.3V supply for compatible components.

5V power

The 5V supply is available on:

These pins provide the Raspberry Pi's 5V supply.

Ground

Ground connections are available on:

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:

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:

FunctionPhysical PinBCM GPIO
SDA3GPIO2
SCL5GPIO3

The two signals are:

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 FunctionPhysical PinBCM GPIO
MOSI19GPIO10
MISO21GPIO9
SCLK23GPIO11
CE024GPIO8
CE126GPIO7

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 FunctionPhysical PinBCM GPIO
TXD8GPIO14
RXD10GPIO15

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.

Try the Raspberry Pi 4B Simulator →

Explore Raspberry Pi Tutorials →