What is an IP address?
IP stands for Internet Protocol, the set of rules for addressing and routing data across networks. An IP address works like a postal address for data. When you load a web page, your device sends a request stamped with the server's address and its own, and the server sends the page back to the address on the request.
What does an IP address look like?
There are two versions in use today, and they look very different.
- IPv4, from RFC 791 in 1981: four numbers from 0 to 255 separated by dots, like
203.0.113.45. This is called dotted decimal. - IPv6, the newer version: eight groups of four hexadecimal digits separated by colons, like
2001:0db8:0a0b:0000:0000:0000:0000:0001, usually shortened to2001:db8:a0b::1.
The example addresses on this page come from blocks set aside for documentation, such as 203.0.113.0 to 203.0.113.255 in RFC 5737, so none of them belongs to a real device.
How does an IP address work?
Data travels across the internet in small chunks called packets. Each packet starts with a header holding the source and destination IP addresses. Routers, the devices that join networks together, read the destination address and pass the packet one step closer to it. Your packet might cross ten or more routers on the way, and none of them needs to know the whole route, only the next step.
Network part and host part
Routers can do this quickly because an IP address has two parts. The first part names the network, like the street in a postal address. The rest names the host, the device on that network, like the house number. A prefix such as /24 says how many of the 32 bits belong to the network.
Take 192.168.1.37/24. The first 24 bits, 192.168.1, are the network, and the last 8 bits, 37, are the host. Every device on that network shares the 192.168.1 part. Routers only need to know where each network is, not every single device, which is what lets the system grow to billions of devices. The same split is often written as a subnet mask, here 255.255.255.0.
How your device gets an IP address
You rarely type an IP address in. When your phone joins a Wi-Fi network, it asks for one using DHCP, the Dynamic Host Configuration Protocol from RFC 2131. The router, acting as a DHCP server, lends it a free address for a set time, called a lease, along with the router's own address and a DNS server to use. When the lease runs out, the device renews it or gets a new one.
From names to numbers: DNS
People remember names, and computers route by numbers. The Domain Name System (DNS) connects the two. When you type a web address, your device asks a DNS server for that name's IP address, then connects to the number it gets back. Our IP Addressing and Protocols course walks through a DNS lookup step by step, along with DHCP, subnet masks and ports.
IPv4 addresses in binary
Computers don't see the dots. An IPv4 address is really one 32-bit binary number, and the dotted decimal form is a human-friendly way to write it. The 32 bits are split into four groups of 8, called octets. Eight bits can make 256 patterns, from 00000000 to 11111111, which is why each number runs from 0 to 255.
| Octet | Binary | Place values with a 1 |
|---|---|---|
| 203 | 11001011 | 128 + 64 + 8 + 2 + 1 |
| 0 | 00000000 | None |
| 113 | 01110001 | 64 + 32 + 16 + 1 |
| 45 | 00101101 | 32 + 8 + 4 + 1 |
To turn an octet into binary, start at the place value 128 and work down, halving each time until you reach 1. Write a 1 for each one you can take away from what is left, and a 0 for each you can't. For 203: take 128 (75 left), take 64 (11 left), skip 32 and 16, take 8 (3 left), skip 4, take 2 (1 left), take 1. That gives 11001011. Check by adding the places with a 1: 128 + 64 + 8 + 2 + 1 = 203.
Dotted decimal: 203 .0 .113 .45
Binary: 11001011.00000000.01110001.00101101Every octet is written with all 8 bits, so 0 is 00000000, not just 0. Thirty-two bits allow 232 = 4,294,967,296 different IPv4 addresses, about 4.3 billion.
Now try one. Turn an octet from binary to decimal, or from decimal to 8 bits, then press Mark to check it in the course.
Turn one octet of an address from binary to decimal, or decimal to 8 bits.
Press Mark to have your answer marked in the IP Addressing & Protocols course.
IPv4 vs IPv6
About 4.3 billion sounded like plenty in 1981. Today there are more than 8 billion people, many with a phone, a laptop and other connected devices, so there are far fewer IPv4 addresses than devices. The central pool of spare IPv4 addresses ran out on 3 February 2011, when the last blocks were handed to the five regional internet registries. IPv6 was designed to fix this for good.
| IPv4 | IPv6 | |
|---|---|---|
| Length | 32 bits | 128 bits |
| Written as | Four decimal numbers with dots | Eight groups of hexadecimal with colons |
| Example | 203.0.113.45 | 2001:db8:a0b::1 |
| Number of addresses | 2^32, about 4.3 billion | 2^128, about 3.4 × 10^38 |
| Sharing addresses | Very common, through NAT | Rarely needed: every device can have its own |
| Getting an address | Usually DHCP | Often self-made from the network prefix (SLAAC), or DHCPv6 |
2128 is about 340 undecillion, or 340 followed by 36 zeros. A single standard IPv6 home network, a /64, has 264 addresses: about 18 billion billion, over four billion times the whole IPv4 internet. IPv6 is defined in RFC 8200. Big networks switched it on for good at World IPv6 Launch on 6 June 2012, and today most devices use both: IPv6 where the other end supports it and IPv4 everywhere else.
How to shorten an IPv6 address
Full IPv6 addresses are long, so RFC 5952 sets two rules for writing them shorter:
- Drop the leading zeros in each group, so
0db8becomesdb8and0000becomes0. - Replace the longest run of all-zero groups with
::. You can only do this once in an address, or nobody could tell how many zeros each::stood for.
Full: 2001:0db8:0a0b:0000:0000:0000:0000:0001
Rule 1: 2001:db8:a0b:0:0:0:0:1
Rule 2: 2001:db8:a0b::1To expand one, count the groups you can see (here 4), and the :: stands for the missing ones: 8 − 4 = 4 groups of zeros.
Public vs private IP addresses
Look up your phone's IP address and then search "what is my IP address", and you will usually see two different numbers. That is because your home uses two kinds of address.
- A public IP address is unique on the whole internet. Your internet service provider (ISP) gives one to your router, and it is the address websites see.
- A private IP address only works inside your own network. Your router hands these out to your phone, laptop and TV, and the same private addresses are reused in millions of other homes.
RFC 1918 sets aside three IPv4 ranges for private networks. Routers on the internet won't forward packets addressed to them.
| Private range | Prefix | Addresses | Often seen in |
|---|---|---|---|
| 10.0.0.0 to 10.255.255.255 | 10.0.0.0/8 | 16,777,216 | Large company networks, some home routers |
| 172.16.0.0 to 172.31.255.255 | 172.16.0.0/12 | 1,048,576 | Company networks, containers |
| 192.168.0.0 to 192.168.255.255 | 192.168.0.0/16 | 65,536 | Most home routers |
How NAT lets a whole house share one address
If your laptop is 192.168.1.20, how does a reply from a website find it? Your router uses network address translation (NAT). When the laptop sends a request, the router swaps the private source address for its public one, notes the swap in a table, and sends it on. When the reply comes back, the router looks up the table and passes it to the laptop. Six devices in a house can browse at once while the internet sees just one address.
NAT is what has kept IPv4 going. Many mobile networks and some broadband providers go a step further and put a whole neighbourhood of customers behind a shared address, called carrier-grade NAT. RFC 6598 reserves 100.64.0.0 to 100.127.255.255 for this, so if your router reports a public address starting 100.64 to 100.127, you are probably behind one.
Special IP addresses worth knowing
| Address | What it means |
|---|---|
| 127.0.0.1 | Localhost: the device talking to itself. In IPv6 it is ::1 |
| 192.168.1.1, 192.168.0.1 or 10.0.0.1 | A common address for the home router itself, often called the default gateway |
| 169.254.x.x | A self-assigned address. The device asked for an address and got no reply, so something is wrong with the network or router |
| 0.0.0.0 | No particular address. A server set to listen on it accepts connections on all its addresses |
| 255.255.255.255 | Broadcast: a packet to every device on the local network |
The 169.254 range comes from RFC 3927. If a laptop shows one of these, it can still reach devices that also have one, but it won't reach the internet. Restarting the router or reconnecting usually gets a proper address from DHCP.
What is a static IP address?
A static IP address stays the same until someone changes it. A dynamic IP address is lent out by DHCP and can change, for example when a lease ends or a router restarts.
- Most homes have a dynamic public address. It often stays the same for weeks or months, but your ISP can change it.
- Servers need static addresses, so DNS records pointing at them stay correct. ISPs sell static public addresses, usually to businesses.
- At home, you can fix a private address for one device, like a printer, by setting a DHCP reservation in the router so that device always gets the same number.
How to find your IP address
First decide which address you want. Your device's settings show its private address on your network. Websites see your public address, which belongs to your router or your mobile network.
| Device | Where to find its own (private) address |
|---|---|
| Windows | Settings, Network and internet, then your Wi-Fi or Ethernet connection's properties. Or type ipconfig in Command Prompt |
| Mac | System Settings, Wi-Fi, then Details next to your network |
| iPhone and iPad | Settings, Wi-Fi, then the i button next to your network |
| Android | Settings, Network and internet (or Connections), then tap your Wi-Fi network. Menu names vary by maker |
| Linux | Type ip addr in a terminal |
To find your public IP address, search "what is my IP address" in a search engine, or open your router's status page. Every device on the same home network shows the same public address. On mobile data, your phone gets a different one from the mobile network, often shared with other customers.
What can someone tell from your IP address?
Less than many people fear, but more than nothing. Address blocks are registered to organisations, so anyone can look up which ISP or company an address belongs to. Location databases then guess where that block is used. The guess is usually right about the country, often roughly right about the region or city, and sometimes wrong, especially on mobile data. An IP address doesn't reveal your name or street address. Your ISP knows which customer had an address at a given time, and in many countries the police can ask for that with the right legal order.
- Can someone hack you with your IP address? Not on its own. It tells an attacker where to send traffic, so they can scan for open services or flood your connection to knock it offline. Home routers block unrequested incoming connections by default. Keep your router's software updated and don't open ports you don't need.
- Does a VPN hide your IP address? From websites, yes. They see the VPN server's address instead of yours. The VPN company can see your real address, so you are trusting it instead of your ISP.
How to change your IP address
- Your public address: restarting your router sometimes gets a new one from your ISP, but often you keep the same one. A VPN shows websites a different address straight away, and switching between Wi-Fi and mobile data changes it too.
- Your private address: reconnecting to the network or renewing the DHCP lease can give a new one. You can also set one by hand in the device's network settings, but pick an address outside the range the router hands out, or two devices may clash.
Worked examples
Example 1: is it a private address?
Which of these are private: 172.20.5.4, 172.32.0.1 and 192.169.1.1?
- 172.20.5.4 is private. The 172 range runs from 172.16 to 172.31, and 20 is between them.
- 172.32.0.1 is public. 32 is just past the end of the range.
- 192.169.1.1 is public. Only 192.168 is private, not 192.169.
Example 2: same network or not?
A laptop is 192.168.1.37/24 and a printer is 192.168.1.200/24. Are they on the same network? With /24, the first three octets are the network. Both start 192.168.1, so yes: the laptop can send to the printer directly, without going through a router. A phone at 192.168.2.15/24 would be on a different network, because its third octet is 2.
Example 3: how many devices fit on a network?
A /24 network leaves 8 bits for hosts, which makes 28 = 256 addresses. Two are kept back: the first (all host bits 0) names the network itself, and the last (all host bits 1) is the broadcast address. That leaves 256 − 2 = 254 addresses for devices, from 192.168.1.1 to 192.168.1.254. With a /16, there are 16 host bits: 216 − 2 = 65,534 devices.
Common mistakes
- Thinking each device has one IP address. Most have at least two: a private one on the local network, plus an IPv6 address, while the public IPv4 address belongs to the router.
- Writing an octet above 255. 192.168.1.300 isn't a valid address. Eight bits only reach 255.
- Thinking an IP address pinpoints your home. Location from an IP address is an estimate, often only as close as a town or region.
- Mixing up IP and MAC addresses. A MAC address identifies a network adapter on the local network. An IP address is used to route data between networks.
- Using :: twice in an IPv6 address. It can only appear once, or the address becomes ambiguous.
- Forgetting the two reserved addresses when counting hosts on a network: subtract 2 for the network and broadcast addresses.
Common questions
Is an IP address the same as a MAC address?
Can two devices have the same IP address?
Does my IP address change when I move?
Why does my IP address show the wrong location?
What is 192.168.1.1?
What is 127.0.0.1?
Revision cards
Say the answer first, then flip the card to check it.
Where to go next
- Learn it
IP Addressing & Protocols
IPv4, IPv6, subnetting and the protocols that power the internet
Start the course - Test it
AP Computer Science Principles
A new exam-style paper every day, with instant marking and a mark scheme
Start today's paper