DEV Community

Cover image for Why Port 8080 and Not 80? A Beginner’s Tale in Go
Margaret Apiyo
Margaret Apiyo

Posted on

Why Port 8080 and Not 80? A Beginner’s Tale in Go

****I

recently started my coding journey with Go. If you’re a beginner looking for a language that is simple yet incredibly powerful, I can’t recommend Go enough.

While building my first Go HTTP web server, I hit a point of curiosity. I learned that a server must "listen" on a specific port number, but I kept seeing 8080 in every tutorial instead of the standard 80.

I did some digging, and here is what I found.

What exactly is a Port?

Think of an IP address as the building address and a Port as the specific door (entry point). The port number decides which software gets the request. When a server "listens" on a port, it means the software is standing behind that door, waiting for someone to knock.

The "Conflict" Rule

On your local machine, only one process can bind to a specific port at a time.
If you have Apache, Nginx, or another system service already listening on Port 80, your Go application will crash on startup. The OS will essentially tell you: "That door is already taken!" By using 8080, you avoid crashing into the main web services already running on your machine.

The "Root" Problem (Privileged Ports)

There is a second reason beginners use 8080 that is even more important: Permissions.
In Unix-like operating systems (Linux and macOS), ports numbered 1 to 1023 are considered "Privileged Ports."
Port 80 requires administrative (root) privileges to run.
Port 8080 is an unprivileged port.

Think of it like this:
Door 80: Imagine this door has a "Security Clearance Required" sign. Only the "System Admin" (Root/Sudo) has the key.
Door 8080: This is an open side entrance. Any developer (standard user) can walk through it and set up shop.

As a developer, you don't want to run your Go binary with sudo every time you test a change. Using 8080 allows you to run your code as a normal user, making your development workflow much smoother and safer.

Why the number 8080?

You might wonder: “Why not 1234 or 9999?”
Technically, you could! However, 8080 became the industry standard because it literally looks like "two 80s." It’s the universal signal to other developers saying: "This is a web server, but it's for development/alternative use."

A Quick Example in Go
In case you’re wondering how this looks in code, here is how we "listen" on 8080 in Go:

package main

import (
    "fmt"
    "net/http"
)

func main() {
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintf(w, "Hello! You've reached the Go server on port 8080.")
    })

    fmt.Println("Server starting on :8080...")
    // We use :8080 to avoid permission issues and port conflicts
    http.ListenAndServe(":8080", nil)
}
Enter fullscreen mode Exit fullscreen mode

Summary

Port 80: The default for HTTP. Requires "Root" permissions.

Port 8080: The "Alternative" to 80. Easy to use for development without special permissions.

Understanding these small "why" questions makes the coding journey so much more rewarding. If you're just starting with Go like me, keep questioning the default`


`

Top comments (0)