IP Address, Subnet Mask, Gateway & MAC Address Explained

2024/01/03 2026/05/16
IP Address, Subnet Mask, Gateway & MAC Address Explained

Every device on a network needs four things configured correctly to communicate: an IP address to identify itself, a subnet mask to determine which devices are local, a gateway to reach remote networks, and a MAC address for physical delivery on the local segment. Understanding how these four networking fundamentals work together is the key to troubleshooting connectivity issues, configuring static IPs, and grasping how packets traverse the internet.

The Four Networking Fundamentals

Before diving into each concept individually, here is the big picture. These four elements work at different layers of the networking stack but cooperate on every single packet your computer sends:

ConceptOSI LayerScopePurpose
MAC AddressLayer 2 (Data Link)Local network (LAN)Identify physical devices
IP AddressLayer 3 (Network)Across networksLogical addressing and routing
Subnet MaskLayer 3 (Network)Used with IPDetermine if destination is local or remote
GatewayLayer 3 (Network)Network boundaryForward packets to other networks

Think of it like mailing a letter: the IP address is the full street address, the subnet mask tells the post office whether the destination is in the same city, the gateway is the post office that forwards letters to other cities, and the MAC address is the name on the mailbox for final delivery.

MAC Address: Your Device’s Hardware ID

A MAC address (Media Access Control Address) is a unique identifier burned into every network interface card (NIC) at the factory. You can think of it as your network card’s serial number – no two cards in the world should share the same MAC address.

Format

A MAC address is a 48-bit value, typically written as six pairs of hexadecimal digits:

aa:bb:cc:11:22:33

The six pairs split into two halves:

  • First three pairs (OUI): The Organizationally Unique Identifier assigned to the manufacturer by IEEE. For example, 00:1A:2B might identify a specific vendor.
  • Last three pairs: A serial number assigned by the manufacturer, ensuring uniqueness across all their devices.

By looking up the first three pairs, you can identify which company manufactured the network card.

Why MAC Matters

MAC addresses operate at Layer 2 (the Data Link layer). When two devices on the same local network need to communicate, the actual frame delivery relies on MAC addresses, not IP addresses. The switch in your network uses MAC addresses to forward frames to the correct port.

Can You Change a MAC Address?

Although MAC addresses are hardware-burned, most operating systems allow you to override them in software (called MAC spoofing). This is useful in specific scenarios like bypassing MAC filters, but it is not something you need to do under normal circumstances.

IP Address: Logical Network Address

An IP address (Internet Protocol Address) is a logical address assigned to a device by the network environment – either dynamically via DHCP or manually as a static configuration. Unlike a MAC address which is fixed to hardware, an IP address can change when you move to a different network.

IP addresses operate at Layer 3 (the Network layer) and enable routing across different networks. If MAC addresses handle “which room in this building,” IP addresses handle “which building in which city.”

IPv4 vs IPv6

IPv4:

  • 32-bit, written as four decimal octets: 192.168.1.100
  • Maximum ~4.3 billion addresses (2^32), nearly exhausted
  • Still the dominant version on most networks

IPv6:

  • 128-bit, written as eight groups of four hex digits: 2001:0db8:85a3:0000:0000:8a2e:0370:7334
  • Virtually unlimited address space (2^128)
  • Gradually being adopted, but IPv4 remains prevalent in internal networks

This article focuses on IPv4.

Subnet Mask: Same Network or Different?

A subnet mask is a 32-bit value paired with an IP address that determines whether a destination IP is on the same subnet (local network) or a different subnet (requiring a gateway).

Think of it like a zip code: if two addresses share the same zip code, the local carrier delivers directly. If the zip codes differ, the mail goes to a sorting facility (the gateway) for forwarding.

How the Subnet Mask Works

The subnet mask uses a bitwise AND operation to extract the network portion of an IP address. With the most common subnet mask 255.255.255.0:

IP Address:    192.168.1.100
               11000000.10101000.00000001.01100100  (binary)

Subnet Mask:   255.255.255.0
               11111111.11111111.11111111.00000000  (binary)

AND Result (Network Address):
               11000000.10101000.00000001.00000000
               = 192.168.1.0

The decision logic:

  • If two IPs produce the same network address after ANDing with the subnet mask, they are on the same subnet. The device sends the packet directly using ARP.
  • If the network addresses differ, the destination is on another subnet. The device sends the packet to the default gateway.

Common Subnet Masks

Subnet MaskCIDR NotationUsable Hosts
255.255.255.0/24254
255.255.0.0/1665,534
255.0.0.0/816,777,214
255.255.255.128/25126
255.255.255.192/2662

CIDR Notation

CIDR (Classless Inter-Domain Routing) is a shorthand that appends the number of network bits after the IP address:

  • 192.168.1.100/24 means IP 192.168.1.100 with subnet mask 255.255.255.0
  • /24 means the first 24 bits are the network portion, and the remaining 8 bits identify hosts

Modern Linux tools like ip addr display addresses in CIDR notation by default.

Default Gateway: The Door to Other Networks

A default gateway is a device (typically a router) responsible for forwarding packets between different subnets. When your computer determines that the destination IP is not on the same subnet, it sends the packet to the gateway IP, which then routes it toward the destination.

In a home network, the gateway is usually your Wi-Fi router, commonly assigned an IP like 192.168.1.1 or 192.168.0.1.

The Routing Decision

