Cloud Cost Basics
18 min
Cloud costs typically break down into a few core dimensions: compute (billed per hour or per second a resource runs), storage (billed per GB per month, regardless of whether it's ever read), and egress (billed per GB of data leaving the provider's network — famously the line item that surprises people, since data coming IN is almost always free).
def monthly_cost(compute_hours, compute_rate, storage_gb, storage_rate, egress_gb, egress_rate):
return round(
compute_hours * compute_rate
+ storage_gb * storage_rate
+ egress_gb * egress_rate,
2,
)
Notice egress at just 50GB already costs more per GB than storing 100GB for the entire month -- that asymmetry (cheap storage, cheap ingress, expensive egress) is deliberate provider economics, and it's exactly why architectures that serve lots of data directly out of the cloud (video, large API responses) budget for egress specifically.
Write `monthly_cost(compute_hours, compute_rate, storage_gb, storage_rate, egress_gb, egress_rate)`: total cost is `compute_hours * compute_rate + storage_gb * storage_rate + egress_gb * egress_rate`, rounded to 2 decimal places.
Cloud bills often have a surprise line item: EGRESS (data leaving the cloud provider's network). Why does egress get billed separately and aggressively, while data coming IN is usually free?
You can compute a monthly cloud cost estimate from compute, storage, and egress usage, and understand why egress is priced so differently from ingress.