Learning objectives
After reading this article you will be able to:
- Understand the difference between IPv4 and IPv6
- Know what static, dynamic, public and private IPs are
- Decide when you need a static IP and when a domain is enough
Every computer that talks to the internet has an IP address, and many hosting questions run through it, from which IP to put in DNS to whether you need a static one. Knowing the two protocol versions shows what changes when you publish a bot, an API or a website.
Most of the time you never type an IP: you point names, and DNS does the rest. Still, understanding the difference prevents configuration mistakes and tells you when a static IP really matters.
What is an IP address?#
An IP address identifies a network interface so packets know where to go. It says who the destination is and where it sits on the network. IPv4 is defined in RFC 791, and IPv6 in RFC 8200.
You normally reach a service by a name such as example.com. The naming system turns that name into an IP before the connection starts. To review that step, read what is DNS.
What is the difference between IPv4 and IPv6?#
IPv4 uses 32 bits, written as four numbers from 0 to 255 separated by dots: 203.0.113.10. That gives about 4.3 billion addresses (2 to the power of 32), a number that became small next to the count of connected devices. The IANA IPv4 registry shows its last central allocation in 2011, and since then addresses change hands through resale and reuse.
IPv6 uses 128 bits, written as eight hexadecimal groups separated by colons: 2001:db8::10. The space is so large that every network gets huge blocks with no scarcity. RFC 4291 defines the addressing architecture, and RFC 5952 sets the recommended text form: lowercase letters, leading zeros omitted, and the longest run of zero groups shortened to :: (only once per address, and never for a single zero group, which is written 0).
| IPv4 | IPv6 | |
|---|---|---|
| Size | 32 bits | 128 bits |
| Format | 203.0.113.10 |
2001:db8::10 |
| DNS record | A | AAAA |
| Localhost | 127.0.0.1 |
::1 |
| Scarcity | Yes, IANA's central pool ran out | No |
| NAT needed | Very common | Usually not |
The 2001:db8::/32 block is reserved for documentation (RFC 3849), which is why it appears in examples like this one.
The two protocols do not talk to each other directly. An IPv6-only client cannot reach an IPv4-only server without a translator in between. That is why the transition runs on dual stack: the server and the network accept both versions at the same time.
What are public IPs, private IPs and CGNAT?#
A public IP is routable on the internet. A private IP only works inside a local network. RFC 1918 reserves three ranges for it:
10.0.0.0/8172.16.0.0/12192.168.0.0/16
Your home router uses NAT: every device on the inside reaches the internet through a single public IP. That is why your computer shows 192.168.0.x while "what is my IP" sites show a different address.
Some providers go further and apply CGNAT, using the 100.64.0.0/10 range (RFC 6598) to share one public IPv4 among many customers. Behind CGNAT, inbound connections never reach you, so opening a port on your router does nothing. It is one of the most common reasons for "my home server is not reachable from outside".
What are static and dynamic IPs?#
A dynamic IP changes from time to time, because the provider hands it out from a shared pool. A static IP is reserved for you and stays the same until you give it back.
- Home connections usually get a dynamic IP, sometimes behind CGNAT.
- Hosting servers usually get a static IP, precisely so DNS can point at it safely.
The problem with a dynamic IP for hosting is simple: DNS keeps the old address and points at nothing once the IP changes. Dynamic DNS services update the record automatically, but they only make sense if you truly must serve from home.
When do you really need a static IP?#
Less often than you might think. Ask who needs to know the address:
- Discord, Telegram and WhatsApp bots normally make outbound connections to the platforms. Nobody needs to know the bot's IP.
- APIs and websites are reached by domain. Whoever uses the name does not care about the IP behind it.
- IP allowlists: a database, a payment API or a third-party firewall only accepts connections from registered addresses. Here your application's outbound IP must be stable.
- A direct A record: if you point the root domain at an IP, that IP has to last.
- Email: mail servers depend on the reputation of an IP, and reverse DNS (PTR) must match it.
Outside those cases, the better path is to point by name. With a CNAME record, the host can change the IP behind it without breaking your DNS. Compare the two records in A vs CNAME and see every type in DNS records.
How do you check IPv4 and IPv6 for your domain?#
Ask for both record types and test the connection on each stack:
dig +short A example.com
dig +short AAAA example.com
curl -4 -sI https://example.com | head -n 1
curl -6 -sI https://example.com | head -n 1If AAAA comes back empty or curl -6 fails, the server only serves IPv4. In Node.js you can list every address of a name and detect the version of each:
import { lookup } from "node:dns/promises";
import { isIP } from "node:net";
const addresses = await lookup("example.com", { all: true });
for (const { address, family } of addresses) {
console.log(`IPv${family}: ${address} (isIP=${isIP(address)})`);
}lookup with all: true returns one item per address, with family equal to 4 or 6 (dns module docs). To validate user input, isIP returns 4, 6, or 0 when the string is not an IP.
A common code mistake is storing an IP in a 15-character field: an IPv6 address reaches 39 characters in full hexadecimal form, and 45 in the form with an embedded IPv4 address at the end (0000:0000:0000:0000:0000:ffff:255.255.255.255). Use columns and validation that accept both formats.
How to do this on Square Cloud#
Square Cloud uses only dynamic IPv4, with no fixed IP and no IPv6, so there is no stable address for an A record: publish by name. Every web application gets a *.squareweb.app subdomain with HTTPS, on every plan. From the Standard plan you can also use your own domain: you create the DNS records the dashboard shows at your registrar, follow validation in real time and get automatic TLS.
Your own domain points with a CNAME to cname.squareweb.app, plus a TXT record for validation. The root domain works if your DNS provider supports a CNAME at the apex (flattening or ALIAS), and the recommended setup redirects www to the main domain. The domain stays registered in your name at your registrar, and that is where you keep the DNS records.
To serve more traffic from one domain, load balancing spreads requests for a custom domain across several applications, with round-robin and passive failover. Learn more in custom domains, the Square Cloud network and load balancing.
Network
Custom domains, automatic TLS and a global CDN for your app
FAQs
Is IPv6 better than IPv4?
IPv6 has a far larger address space and removes the need for NAT in most cases. In practice the two coexist, and a well-configured server serves both.
Do I need a static IP to host a bot or an API?
Almost never. A bot usually only makes outbound connections, and an API is reached through a domain. A static IP matters when a third party allows access by IP list.
What is CGNAT and why does it get in the way?
It is when an internet provider shares one public IPv4 address among many customers. You usually cannot receive inbound connections from the internet, so hosting a server at home becomes hard.
How do I know if my server answers over IPv6?
Look for an AAAA record on the domain and test the connection with curl -6. If there is no AAAA record or the connection fails, the server only serves IPv4.
More in Networking and domains
See all 27 articles- What is a load balancer and how does it work?A load balancer spreads incoming requests across several servers. Learn how it works, the main algorithms, layer 4 vs 7, and a working nginx example.
- DNS records explained: A, CNAME, MX, TXTDNS records are the instructions in a zone that tell the internet where a name points. Learn A, AAAA, CNAME, MX, TXT, NS and CAA with examples and dig commands.
- How to point a domain to your server or appTo point a domain to your server or app, create a CNAME (or A) record in your registrar's DNS panel. Steps, how to test it, and common mistakes.
- Cache-Control headers explainedCache-Control is the HTTP header that sets how long browsers and CDNs keep a response. Learn max-age, no-cache, immutable and ready-made recipes for each file type.