How to use resource labels for cost attribution on Google Cloud, standard naming conventions, and how labels differ from tags.
What Are Resource Labels?
Labels are key-value pairs you attach to Google Cloud resources. They are metadata that help you organize, filter, and track resources. For cost optimization, the key use case is cost allocation — breaking down your bill by team, environment, application, or any dimension you choose.
Labels flow from resources into the billing system. When you enable billing exports, label data appears in your billing reports and BigQuery exports, letting you answer questions like “how much did the analytics team spend on production compute last month?”
How Labels Work
Constraints:
- Up to 64 labels per resource
- Keys: 1-63 characters, must start with a lowercase letter or international character
- Values: 0-63 characters (can be empty)
- Keys and values can contain lowercase letters, digits, underscores, and dashes
- Keys must be unique within a single resource
- No limit on total labels across all resources in a project
Adding labels via gcloud:
# Add labels to a VM
gcloud compute instances update my-vm \
--update-labels=team=analytics,environment=production,application=data-pipeline
# Add labels to a disk
gcloud compute disks update my-disk \
--update-labels=team=analytics,environment=production
# Remove a label
gcloud compute instances update my-vm \
--remove-labels=applicationLabels for Cost Allocation
Labels are the primary mechanism for attributing costs to teams, projects, or components in Google Cloud.
How it works:
- Apply labels to all resources (VMs, disks, buckets, databases, etc.)
- Label data flows into the billing system automatically
- View cost breakdown by label in the Billing console (Charts > Group by label)
- For detailed analysis, export billing data to BigQuery and query by label
Example cost queries:
- “Show me all costs where
team = analytics” - “Compare
environment: productionvsenvironment: developmentspend” - “Which
applicationhas the highest compute cost?”
Tip: Labels only provide value if they are applied consistently. Enforce required labels through organization policies or deployment automation. A label that exists on half your resources gives you an incomplete picture.
Standard Label Keys
| Key | Example Values | Purpose |
|---|---|---|
team | analytics, platform, security | Which team owns the resource |
environment | production, staging, development | Deployment environment |
application | web-api, data-pipeline, auth-service | Which application this resource serves |
owner | team-data, platform-oncall | Responsible team or support alias |
costcenter | engineering, marketing, rnd-2026 | Cost center for accounting |
component | frontend, backend, database, cache | Component within an application |
state | active, deprecated, archive | Lifecycle state |
Note: These are conventions, not enforced by Google. Pick a set of keys that makes sense for your organization and apply them consistently. Avoid ad-hoc label keys that only one person understands.
Labels vs Tags
Google Cloud has three different “tagging” mechanisms. They serve different purposes and are often confused.
| Aspect | Labels | Resource Manager Tags | Network Tags |
|---|---|---|---|
| What they are | Key-value pairs on resources | Key-value pairs created as separate resources | Strings on VMs |
| Primary use | Cost allocation, organization | IAM policy conditions, org policies | Firewall rules, network routing |
| Can use in IAM? | No | Yes (conditions on allow/deny policies) | No |
| Appear in billing? | Yes | No | No |
| Limits | 64 per resource | Configurable hierarchy | Multiple per VM |
| Example | team: analytics | env: production (used in IAM condition) | http-server (used in firewall rule) |
For cost attribution, use Labels. For policy enforcement and IAM conditions, use Resource Manager Tags. For firewall rules, use Network Tags.
Labels in BigQuery Billing Exports
When you enable billing export to BigQuery, labels are included with the billing data. This enables SQL-based cost analysis.
Example query: costs by team
SELECT
labels.key AS label_key,
labels.value AS label_value,
SUM(cost) AS total_cost
FROM
`project.dataset.gcp_billing_export_v1_XXXXX_XXXXX_XXXXX`,
UNNEST(labels) AS labels
WHERE
labels.key = 'team'
AND invoice.month = '202605'
GROUP BY
label_key, label_value
ORDER BY
total_cost DESCThis gives you a per-team cost breakdown for the month. You can extend this to filter by environment, application, or any other label dimension.
Best Practices
| Practice | Why |
|---|---|
| Define required labels early | Retrofitting labels onto existing resources is painful. Set standards before you deploy. |
| Use consistent key names | team everywhere, not team in one project and squad in another. |
| Enforce via org policy and automation | Require labels before resources can be created. |
| Keep values short and standardized | production not Production, prod, and PROD in different places. |
| Review quarterly | Remove unused labels, add new ones as teams and services evolve. |
| Do not use labels for sensitive data | Labels are visible to anyone with resource viewer access. No secrets, no PII. |
| Apply to all resource types | VMs, disks, buckets, databases, Cloud Run services. Gaps in coverage mean gaps in cost visibility. |
TL;DR
- Labels are key-value pairs for cost attribution, organization, and filtering. Up to 64 per resource.
- Standard keys:
team,environment,application,owner,costcenter,component. - Labels flow into billing reports and BigQuery exports for cost analysis by team, environment, or application.
- Labels are not Tags: Labels = cost tracking. Resource Manager Tags = IAM policy conditions. Network Tags = firewall rules.
- Consistency is critical. Enforce required labels through org policies or deployment automation.
- Do not put sensitive data in labels. They are visible to anyone with resource viewer access.
Resources
Labels Overview Official documentation on label constraints, usage, and best practices.
Use Labels for Cost Visibility Google Cloud Blog on using labels for cost management.
Tags and Labels Comparison How Resource Manager Tags differ from labels.
Billing Budgets and Alerts Scope budgets by label to alert on per-team or per-environment spending.
Cost Optimization Overview of all cost levers on Google Cloud.