Networking / Guide

IP address, subnet mask, gateway: the three settings to understand

What the IP address, the subnet mask and the default gateway mean, how a machine uses them to reach another one, and how to read them on Windows, Linux and macOS.

Networking Guide Beginner Published October 20, 2026 Translated October 27, 2026 10 min read Version française
Network equipment with Ethernet cables plugged in
Photo: Albert Stoynov on Unsplash

In plain words

A machine on a network is like a resident in a town. The IP address is its postal address, the mask says which part of the address names the neighbourhood, and the gateway is the neighbourhood post office: any letter for another neighbourhood is handed to it. Finally, DNS is the directory that turns a name into an address.

Every machine connected to an IPv4 network has at least three settings: an IP address, a subnet mask and a default gateway. Together, they answer two questions: "who am I on this network?" and "which way do I go to reach anywhere else?".

A fourth setting, the DNS server, turns names (example.com) into addresses. It is covered at the end of this guide.

1. The IP address: the machine's identity

An IPv4 address is written as four numbers from 0 to 255 separated by dots: 192.168.1.42. Each number takes one byte, or 8 bits: an address is therefore 32 bits long.

On a given network, two machines cannot share the same address. If that happens, one of them (or both) loses its connection on and off: that is an address conflict.

An IP address is read in two parts:

  • the network part, shared by every machine on the same local network;
  • the host part, specific to each machine.

Where is the boundary between the two? That is the mask's job.

2. The subnet mask: the boundary

The mask says how many bits, counting from the left, belong to the network part. The most common mask at home is 255.255.255.0:

1st octet 2nd octet 3rd octet 4th octet
Address 192.168.1.42 192 168 1 42
Mask 255.255.255.0 255 255 255 0
Result network network network host

The first three octets identify the network (192.168.1), the last one identifies the machine (42). Every machine in 192.168.1.x is therefore on the same local network.

In binary, 255 is written 11111111: the mask 255.255.255.0 lines up 24 bits set to 1, then 8 bits set to 0. Hence its short form, CIDR notation: 192.168.1.42/24. Both forms say exactly the same thing.

Addresses you cannot give to a machine

In a /24 network, two addresses are reserved:

Address Role
192.168.1.0 The address of the network itself (host part all zeros)
192.168.1.255 The broadcast address: a message sent here reaches every machine on the network
192.168.1.1 to 192.168.1.254 The 254 usable addresses for machines

3. The gateway: the way out

A machine can only talk directly to machines on its own network. For everything else (the internet, another company network), it hands its packets to a router: the default gateway. At home, it is your internet box or router, often at 192.168.1.1 or 192.168.1.254.

Warning

The gateway must always be on the same network as the machine. A machine at 192.168.1.42/24 cannot use a gateway at 192.168.0.1: it has no way to reach it.

4. How a machine decides where to send a packet

This is where the three settings work together. Before sending a packet, the machine applies its mask to its own address and to the destination address (a bitwise logical AND). If both results are identical, the destination is on the same network.

Take the machine 192.168.1.42/24, gateway 192.168.1.1:

Destination Destination AND mask Same network as 192.168.1.0? The packet goes…
192.168.1.50 (a printer) 192.168.1.0 Yes directly to the printer
192.168.2.10 (another network) 192.168.2.0 No to the gateway
1.1.1.1 (a server on the internet) 1.1.1.0 No to the gateway

To deliver a packet on the local network, the machine still needs the physical address (MAC address) of the recipient or of the gateway: it asks for it with the ARP protocol ("who has address 192.168.1.50?"), and keeps the answer in memory for a few minutes.

5. Viewing your settings

Windows

In a terminal (PowerShell or Command Prompt):

ipconfig

Excerpt of the output:

Ethernet adapter Ethernet:
   IPv4 Address. . . . . . . . . . . : 192.168.1.42
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.1.1

ipconfig /all adds the MAC address, the DNS servers and the DHCP status. In PowerShell, Get-NetIPConfiguration shows the same information adapter by adapter.

Linux

ip -4 addr show
ip route

Excerpts:

inet 192.168.1.42/24 brd 192.168.1.255 scope global dynamic enp3s0
default via 192.168.1.1 dev enp3s0 proto dhcp

The first line gives the address and mask in CIDR notation, plus the broadcast address (brd). The default via line gives the gateway. DNS servers are shown with resolvectl status on distributions that use systemd-resolved (Ubuntu in particular).

macOS

networksetup -getinfo Wi-Fi

Result:

DHCP Configuration
IP address: 192.168.1.42
Subnet mask: 255.255.255.0
Router: 192.168.1.1

Replace Wi-Fi with Ethernet for a wired connection (networksetup -listallnetworkservices lists the exact names). DNS servers are shown with scutil --dns.

6. Automatic (DHCP) or static?

Most of the time, these settings are handed out automatically by a DHCP server built into the box. The machine asks for an address at startup and receives the address, mask, gateway and DNS servers for a limited time (the lease).

A server, a NAS or a printer, on the other hand, must always keep the same address, so you can find it. Two methods:

Method How Advantage
DHCP reservation (recommended) In the box or router, you tie the machine's MAC address to an IP address Everything is managed in one place; the machine stays on DHCP
Static address You type the address, mask, gateway and DNS in the machine's settings Works even if the DHCP server is down

Tip

If you set an address by hand, pick it outside the range handed out by DHCP (shown in the box's interface), otherwise DHCP will eventually give it to another machine.

7. The fourth setting: DNS

Machines talk to each other with IP addresses, but we use names. The DNS server does the translation: example.com → an IP address. At home, the box often acts as a DNS relay; you can also set a public resolver or a local DNS server.

Typical symptom of a DNS problem: ping 1.1.1.1 answers, but no website opens by its name. The way to check it is detailed in network troubleshooting: the essential commands.

8. The most common mistakes

Symptom Likely cause What to do
Address in 169.254.x.x The machine got no DHCP answer and gave itself a fallback address (APIPA) Check the cable or Wi-Fi and that DHCP is enabled on the box, then restart the network adapter
Local machines answer, the internet does not Gateway missing, wrong or outside the network Check the gateway with the commands in section 5
The internet works by IP address, not by name DNS missing or unreachable Check the adapter's DNS servers
Random drop-outs, "IP address conflict" message Two machines have the same address Switch one to DHCP or give it an address outside the DHCP range
Some local machines are unreachable Different masks from one machine to another Use the same mask across the whole network

Key takeaways

  • IP address: the machine's identity, unique on the network.
  • Mask: separates the network part from the host part; 255.255.255.0 is also written /24.
  • Gateway: the router that takes packets out of the local network; it is always on the same network as the machine.
  • DNS: turns names into addresses.
  • For a server, prefer a DHCP reservation to an address typed by hand.

Read next