{"canonical_url":"https://engineer.company/glossary/ip-address/","content_markdown":"# IP address\n\n## What it is\n\nAn IP address is the number the Internet Protocol writes into every packet to\nsay where the packet is going, next to a second address that says where it came\nfrom. RFC 791, the 1981 specification of IP version 4, calls it an internet\naddress and draws the line in one sentence: \"An address indicates where it is.\"\nA name, such as a domain, says what you are looking for and has to be turned\ninto an address first, which is the job of [DNS](/glossary/#dns). The route, the\npath between the two addresses, is left to the routers in between.\n\nIn IPv4 the address is 32 bits, four octets, written as four decimal numbers\nfrom 0 to 255 separated by dots: 192.0.2.10. RFC 791 split those bits into a\nnetwork number and a local part, with three fixed classes deciding where the\nsplit fell. The classes fitted most organisations badly: a class C network held\nat most 254 hosts, a class B up to 65,534, so class B numbers ran short while\nrouting tables grew. In September 1993 RFC 1519 replaced the classes with CIDR,\nwhich lets the split fall after any bit and writes its position after a slash.\n192.0.2.0/24 is the block whose first 24 bits are fixed: 256 addresses.\n\nIPv6 widens the address to 128 bits. It is written as eight groups of up to four\nhexadecimal digits separated by colons, and RFC 4291 lets one run of zero groups\ncollapse to `::`, so 2001:db8:0:0:0:0:2:1 can also be written 2001:db8::2:1.\nBecause the same address could then be spelt many ways, RFC 5952 later fixed one\nrecommended form: lower case, no leading zeros in a group, and `::` used for the\nlongest run of zero groups.\n\nAn address belongs to a network interface, not to a machine. RFC 791 already\nsaid that a single host must be able to act as several, with several internet\naddresses, and that some hosts have several physical interfaces. RFC 4291\nrequires every IPv6 interface to have at least one link-local address, valid\nonly on its own network segment, whatever other addresses it holds. A host on a\nnetwork that runs both versions therefore carries several addresses at once,\nbesides the loopback addresses it uses to reach itself: the 127.0.0.0/8 block in\nIPv4 and `::1` in IPv6.\n\nNot every address is reachable from everywhere. RFC 1918 sets aside three IPv4\nblocks for private networks, 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16, and\nsays that routing information about them shall not be passed between\norganisations. A device holding one therefore reaches the internet only through\nsomething that stands in for it, such as NAT, which RFC 3022 describes as\ntranslating the private address into a public one on the way out. Three further\nblocks, 192.0.2.0/24, 198.51.100.0/24 and 203.0.113.0/24, are reserved by RFC\n5737 for documentation, and RFC 3849 does the same for 2001:db8::/32 in IPv6.\nEvery example address in this article comes from those documentation ranges.\n\n## Why it matters\n\nThe address is the one fact about a client that a server always has, because\nwithout it the reply would have nowhere to go. That makes it the default key for\nmany decisions: [firewall](/glossary/#firewall) rules allow or block by address,\na rate limit counts requests per address, an access log writes it on every line,\nand an abuse report names it. Each of these works only as well as the address\nidentifies what you think it identifies.\n\nIt identifies less than it seems to. Behind NAT, every device in an office or a\nhousehold can reach the internet from the same public IPv4 address, so a block\nor a limit aimed at one of them lands on all of them. Behind a proxy or a\n[CDN](/glossary/#cdn), the server sees the proxy's address on every request, and\nthe client's own address arrives, if at all, in a header that someone else\nwrote. A rule written against an address is a rule about a network position,\nnever about a person.\n\nAt the same time it reveals more than people expect. RFC 7239, which\nstandardised the `Forwarded` header that proxies use to pass the client's\naddress on, notes in its privacy section that an IP address may identify a\nclient uniquely, show which operator it uses, and give a rough idea of where it\nis. A log full of addresses is therefore a liability as well as a tool, and a\ngood reason to decide what you keep before you start keeping it.\n\nAnd there are now two kinds. Anything that parses, stores or compares addresses\nhas to accept IPv4 and IPv6 alike, because a client on a network that offers\nboth may arrive over either. Code written when every address fit in fifteen\ncharacters of digits and dots breaks on the first IPv6 visitor, usually\nsomewhere far from where the address was read.\n\n## What it looks like in practice\n\nPython's standard library includes an `ipaddress` module that parses both\nversions and does the arithmetic, so you never have to split strings by hand. In\nan interactive session:\n\n```text\n\u003e\u003e\u003e import ipaddress\n\u003e\u003e\u003e ipaddress.ip_address(\"203.0.113.57\")\nIPv4Address('203.0.113.57')\n\u003e\u003e\u003e ipaddress.ip_address(\"2001:0DB8:0000:0000:0000:0000:0002:0001\")\nIPv6Address('2001:db8::2:1')\n\u003e\u003e\u003e ipaddress.ip_network(\"203.0.113.57/24\", strict=False)\nIPv4Network('203.0.113.0/24')\n\u003e\u003e\u003e ipaddress.ip_network(\"2001:db8:42:7::5/48\", strict=False)\nIPv6Network('2001:db8:42::/48')\n```\n\nThe second call shows the normalisation that RFC 5952 asks for: the long\nupper-case spelling and the short lower-case one are the same address, and the\nmodule prints the canonical form. A string such as 192.0.2.300 is refused with a\n`ValueError`, because 300 does not fit in an octet. The last two calls turn an\naddress into the network around it. Without `strict=False` the module would\nrefuse those as well, because 203.0.113.57/24 has host bits set; with it, the\nhost part is set to zero and what remains is the network alone.\n\nThat zeroing is how this site's web access log treats visitors' addresses. Its [privacy page](/privacy/) says the address is shortened as the web log line is written, with the last part replaced by zeroes before the line reaches disk, so the stored value identifies a rough network in which a whole office or street can look identical. The server records the address under two names, masks both, and drops headers that can carry an address of their own before writing the line. The page does not say how many bits survive; the /24 and /48 above are this article's illustration, not the site's settings. Masking at write time keeps full addresses out of that web log without relying on a later clean-up job. The same privacy page separately records a Gopher exception: the operating system's per-connection log names the source address and expires after thirty days.\n\n## Where it goes wrong\n\n**Trusting a header for the client's address.** `X-Forwarded-For` and the\nstandard `Forwarded` header are plain request headers, and RFC 7239 warns that\nany hop between the client and the server, and the client itself, may rewrite\nthe `Forwarded` header, by mistake or on purpose. Code that takes the first\naddress in the list lets any client choose its own address, and with it its own\nrate limit and its own place on an allow-list. Use the address of the TCP\nconnection unless the request came through a proxy you run, and then read only\nwhat your own proxies appended, counting from the right.\n\n**Treating an address as a person.** Because many users can share one address, a\nban on an address may lock out an entire office, and a limit sized for one\nperson throttles a whole school. Use addresses for coarse decisions, set limits\nwith shared addresses in mind, and tie anything personal to an authenticated\naccount instead.\n\n**Comparing addresses as strings.** 2001:db8::2:1 and 2001:DB8:0:0:0:0:2:1 are\none address and two different strings, so an allow-list matched by text accepts\none and rejects the other. Parse both sides before comparing, or store only the\nRFC 5952 form.\n\n**Parsing for IPv4 only.** A regular expression for four dotted numbers, a\ncolumn sized for fifteen characters, or code that splits host and port at the\nlast colon will all fail on IPv6. Use a real parser and a column type or length\nmeant for both versions. When a port is written next to an IPv6 address, RFC\n5952 recommends brackets, as in [2001:db8::1]:443, because without them the last\ngroup could be read as part of the address.\n\n**Keeping full addresses longer than needed.** Logs, analytics tables and\nbackups collect addresses for years if nothing stops them. Decide what precision\nyou need, shorten the address when it is written rather than afterwards, and\ngive the remainder an expiry date.\n\n**Using real addresses in examples.** A sample configuration, a test fixture or\na screenshot that uses someone's real address sends copied traffic to a\nstranger. RFC 5737 reserves its three blocks precisely to reduce that kind of\nconflict and confusion; use them, and 2001:db8::/32 for IPv6.\n\n## Further reading\n\n- [RFC 791: Internet Protocol](https://www.rfc-editor.org/rfc/rfc791.html) — the\n  1981 specification of IPv4, with its 32-bit address and the distinction\n  between names, addresses and routes.\n- [RFC 4291: IP Version 6 Addressing Architecture](https://www.rfc-editor.org/rfc/rfc4291.html)\n  — the IPv6 address types, their text forms and the link-local requirement.\n- [RFC 5952: A Recommendation for IPv6 Address Text Representation](https://www.rfc-editor.org/rfc/rfc5952.html)\n  — one canonical way to write an IPv6 address, and the trouble that flexible\n  spellings cause.\n- [RFC 7239: Forwarded HTTP Extension](https://www.rfc-editor.org/rfc/rfc7239.html)\n  — how proxies pass a client's address on, why the result cannot simply be\n  trusted, and its privacy cost.\n- [RFC 5737: IPv4 Address Blocks Reserved for Documentation](https://www.rfc-editor.org/rfc/rfc5737.html)\n  — the three ranges meant for examples.\n- [ipaddress: IPv4/IPv6 manipulation library](https://docs.python.org/3/library/ipaddress.html)\n  — Python's standard module for parsing, comparing and grouping addresses.\n\n\u003chttps://engineer.company/glossary/ip-address/\u003e\n","date_modified":"2026-11-12T05:34:23Z","description":"What an IP address is in IPv4 and IPv6, how to read and store one, and how servers get it wrong: forged headers, string compares and full logs.","formats":{"gemtext":"https://engineer.company/glossary/ip-address/index.gmi","gopher":"https://engineer.company/glossary/ip-address/gophermap","html":"https://engineer.company/glossary/ip-address/","json":"https://engineer.company/glossary/ip-address/index.json","markdown":"https://engineer.company/glossary/ip-address/index.md","pdf":"https://engineer.company/glossary/ip-address/index.pdf"},"kind":"page","language":"en","title":"What is an IP address?","url":"https://engineer.company/glossary/ip-address/","version":1}