When your computer needs to send a packet, it follows these steps:

  1. Check the subnet: Compute the network address of your IP and the destination IP using the subnet mask. Are they the same?
  2. Same subnet: Use ARP to resolve the destination’s MAC address and send the frame directly on the local network.
  3. Different subnet: Send the packet to the default gateway. The gateway consults its routing table to determine the next hop.

Without a properly configured gateway, your device can communicate with local machines but cannot reach any external network, including the internet.

How They Work Together (Packet Flow)

Let us trace a real-world example. Your computer (192.168.1.100/24) wants to connect to a web server at 142.250.185.78 (Google):

Step 1 – Subnet Check: Your computer applies the subnet mask 255.255.255.0. Your network address is 192.168.1.0. Google’s network address is 142.250.185.0. They differ, so this is a cross-network communication.

Step 2 – Send to Gateway: Your computer looks up the default gateway (192.168.1.1) in the routing table. It uses ARP to find the gateway’s MAC address, sets the destination MAC in the Ethernet frame to the router’s MAC, and sends the frame.

Step 3 – Router Forwards: The router receives the frame, strips the Layer 2 header, and examines the destination IP. It performs NAT (translating your private IP 192.168.1.100 to its public IP), then forwards the packet toward the ISP.

Step 4 – Internet Routing: The packet traverses multiple routers (hops) across the internet, each one consulting its routing table to determine the next hop, until it reaches Google’s server.

Step 5 – Response Returns: Google’s response packet routes back through the internet to your router’s public IP. The router performs reverse NAT, translating the destination back to 192.168.1.100, and delivers the frame to your computer using your MAC address.

Throughout this entire process, the IP addresses (source and destination) remain constant, but the MAC addresses change at every hop – each router rewrites the Layer 2 header for the next physical segment.

Commands to Check Your Network Settings

# Show all interfaces with IP and MAC
ip addr show

# Example output for eth0:
# 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 ...
#     link/ether aa:bb:cc:11:22:33 brd ff:ff:ff:ff:ff:ff   <- MAC Address
#     inet 192.168.1.100/24 brd 192.168.1.255 scope global <- IP / Subnet Mask
#     inet6 fe80::a8bb:ccff:fe11:2233/64 scope link        <- IPv6 link-local

# Show routing table (includes gateway)
ip route show

# Example output:
# default via 192.168.1.1 dev eth0    <- Default Gateway
# 192.168.1.0/24 dev eth0 scope link  <- Local subnet (no gateway needed)

Linux / macOS (ifconfig – legacy)

# Show network interface details
ifconfig

# macOS specific (Wi-Fi interface):
ifconfig en0

# Example output:
# en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
#     ether aa:bb:cc:11:22:33              <- MAC Address
#     inet 192.168.1.100 netmask 0xffffff00 broadcast 192.168.1.255  <- IP / Subnet Mask

macOS (gateway)

# Show default gateway on macOS
netstat -nr | grep default

# Example output:
# default    192.168.1.1    UGScg    en0

Windows (ipconfig)

ipconfig /all

Example output:

Ethernet adapter Ethernet:
   Physical Address. . . . . . . . . : AA-BB-CC-11-22-33   <- MAC Address
   IPv4 Address. . . . . . . . . . . : 192.168.1.100       <- IP Address
   Subnet Mask . . . . . . . . . . . : 255.255.255.0       <- Subnet Mask
   Default Gateway . . . . . . . . . : 192.168.1.1         <- Gateway

Check Your Public IP

curl ifconfig.me
# or
curl ipinfo.io/ip

Your public IP is the address your ISP assigns to your router’s WAN interface – this is the IP the rest of the internet sees.

Private vs Public IP Addresses

Private IP Ranges (RFC 1918)

Private IPs are reserved for use within local area networks and cannot be routed on the public internet. The Internet Assigned Numbers Authority (IANA) reserves three ranges:

RangeCIDRTypical Use
10.0.0.010.255.255.25510.0.0.0/8Large enterprise networks
172.16.0.0172.31.255.255172.16.0.0/12Medium-sized networks
192.168.0.0192.168.255.255192.168.0.0/16Home and small office networks

When you see 192.168.1.100 on your machine, that is a private IP assigned by your router’s DHCP server.

Public IP Addresses

A public IP is assigned by your ISP and is globally unique on the internet. It identifies your network connection to the outside world. You can check yours with curl ifconfig.me.

NAT: Bridging Private and Public

Since private IPs cannot travel on the internet, your router uses NAT (Network Address Translation) to convert outgoing packets from your private IP to its public IP. When responses return, NAT reverses the translation. This allows dozens of devices in your home to share a single public IP address.

Why Private IPs Exist

IPv4 only provides about 4.3 billion addresses – far fewer than the number of connected devices worldwide. Private IP ranges allow unlimited reuse within local networks, dramatically extending the usable address space until IPv6 fully replaces IPv4.


Summary

These four networking fundamentals form the foundation of all IP-based communication:

  • MAC Address – identifies the physical device on the local segment
  • IP Address – provides the logical address for end-to-end routing
  • Subnet Mask – determines whether the destination is local or remote
  • Gateway – forwards packets to other networks when the destination is not local

Every time you open a web browser, send an email, or stream a video, these four components work together seamlessly. Understanding them makes network troubleshooting far more intuitive – when connectivity fails, you can systematically check: Is my IP correct? Is my subnet mask right? Can I ping the gateway? Is the gateway routing correctly?

Further reading:

B
BenZ Software Developer

Software developer passionate about technology. Sharing programming experiences and learning notes.