IP Address Basics

Validate IP Address: IPv4 and IPv6 Rules

An inspector checks address-shaped tiles against a frame, illustrating valid IPv4 and IPv6 syntax.

To validate IP address syntax, check that the value follows IPv4 or IPv6 rules: IPv4 has four decimal numbers from 0 to 255, while IPv6 has eight hexadecimal groups with an optional zero-compression shortcut. A valid result confirms the address is well-formed; it does not prove the address is assigned, public, online, or reachable.

That distinction saves a lot of head-scratching. 127.0.0.1 is perfectly valid, yet it is an IPv4 loopback address that points back to the device you are using. IANA lists it in its special-purpose registry. Think of it as a mirror: it shows you your own machine and never reaches a neighbor. If you only need the public address your connection shows, use Loqmi’s IP checker. It answers a different question than a format validator does.

How to validate IP address syntax

Start by deciding whether the value should be one bare address, a network, or an address-and-port pair. Those look alike in a configuration file, but they are different inputs, a bit like a postcode and a full street address. A strict single-address check should accept 192.168.1.25 or 2001:db8::25. It should reject extra labels, brackets, and a port, unless the tool explicitly supports them. The IPv6 example uses the documentation prefix 2001:db8::/32 reserved by RFC 3849.

Check IPv4

IPv4 is a 32-bit address, usually written as four decimal octets separated by periods. Each octet must be from 0 through 255. So 203.0.113.8 has the right shape, while 203.0.113.300 fails because its last number is too large. The valid example comes from the documentation-only block 203.0.113.0/24 set aside by RFC 5737. The leading-zero form 192.168.001.8 is best rejected. Parsers have not always treated it the same way, and strict libraries avoid the ambiguity. It is like an extra digit on a phone number that some switchboards ignore and others dial anyway.

Check IPv6

IPv6 is 128 bits, written as eight groups of hexadecimal digits separated by colons. A group can drop its leading zeroes, and one run of zero groups can be replaced with ::. For example, 2001:0db8:0000:0000:0000:0000:0000:0001 shortens to 2001:db8::1. The double colon can appear only once. Otherwise a parser could not tell how many zero groups each shortcut stands for. RFC 4291 defines the address forms, and RFC 5952 recommends a consistent way to write them.

Quick check: Paste an address into Loqmi’s IP checker to see the public address your browser connection exposes. That checks your connection’s outward-facing address, not an unrelated address copied from a log or router setting.

Valid address does not mean usable address

“Valid” is a narrow verdict about syntax. The next question is what the address is for: a private LAN, loopback testing, documentation, multicast, or a globally reachable network. The question after that is whether a particular host answers right now. Each check needs different evidence, and punctuation alone cannot answer all three.

Three trays hold a well-formed address, a local-only address, and an unanswered destination. Validation cannot prove that a host responds.
Syntax, address classification, and whether a host responds are separate questions that need different checks.
What you want to knowWhat to checkExample or next step
Is the text an IP address?Syntax and numeric ranges192.168.1.25 is valid IPv4.
Is it an internal address?Address classification192.168.1.25 is in a private IPv4 block.
Is it a network range?CIDR prefix and network rules192.168.1.0/24 describes a network, not one host address.
Does a host answer?A permitted connection or diagnostic testTry the service or a network diagnostic; a blocked ping is not proof the host is offline.

Private IPv4 space is set aside for local networks by RFC 1918. A home router usually gives a device one of those addresses, then uses Network Address Translation (NAT) to share one public IPv4 address. IPv6 has its own special-purpose ranges. IANA’s registries describe these categories, but they explicitly do not guarantee whether an address is routable in every network context.

That is why a validator may label an address private or reserved and still call it valid. “Private” is not a formatting error. It describes how the address is used, much like a hotel room number that is unique inside the building and useless to anyone outside. Want to see your local device address? Follow our guide to finding your local IP address. To compare it with the address websites see, read public vs. private IP addresses.

