> For the complete documentation index, see [llms.txt](https://docs.console.zenlayer.com/api-reference/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.console.zenlayer.com/api-reference/compute/bmc/vpc/subnet/createsubnet.md).

# CreateSubnet

## 1. API Description

This API (CreateSubnet) is used to create a subnet.

#### Prerequisites

Before creating a subnet, call [`DescribeSubnetAvailableResources`](/api-reference/compute/bmc/vpc/subnet/describesubnetavailableresources.md) to check the zones available for subnet creation.

{% hint style="info" %} <mark style="color:blue;">**Note**</mark>

* <mark style="color:blue;">The quantity of subnets you can create in one zone is limited. If you need more, please contact Zenlayer Support.</mark>
* <mark style="color:blue;">Create a subnet separately if you need a Layer 2 network; create subnets in a VPC if you need a Layer 3 network. You are recommended to create subnets in a VPC because they can communicate with each other. You can also create a subnet separately and then upgrade it into a VPC.</mark>
* <mark style="color:blue;">This API is an async API. A subnet ID list is returned after the creation request is sent. However, it does not mean the creation has been completed. The status of the subnet will be</mark> <mark style="color:blue;">`CREATING`</mark> <mark style="color:blue;">during the creation. You can use</mark> [<mark style="color:blue;"><mark style="color:purple;">`DescribeSubnets`<mark style="color:purple;"></mark>](/api-reference/compute/bmc/vpc/subnet/describesubnets.md) <mark style="color:blue;">to query the status of the subnet. If the status changes from</mark> <mark style="color:blue;">`Creating`</mark> <mark style="color:blue;">to</mark> <mark style="color:blue;">`Available`</mark><mark style="color:blue;">, it means that the subnet has been created successfully;</mark> <mark style="color:blue;">`CREATE_FAILED`</mark> <mark style="color:blue;">means the subnet has been created failed. Any operations on the subnets are not allowed while creating.</mark>
  {% endhint %}

## 2. Input Parameters

The following request parameter list only provides API request parameters.

| Parameter Name  | Required | Type   | Description                                                                                                                                                                                                                                                                                                                                            |
| --------------- | -------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| zoneId          | Yes      | String | Zone ID to which the subnet belongs.                                                                                                                                                                                                                                                                                                                   |
| cidrBlock       | Yes      | String | <p>CIDR block of the subnet. The optional values are as follows:</p><p>10.0.0.0/16 , 172.16.0.0/16 , 192.168.0.0/16 and their subsets.</p><p>If the subnet is going to be added into a VPC, the value should be in the range of VPC CIDR block and not overlap with IP ranges of other subnets in this VPC.</p>                                        |
| subnetName      | Yes      | String | <p>Subnet name to be displayed.</p><p>This parameter can contain up to 64 characters. Only letters, numbers, - and periods (.) are supported.</p>                                                                                                                                                                                                      |
| resourceGroupId | No       | String | <p>Resource group ID.</p><p>If the value is not passed in, the subnet will be put into the default resource group. If no authorized default resource group found, the request will fail.</p><p>If the subnet is going to be added into a VPC, this parameter will be ignored. The created subnet will be added into the resource group of the VPC.</p> |
| vpcId           | No       | String | VPC ID.                                                                                                                                                                                                                                                                                                                                                |

## 3. Output Parameters

| Parameter Name | Type   | Description                                                                                                           |
| -------------- | ------ | --------------------------------------------------------------------------------------------------------------------- |
| requestId      | String | <p>The unique request ID, which is returned for each request.</p><p>RequestId is required for locating a problem.</p> |
| subnetId       | String | Subnet ID.                                                                                                            |

## 4. Code Example

{% tabs %}
{% tab title="Example" %}
Create a subnet in zone `SIN-B`.

<pre class="language-json"><code class="lang-json"><strong>POST /api/v2/bmc HTTP/1.1
</strong>Host: console.zenlayer.com
Content-Type: application/json
X-ZC-Action: CreateSubnet


Request:
{
  "zoneId": "SIN-B",
  "cidrBlock": "10.0.0.0/16",
  "subnetName": "Subnet-Test-alict"
}

Response:
{
  "requestId": "T39EC84B4-63B4-409E-A09D-F052434DF276",
  "response": {
    "requestId": "T39EC84B4-63B4-409E-A09D-F052434DF276",
    "subnetId": "832999436413042904"
  }
}
</code></pre>

{% endtab %}
{% endtabs %}

## 5. Developer Resources

Zenlayer Cloud API 2.0 integrates [SDKs](/api-reference/api-introduction/toolkit/api-sdk.md)，to make it easier for you to call APIs. More programming languages will be supported.

## 6. Error Codes

The following only lists the error codes related to the API business logic. For other error codes, see [Common Error Codes](/api-reference/api-introduction/instruction/commonerrorcode.md).

| HTTP Status Code | Error Code                                          | Description                                                        |
| ---------------- | --------------------------------------------------- | ------------------------------------------------------------------ |
| 403              | OPERATION\_DENIED\_VPC\_ZONE\_SUBNET\_EXCEED\_LIMIT | Quantity of subnets exceeds the limit of the zone.                 |
| 403              | OPERATION\_DENIED\_SUBNET\_EXCEED\_LIMIT            | The number of availability zones for the subnet exceeds the limit. |
| 404              | INVALID\_ZONE\_NOT\_FOUND                           | Zone not found.                                                    |
| 400              | INVALID\_PARAMETER\_SUBNET\_CIDR\_NOT\_BELONG\_VPC  | The subnet IP range does not belong to the VPC IP range.           |
| 403              | OPERATION\_DENIED\_NO\_AVAILABLE\_VPC\_REGION       | Invalid availability region ID of VPC.                             |
| 403              | OPERATION\_DENIED\_ZONE\_NOT\_BELONG\_VPC           | Zone of subnet does not belong to the availability region of VPC.  |
| 400              | INVALID\_PARAMETER\_SUBNET\_LAN\_IP                 | CIDR block is not within a private network range.                  |
| 404              | INVALID\_VPC\_NOT\_FOUND                            | VPC not found.                                                     |
| 400              | INVALID\_PARAMETER\_SUBNET\_CIDR\_BLOCK             | Invalid CIDR block format.                                         |
| 403              | OPERATION\_DENIED\_VPC\_STATUS\_NOT\_SUPPORT        | VPC status not supported.                                          |
| 400              | INVALID\_PARAMETER\_VPC\_SUBNET\_OVER\_LAP          | Overlapped CIDR blocks of subnets in VPC.                          |
| 400              | INVALID\_PARAMETER\_SUBNET\_LAN\_IP\_NETMASK        | Invalid CIDR block netmask range.                                  |
| 403              | OPERATION\_DENIED\_ZONE\_NOT\_SUPPORT\_SUBNET       | The availability zone does not support creating subnets.           |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.console.zenlayer.com/api-reference/compute/bmc/vpc/subnet/createsubnet.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
