Public IP vs Private IP

In AWS EC2, Private IPs and Public IPs are used to define how an instance communicates within the AWS network and with the outside world.

Generated image

Β 


πŸ” Private IP

  • Assigned to EC2 instance within a VPC
  • Used for internal communication (within same VPC or peered VPCs)
  • Non-routable on the internet
  • Remains attached to the instance until it's stopped or terminated
  • Example: 172.31.16.45

πŸ”Έ Use Case: App server talking to database server in private subnet.


🌍 Public IP

  • Mapped to the instance’s private IP via NAT (Network Address Translation)
  • Used for communication over the internet
  • Assigned automatically (for default subnets) or manually (via Elastic IP)
  • Changes if the instance is stopped and restarted (unless Elastic IP is used)
  • Example: 3.109.221.105

πŸ”Έ Use Case: Web server accessed from the internet.


πŸ” Summary Comparison

Feature Private IP Public IP
Visibility Internal (VPC only) Global (Internet)
Internet Access ❌ Directly No βœ… Yes
Assignment By VPC DHCP (or manual) Auto-assigned or Elastic IP
Persistence Until stop/terminate May change unless Elastic IP used
Usage Backend/internal traffic Web apps, SSH, API calls from outside

πŸ“ Note:

  • Elastic IP = Static public IP assigned to your account; can be reattached.
  • Instances in private subnets usually don’t have public IPs and use NAT gateways for internet access.
Back to blog

Leave a comment