skip to content

An EC2 instance launched into an AWS VPC public subnet receives a public IPv4 address automatically. What happens to that address when the instance is stopped and started again, and how does allocating an Elastic IP change the picture?

level: juniorimportance: should knowfreq 62%

answer

  1. borrowed versus owned
  2. reboot keeps it, stop does not
  3. the guest OS never sees it
  4. re-associate to move it elsewhere
  5. every public IPv4 is metered now

basics

~20 s

An auto-assigned public IPv4 address is borrowed from an AWS pool and released when the instance stops or terminates, so a start hands out a different one. An Elastic IP belongs to your account, survives stop/start, and can be moved to another instance or interface.

solid answer

~50 s

The auto-assigned public IPv4 address is not yours — it is drawn from an AWS pool for the life of the running instance. A reboot keeps it, but a **stop** releases it, and starting the instance again produces a different address. That makes it unusable for anything another party has written down: DNS records, partner allow-lists, license servers. An **Elastic IP** is allocated to your account instead, so it persists across stop/start and can be re-associated with a different instance or network interface — which is exactly how you fail an address over. Two things worth adding: the instance's operating system never sees either address, because the internet gateway does the one-to-one mapping outside the guest; and since February 2024 every public IPv4 address in use is billed per hour, whether it is attached to a running instance or sitting idle in your account.

code

bash · 11 lines
bash
# Allocate an account-owned address and attach it to an instance
ALLOC_ID=$(aws ec2 allocate-address --domain vpc --query AllocationId --output text)
aws ec2 associate-address \
  --instance-id i-0123456789abcdef0 \
  --allocation-id "$ALLOC_ID"

# Moving it later is a re-association, not a new address
aws ec2 associate-address \
  --instance-id i-0fedcba9876543210 \
  --allocation-id "$ALLOC_ID" \
  --allow-reassociation

go deeper

for a junior

Remember the lifecycle rule — reboot keeps the auto-assigned address, stop and start replaces it — and that an Elastic IP is the way to get one that stays put. Say that plainly and you have the question.

for a middle

Explain that the address lives on the internet gateway's translation, not on the instance interface, and that an Elastic IP is an account-level allocation you can move between interfaces. Know that public NAT gateways require one.

for a senior

Argue for designs that need no per-instance public address at all: load balancers in front, NAT gateway behind, addresses treated as a scarce, metered, allow-listed asset. Be ready to explain what changed with the 2024 IPv4 charge.

for a principal

Own the fleet-wide address strategy — how many stable egress addresses the organisation exposes to partners, who governs the allow-lists that reference them, and whether an IPv6 or private-connectivity path removes the dependency entirely.

## Two kinds of public IPv4 address A VPC instance can end up with a public IPv4 address in one of two ways, and interviews probe whether you know the difference because the failure modes are completely different. **Auto-assigned public IPv4.** Subnets carry a setting that decides whether instances launched into them get a public address by default, and the launch request can override it. When it applies, AWS lends the instance an address from a regional pool. It is bound to that instance for as long as it is *running*. There is no name for it in your account, you cannot choose it, and you cannot get the same one back. **Elastic IP.** This is an address you explicitly allocate to your AWS account. It exists independently of any instance, has an allocation ID, and stays yours until you release it. You associate it with an instance or, more precisely, with an elastic network interface — and you can disassociate and re-associate it elsewhere at will. ## The lifecycle rule that catches people The distinction only becomes visible across the instance lifecycle: - **Reboot** — the auto-assigned address is kept. A reboot does not release the instance's placement or its networking. - **Stop, then start** — the auto-assigned address is released back to the pool. The started instance gets a *different* public address. This is the one that breaks things. - **Terminate** — the address is gone either way. An Elastic IP is unaffected by all of these; it stays associated across a stop/start, and stays allocated to your account even after the instance is terminated (which is exactly when people forget it exists and keep paying for it). So the moment anyone outside your account has to know the address — a DNS `A` record, a partner's firewall allow-list, an on-premises IPsec peer, an SFTP counterparty — an auto-assigned address is the wrong tool. Either use an Elastic IP or, better, put the workload behind a load balancer or a DNS name so the address stops being part of your contract with the outside world. ## The address is not on the instance A detail that surprises people the first time they look: the operating system inside the instance has no idea about the public address. The interface is configured only with the VPC private address. The internet gateway performs the one-to-one translation on the way out and the way back, entirely outside the guest. That is why you cannot discover the public address by inspecting the instance's own interface configuration — you look it up through the instance metadata service, or through the EC2 API, or from outside. ## Where Elastic IPs are mandatory A **public NAT gateway** must have an Elastic IP; there is no auto-assigned option, precisely because the whole point of the NAT gateway is to be a stable, known source address for everything behind it. That stability is why partners are willing to allow-list it. You can also associate additional Elastic IPs with a public NAT gateway. That is not about vanity addresses — each address brings its own set of source ports, which is how you expand a NAT gateway's simultaneous-connection capacity toward a single busy destination. ## The cost change nobody noticed Until 2024, an Elastic IP was free while attached to a running instance and charged only when idle — the classic "don't hoard addresses" incentive. Since **1 February 2024** AWS charges an hourly rate for **every public IPv4 address in use**, including auto-assigned ones on running instances and the addresses on NAT gateways and load balancers. Individually the rate is small; across a fleet of hundreds of instances that each did not need a public address, it is a real line item, and it turned "does this thing need a public IP at all?" into a cost question as well as a security one. The standard responses are the ones you would want anyway: put instances in private subnets behind a load balancer, share one NAT gateway's address instead of giving every instance its own, and adopt IPv6 where the workload allows it, since IPv6 addresses are not charged this way. ## What to say in the interview Lead with the lifecycle rule — reboot keeps it, stop/start loses it — because that is the concrete, checkable fact. Then give the reason to care: anything external that depends on the address needs stability, which is what an Elastic IP buys. Finish with the modern framing: the best answer to "which address do I need?" is often "none, put it behind a load balancer or a NAT gateway", and that answer is now cheaper as well as safer.

  • Your instance needs a stable outbound address for a partner's allow-list, but it should not be reachable from the internet. What do you do?
    Put the instance in a private subnet and route its egress through a NAT gateway, then give the partner the NAT gateway's Elastic IP. The address is stable and allow-listable, while nothing inbound can reach the instance because the NAT gateway only holds state for outbound flows.
  • Why does an Elastic IP keep costing money after you terminate the instance it was attached to?
    Because it is allocated to your account, not to the instance — termination only disassociates it. It stays reserved for you, and since public IPv4 addresses are billed hourly you keep paying until you explicitly release the allocation.
  • Does any of this apply to IPv6 addresses in a VPC?
    No. IPv6 addresses assigned in a VPC are globally routable and stable on the interface, there is no Elastic-IP equivalent needed for stability, no one-to-one translation happens, and they are not subject to the public IPv4 hourly charge.

saying these in an interview costs you the question

  • Says a reboot loses the public address
  • Thinks the public address is configured inside the instance's OS
  • Assumes an Elastic IP is free while attached
  • Believes an Elastic IP is permanently tied to one instance
  • Treats an auto-assigned address as safe to put in a DNS record

context