binding a socket
Before a shop can take phone orders, it must claim a phone number that customers will dial. Binding a socket is claiming that number. It tells the operating system: this socket should own this particular local address and port, so that traffic arriving for that address-and-port is delivered to me. Without binding, a socket has no fixed local identity that others can aim at.
In code you call bind(fd, address), where the address pairs a local IP (often 0.0.0.0 to mean every network interface, or 127.0.0.1 for loopback only) with a port number. The kernel checks that the port is not already taken in a conflicting way and then reserves it for your socket. Servers almost always bind explicitly, because clients must know in advance where to find them — a web server binds TCP port 443, a DNS server binds UDP port 53. Clients usually do not call bind; when they connect, the OS auto-assigns an ephemeral source port instead, so an explicit bind is unnecessary for them.
Why it matters: bind is the step that turns a blank socket into a reachable endpoint, and it is where you decide your service's reach. Bind to 0.0.0.0 and the whole network can connect; bind to 127.0.0.1 and only the local machine can. Two practical hazards: binding to a privileged port below 1024 typically requires administrator rights, and trying to bind a port another process already holds fails with an 'address already in use' error — famously common just after a server restarts, because the previous connections may still be lingering in the TIME-WAIT state (the SO_REUSEADDR option is the usual cure).
A server does bind(fd, {0.0.0.0, 8080}). From then on, any client on the network connecting to this host's port 8080 is routed to that socket. Had it used {127.0.0.1, 8080}, only programs on the same machine could reach it.
Bind picks both the local interface and the port a server answers on.
'Address already in use' right after a restart usually does not mean another program stole the port — it means your own old connections are in TIME-WAIT. Setting SO_REUSEADDR before bind lets you rebind immediately.