Four input traps that look like bad IPs

  • A port appended to IPv4: 203.0.113.8:port is an address plus a port, not a bare IP address. Validate each part in the format the application expects.
  • Brackets around IPv6: [2001:db8::1]:port is common endpoint notation. The brackets separate the IPv6 address from its port, so do not pass either one to a bare-address checker.
  • A CIDR suffix: 10.20.0.0/16 identifies a network block. CIDR (Classless Inter-Domain Routing) uses the number after the slash to say how many leading bits form the network prefix. Validate the address and prefix together as a network, not as a single IP.
  • An IPv6 zone identifier: fe80::1%12 can identify a link-local address on one particular interface. Some parsers accept the zone suffix and others expect only the address, so check the target system’s specification.

IPv6 also has IPv4-mapped forms, such as ::ffff:192.0.2.10, which combine IPv6 notation with a dotted IPv4 tail. A simplistic regex can reject this valid form or accept an invalid one, so use a standard address parser when you build software. Python’s ipaddress library and .NET’s IPAddress.TryParse are examples. Parser behavior around nonstandard shorthand can still differ, so check the library against your application’s input contract.

Troubleshoot a failed validation

SymptomLikely causeWhat to do
IPv4 rejectedMissing/extra octet, non-decimal character, value above 255, or leading zeroRewrite as four plain decimal octets, such as 192.168.1.8.
IPv6 rejectedInvalid hex digit, too many groups, or more than one ::Expand it to eight groups and check each group has one to four hex digits.
A range is rejectedThe tool expects one address, not CIDRUse a network-aware parser and check the prefix length separately.
It validates but does not connectFormat passed; routing, firewall, host, or service may still be unavailableCheck the correct protocol and port, then test from the relevant network.

For a manual IPv6 check, expand 2001:db8::1. The visible groups are 2001, db8, and 1, so :: fills the five missing groups. That gives 2001:db8:0:0:0:0:0:1, eight groups in total. If the expanded version has more or fewer than eight groups, or a group contains a character outside hexadecimal digits, the string is malformed. The shortcut is a space-saver, not a magic eraser.

Choose the right check for your goal

If you are checking your connection’s public address, use Loqmi’s home page. If you suspect a VPN is exposing the wrong address, compare the reported address before and after connecting with our VPN check guide. A difference is expected when a VPN is active. A matching address alone is not a complete privacy audit.

If you are validating a value for a form, firewall, or script, first decide whether the field accepts a host address, a CIDR network, or an endpoint with a port. Then use a standard parser, and apply your own policy checks after parsing, such as whether private ranges are allowed. A valid public IP does not tell you who owns it. An IP location lookup is approximate, so if location is the question, see why IP locations can be wrong.

For connectivity rather than syntax, test the service you need. A ping may be blocked while a website or application works fine. A reachable address may also have no service listening on the port you need. If your concern is connection quality, Loqmi’s internet speed test measures the connection differently from an IP validator.

Do not treat “public” as “safe.” Address classification only describes a range’s intended scope. It does not prove that a device is trustworthy, that a connection is secure, or that a firewall rule is appropriate.

Key takeaways

  • IPv4 uses four decimal octets from 0 to 255; IPv6 uses eight hexadecimal groups, with limited zero compression.
  • Syntax validity does not prove assignment, public reachability, or that a host is online.
  • Keep bare addresses, CIDR networks, ports, and IPv6 zone identifiers distinct when validating input.
  • Use a standard parser for software and a network test for connectivity; they answer different questions.

Frequently asked questions

Can a valid IP address belong to nobody?

Yes. Syntax validation only checks whether the characters and structure represent an IPv4 or IPv6 address. An address can be well-formed yet unassigned, reserved for a special purpose, or not advertised by any network. Confirm assignment and routing separately when that matters.

Why does 192.168.1.1 validate if it is not my public IP?

192.168.1.1 is a valid IPv4 address in a private range used inside local networks. Your router can use it to identify a device on your home network while presenting a separate public address to websites. Validity describes format; public versus private describes how the address is used.

Should I validate an IP address with a port number?

Validate the address and port as separate fields, or use a parser designed for a complete network endpoint. A port is not part of the IP address itself. For IPv6 endpoints, brackets are commonly used around the address before the port, as in [2001:db8::1]:443.

Is an IPv6 address with a percent sign valid?

A suffix such as %12 can be a zone identifier attached to a scoped IPv6 address, often a link-local address. Whether a validator accepts it depends on the software and the field you are checking. If the application expects only a bare address, remove the zone suffix only after confirming the application’s rules.

Sources

Related articles