Stay organized with collections Save and categorize content based on your preferences.
Compute Engine offers predefined machine types that you can use when you create a VM instance. A predefined machine type has a preset number of vCPUs and amount of memory, and is charged at a set price. If predefined VMs don't meet your needs, you can create a VM instance with custom virtualized hardware settings. Specifically, you can create a VM instance with a custom number of vCPUs and amount of memory, effectively using a custom machine type. Custom machine types are available for the following:
Custom VMs are ideal in the following scenarios:
Select the tab for how you plan to use the samples on this page:
ConsoleWhen you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloudInstall the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update
.To use the Terraform samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update
.
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
GoTo use the Go samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update
.
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
JavaTo use the Java samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update
.
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
Node.jsTo use the Node.js samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update
.
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
PHPTo use the PHP samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update
.
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
PythonTo use the Python samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update
.
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
RESTTo use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
To get the permissions that you need to create a VM with a custom machine type, ask your administrator to grant you the Compute Instance Admin (v1) (roles/compute.instanceAdmin.v1
) IAM role on the project. For more information about granting roles, see Manage access to projects, folders, and organizations.
This predefined role contains the permissions required to create a VM with a custom machine type. To see the exact permissions that are required, expand the Required permissions section:
Required permissionsThe following permissions are required to create a VM with a custom machine type:
compute.instances.setMachineType
on the VMcompute.instances.create
on the projectcompute.images.useReadOnly
on the imagecompute.snapshots.useReadOnly
on the snapshotcompute.instanceTemplates.useReadOnly
on the instance templatecompute.networks.use
on the projectcompute.addresses.use
on the projectcompute.networks.useExternalIp
on the projectcompute.subnetworks.use
on the project or on the chosen subnetcompute.subnetworks.useExternalIp
on the project or on the chosen subnetcompute.instances.setMetadata
on the projectcompute.instances.setTags
on the VMcompute.instances.setLabels
on the VMcompute.instances.setServiceAccount
on the VMcompute.disks.create
on the projectcompute.disks.use
on the diskcompute.disks.useReadOnly
on the diskYou might also be able to get these permissions with custom roles or other predefined roles.
LimitationsGoogle charges for custom VMs based on the number of vCPUs and memory hours that the VM uses. This is different from how predefined machine types are charged. The on-demand prices for custom machine types include a 5% premium over the on-demand prices for predefined machine types.
When using a custom machine type, any memory up to and including the default amount per vCPU is charged at the machine family custom machine type pricing. E2 custom machine and E2 shared-core custom machine types share the same pricing scheme.
If you use your commitments to run custom machine types, then Compute Engine charges a 5% premium over the commitment prices. Compute Engine charges this premium for the portion and duration of your commitment that you run these custom machine type VMs.
See VM instance pricing for information by machine series.
Custom VMs are subject to the same 1-minute minimum charge as any other instance, but sustained use discounts for custom machine types are calculated differently. For more information, see sustained use discounts for custom VMs.
Extended memory pricingFor memory above the default, Compute Engine charges for extended memory based on the machine family extended custom memory pricing. The price for extended memory is different from the price for memory below the default threshold.
Extended memory prices differ depending on the region. Instances running with extended memory are subject to the same 1-minute minimum charge as any other instance. Extended memory also qualifies for sustained use discounts.
Add extended memory to a machine typeDepending on the machine series, each machine type has a specific amount of memory by default. For some workloads, this might not be enough memory. For an extra cost, you can get more memory per vCPU beyond the default limit. This is referred to as extended memory.
With extended memory, you can specify an amount of memory for the custom machine type with no limitation per vCPU. Instead of using the default memory size based on the number of vCPUs specified, you can specify an amount of extended memory, up to the limit of the machine series.
Machine series vCPU limit Memory limit N4 80 640 GB N2 80 864 GB N2D 96 768 GB N1 96 624 GBIf you require more memory, use one of the memory-optimized machine types.
Determine if you need extended memoryCertain workloads need more than the default amount of memory per vCPU to deliver optimum results. Workloads that are based on in-memory high- performance analytics databases, including relational and NoSQL databases such as MS SQL Server, MongoDB, and MemcacheD/Redis, are in this category. The vCPU-based licensing of operating systems and software stacks also makes selecting an optimal VM memory configuration more challenging with predefined machine types. By using extended memory, you can add as much memory as your VMs need for the best price- performance ratio.
Express memory in GB or MBFor Google Cloud tools and documentation, machine type memory is calculated in gigabytes (GB), where 1 GB is 230 bytes. This unit of measurement is also known as a gibibyte (GiB) . When converting memory from GB to MB, 1 GB = 1024 MB.
In the API, you must always provide memory in megabytes. If you use the Google Cloud CLI, you can provide the total memory for a VM in gigabytes or megabytes. However, the gcloud CLI expects the memory value to be an integer, so you cannot provide a float value. For example, to express 5.75 GB, convert 5.75 GB into MB instead. In this case, 5.75 GB is 5888 MB.
Create a VM with a custom machine typeBefore you create a custom VM instance, make sure you read the
custom specificationsfor creating this machine type.
ConsoleIn the Google Cloud console, go to the Create an instance page.
In the Machine configuration pane, do the following:
Optional: Specify other configuration options. For more information, see Configuration options during instance creation.
To create and start the instance, click Create.
Create a custom machine type using the gcloud compute instances create
command with the --machine-type
option.
gcloud compute instances create INSTANCE_NAME \
--machine-type=MACHINE_TYPE-custom-NUMBER_OF_VCPUS-AMOUNT_OF_MEMORY_MB
Replace the following:
AMOUNT_OF_MEMORY_MB: amount of memory in MB or GB
To create a G2 VM with 4 vCPUs and 19 GB of memory in zone us-central1-a
, run the following command:
gcloud compute instances create example-instance \
--zone=us-central1-a --machine-type=g2-custom-4-19456
For G2 VMs, memory must be a multiple of 1024 MB and within the supported memory range. For more information about creating G2 VMs, see Create a VM that has attached GPUs.
Here's an example using an N2 machine type with 48 vCPUs and 310 GB of memory in zone us-central1-a
:
gcloud compute instances create example-instance \
--zone=us-central1-a --machine-type=n2-custom-48-317440
For supported machine series, such as N2, you can configure extended memory, which lets you specify a higher amount of memory than the maximum ratio of memory to vCPUs. To configure extended memory, increase the value of AMOUNT_OF_MEMORY_MB
and append -ext
to the machine type name, for example --machine-type=n2-custom-48-720000-ext
.
Alternatively, you can specify a custom machine type by using the custom options: --custom-cpu
, --custom-memory
, --custom-vm-type
, and --custom-extensions
.
gcloud compute instances create INSTANCE_NAME \
--custom-cpu=NUMBER_OF_VCPUS \
--custom-memory=NUMBER_OF_MB \
--custom-vm-type=MACHINE_TYPE \
--custom-extension
Replace the following:
The following example is an N2 custom machine type with 48 vCPUs and 310 GB of memory using the Google Cloud CLI options.
gcloud compute instances create example-instance \
--custom-cpu=48 --custom-memory=317440 --custom-extension --custom-vm-type=n2
When using the --custom-memory
option, specify the total amount of memory in GB or in MB. The property value must be an integer, so if you want to specify increments of 0.25 GB for memory, use the value 250 MB instead.
For E2 shared-core custom machine types, use the same gcloud compute instances create
command and include the shared-core machine size: micro
, small
, or medium
. The vCPU and memory are limited.
gcloud compute instances create INSTANCE_NAME\
--machine-type=MACHINE_TYPE-AMOUNT_OF_MEMORY_MB
Replace the following:
The following example is an E2 shared-core small custom machine type with 0.5 vCPU and 2.25 GB of memory.
gcloud compute instances create example-instance \
--machine-type=e2-custom-small-2304
Terraform To generate the Terraform code, you can use the Equivalent code component in the Google Cloud console.
Before trying this sample, follow the Go setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Go API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
JavaBefore trying this sample, follow the Java setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Java API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.jsBefore trying this sample, follow the Node.js setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Node.js API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
PythonBefore trying this sample, follow the Python setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Python API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
RESTUsing the instances.insert
method, construct an instance creation request and specify the custom machineType
values. Provide the memory in MB.
micro
, small
, or medium
.-ext
at the end of the machine type.POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances
Example request body
{
"name": "exampleinstance",
"machineType": "zones/us-central1-a/machineTypes/n2-custom-16-107520",
"disks": [
{
"boot": true,
"diskSizeGb": 10,
"initializeParams": {
"sourceImage": "projects/debian-cloud/global/images/family/debian-11"
}
}
],
"networkInterfaces": [
{
"network": "global/networks/default"
}
]
}
```
You can similarly create preemptible instances and groups of instances with custom machine types.
Add extended memory during instance creationTo create a VM instance with extended memory, do the following:
ConsoleIn the Google Cloud console, go to the Create an instance page.
In the Machine configuration pane, do the following:
Optional: Specify other configuration options. For more information, see Configuration options during instance creation.
To create and start the VM, click Create.
Create a custom machine using the gcloud compute instances create
command with the --machine-type
option.
gcloud compute instances create INSTANCE_NAME\
--machine-type=MACHINE_TYPE-custom-NUMBER_OF_VCPUS-AMOUNT_OF_MEMORY_MB
Replace the following:
Here's an example using an N2 machine type with 48 vCPUs and 310 GB of memory in zone us-central1-a
:
gcloud compute instances create example-instance \
--zone=us-central1-a --machine-type=n2-custom-48-317440
Go
Before trying this sample, follow the Go setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Go API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
JavaBefore trying this sample, follow the Java setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Java API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.jsBefore trying this sample, follow the Node.js setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Node.js API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
PythonBefore trying this sample, follow the Python setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Python API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
RESTUsing the instances.insert
method, construct your instance creation request as you would to create an instance with custom memory. Include -ext
, which indicates extended memory, when specifying the machineType
values:
-ext
to extend the memory up to the limit as described by that particular machine family. zones/ZONE/machineTypes//MACHINE_TYPE-NUMBER_OF_CPUS-AMOUNT_OF_MEMORY-ext
Replace the following:
For example, the following specifies an N2 machine type with 2 vCPUs and 20 GB of memory, note that you must convert the memory to MB:
zones/ZONE/machineTypes/n2-custom-2-20480-ext
Add extended memory to an existing VM instance
To add more memory to an existing instance that uses a custom machine type, you must first
stop the instance. After the instance stops, complete the following steps to add more memory to the VM.
ConsoleIn the Google Cloud console, go to the VM instances page.
Choose the stopped VM you want to modify from the VM list.
Click Edit at the top of the page.
In Machine configuration, select General-purpose.
In the Machine type section, select Custom.
Select the number of vCPUs you want.
To add extended memory, select Extend memory and then specify the amount of memory you want.
Save your changes.
Use the gcloud compute instances stop
command to stop the VM. Then use the gcloud compute instances set-machine-type
command with the --custom-memory
and --custom-extensions
options to edit the machine's resources.
Save the changes and restart the VM.
GoBefore trying this sample, follow the Go setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Go API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
JavaBefore trying this sample, follow the Java setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Java API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.jsBefore trying this sample, follow the Node.js setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Node.js API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
PythonBefore trying this sample, follow the Python setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Python API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
RESTUse the instances.stop
method then use the instances.setMachineType
method to edit the machine type resources.
Once you stop the instance, edit the machineTypes
option with your changes.
{
"name": "INSTANCE_NAME", "machineType": "zones/ZONE/machineTypes/MACHINE_TYPE",
... }
Replace the following:
+ INSTANCE_NAME: The name of the VM
+ ZONE: The zone where your VMs reside
+ MACHINE_TYPE: The name of the VM
What's next
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["Compute Engine offers both predefined VM machine types with fixed vCPU and memory configurations, as well as custom machine types that allow for tailored vCPU and memory settings, primarily on N and E series machines."],["Custom VMs provide flexibility for workloads that don't fit into predefined types, offering control over processing power and memory, with memory adjustments in 256 MB increments and with the added ability to optimize software licensing costs."],["Extended memory, available on specific N-series machines (N4, N2, N2D, N1), provides increased memory per vCPU for memory-intensive tasks like in-memory databases and is charged separately, but does qualify for sustained use discounts."],["Creating or modifying custom VMs with or without extended memory can be accomplished through the Console, `gcloud` CLI, Terraform, or various programming languages like Go, Java, Node.js, and Python, utilizing the provided code examples."],["Custom VMs have a 5% premium on pricing over predefined types, and this premium also applies to commitment usage, local SSD disks prevent any CPU or memory changes."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4