If you are wondering about raspberry pi how to connect to wifi, you are not alone. Getting your single-board computer online is the critical first step for everything from Home Assistant deployments to headless IoT sensors. However, the way you connect to WiFi has fundamentally changed with the release of Raspberry Pi OS Bookworm (Debian 12).

In this beginner guide, we will cover the exact methods to connect your Raspberry Pi 4, Pi 5, and Zero 2 W to your wireless network, including the modern NetworkManager approach, the legacy wpa_supplicant method, and headless configurations.

Why Your Raspberry Pi OS Version Matters for WiFi

Before typing any commands, you must know which OS version you are running. In late 2023, the Raspberry Pi Foundation shifted from Debian 11 (Bullseye) to Debian 12 (Bookworm). This update completely replaced the legacy wpa_supplicant networking daemon with NetworkManager. If you follow older tutorials telling you to edit /etc/wpa_supplicant/wpa_supplicant.conf on a modern Pi 5 or Pi 4 running Bookworm, your WiFi simply will not connect.

Method 1: The Desktop GUI Approach (Easiest)

If you are running Raspberry Pi OS with the official desktop environment and have a monitor and mouse connected, the GUI method is identical to connecting a smartphone or laptop.

  1. Locate the Network Icon (two arrows or a WiFi symbol) in the top-right system tray.
  2. Click the icon to reveal a dropdown list of available wireless networks.
  3. Select your target SSID.
  4. Enter your WPA2/WPA3 password when prompted and click OK.

Once connected, the icon will change to display signal strength bars. Hovering over it reveals your assigned local IP address (e.g., 192.168.1.45), which you will need for SSH access.

Method 2: Headless Setup via Raspberry Pi Imager

For headless projects (no monitor or keyboard), the most reliable way to configure WiFi is before you even flash the SD card. The official Raspberry Pi Imager includes a hidden advanced settings menu.

  1. Open Raspberry Pi Imager and select your device (e.g., Raspberry Pi 5) and OS.
  2. Press Ctrl+Shift+X (Windows/Linux) or Cmd+Shift+X (macOS) to open the OS Customisation overlay. Alternatively, click the gear icon if prompted.
  3. Check the box for Configure Wireless LAN.
  4. Enter your exact SSID and Password.
  5. Critical Step: Set the correct Wireless LAN Country. Failing to set the country code (e.g., US, GB, DE) will prevent the Pi from broadcasting on 5GHz channels due to local regulatory domain restrictions.

Flash the SD card, insert it into your Pi, and boot. The Pi will automatically connect to your router on the first startup.

Method 3: Command Line WiFi Setup (Bookworm OS)

If you are already booted into a headless Raspberry Pi OS Bookworm terminal (perhaps via Ethernet or a serial console), you must use nmcli (NetworkManager Command-Line Interface).

First, scan for available networks:

sudo nmcli dev wifi list

This outputs a table of SSIDs, signal strengths, and security types. To connect, use the following syntax:

sudo nmcli dev wifi connect "YOUR_SSID" password "YOUR_PASSWORD"

If your network is a hidden SSID, append the hidden yes flag:

sudo nmcli dev wifi connect "HiddenNetwork" password "SecretPass" hidden yes

You can verify your connection status and retrieve your IP address by typing:

nmcli connection show

Method 4: Legacy wpa_supplicant (Bullseye and Older)

If you are maintaining an older fleet of Pi 3B+ or Pi 4 devices running Raspberry Pi OS Bullseye or Buster, NetworkManager is not present. You must use the wpa_supplicant configuration file.

Open the terminal and edit the file:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Add the following block at the bottom:

country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="YourNetworkName"
    psk="YourNetworkPassword"
    key_mgmt=WPA-PSK
}

Save the file (Ctrl+O, Enter, Ctrl+X) and reboot the Pi. For a deep dive into legacy networking configurations, refer to the official Raspberry Pi networking documentation.

Raspberry Pi WiFi Hardware & Frequency Comparison

Not all Raspberry Pi models have the same wireless capabilities. Understanding your board's physical WiFi chip limitations is crucial for smart home and IoT deployments.

ModelWiFi Standard2.4 GHz5 GHzBluetooth
Raspberry Pi 5802.11ac (Wi-Fi 5)YesYes5.0 / BLE
Raspberry Pi 4B802.11ac (Wi-Fi 5)YesYes5.0 / BLE
Raspberry Pi 3B+802.11ac (Wi-Fi 5)YesYes4.2 / BLE
Raspberry Pi Zero 2 W802.11n (Wi-Fi 4)YesNo4.1 / BLE
Raspberry Pi Zero W802.11n (Wi-Fi 4)YesNo4.1 / BLE

Note: If you are deploying a Pi Zero 2 W in a crowded RF environment, you are restricted to the 2.4GHz band, which may suffer from microwave and Bluetooth interference.

Assigning a Static IP via NetworkManager

For servers like Home Assistant or Pi-hole, a dynamic IP assigned via DHCP is unreliable. In Bookworm OS, you assign a static IP using nmcli. Assuming your connection is named MyWiFi and your gateway is 192.168.1.1:

sudo nmcli con mod "MyWiFi" ipv4.addresses 192.168.1.50/24
sudo nmcli con mod "MyWiFi" ipv4.gateway 192.168.1.1
sudo nmcli con mod "MyWiFi" ipv4.dns "1.1.1.1,8.8.8.8"
sudo nmcli con mod "MyWiFi" ipv4.method manual
sudo nmcli con up "MyWiFi"

This guarantees your Pi will always boot with the IP 192.168.1.50, making SSH and web-dashboard access predictable.

Troubleshooting Common WiFi Connection Failures

Even with the correct commands, RF environments and hardware quirks can block your connection. Here is how to diagnose the most common issues.

1. The 5GHz Country Code Block

If your Pi connects to 2.4GHz but refuses to see your 5GHz SSID, your regulatory domain is likely unset or incorrect. The WiFi chip firmware disables 5GHz channels (specifically DFS channels) until a valid country code is provided. Use sudo raspi-config, navigate to Localisation Options > WLAN Country, and select your exact region.

2. Power Supply Brownouts

The WiFi/Bluetooth combo chip on the Pi 4 and Pi 5 draws sudden current spikes during transmission. If you are using a cheap third-party USB-C power supply, the voltage may dip below 4.8V, causing the kernel to throttle the CPU and drop the WiFi interface. Always use the official Raspberry Pi power supply to ensure stable 5V/3A (Pi 4) or 5V/5A (Pi 5) delivery.

3. WPA3 Enterprise and EAP Limitations

While standard WPA2/WPA3-Personal works out of the box, connecting to enterprise networks (like university or corporate WPA2-Enterprise with PEAP/MSCHAPv2) requires generating specific NetworkManager keyfiles or utilizing the nmtui (NetworkManager Text User Interface) tool to properly configure the CA certificate and inner authentication phase.

Pro Tip: If you completely lock yourself out of a headless Pi by misconfiguring the WiFi, remove the SD card, insert it into your PC, and create an empty file named ssh (no extension) in the boot partition, alongside a corrected userconf.txt or Imager configuration to force a network retry on next boot.

Mastering these connection methods ensures your Raspberry Pi remains a reliable, always-on node in your electronics and smart home ecosystem.