> 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/legacy/vm/classic-network/createsubnet.md).

# CreateSubnet

## 1. API Description

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

#### Prerequisites

Before creating a subnet, you can call `DescribeSubnetAvailableResources` to check the available zones.

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

* <mark style="color:blue;">Subnet quota is limited. If you need more, please contact Zenlayer Support.</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 call</mark> [<mark style="color:purple;">`DescribeSubnets`</mark>](/api-reference/legacy/vm/classic-network/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;">`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                                                                                                                                                                                   |
| ----------------- | -------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| cidrBlock         | Yes      | String | <p>CIDR block of the subnet. The optional values are as follows:</p><p>10.0.0.0/24, 172.16.0.0/24, 192.168.0.0/24 and their subsets.</p><p>The subnet IP ranges cannot be overlapped.</p>     |
| subnetName        | Yes      | String | <p>Subnet name to be displayed.</p><p>This parameter must start and end with a number or a letter, containing 2 to 63 characters. Only letters, numbers, - and periods (.) are supported.</p> |
| zoneId            | Yes      | String | Zone ID of subnet.                                                                                                                                                                            |
| subnetDescription | No       | String | Subnet description.                                                                                                                                                                           |

## 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 FRA-A.**

```json
POST /api/v2/vm HTTP/1.1
Host: console.zenlayer.com
Content-Type: application/json
X-ZC-Action: CreateSubnet
<Common Request Params>

Request:
{
  "zoneId": "FRA-A",
  "cidrBlock": "10.0.0.0/20",
  "subnetName": "subnetXXX",
  "subnetDescription": "subnetXXX Description"
}

Response:
{
  "requestId": "TBFC01FCF-6439-4530-ADBC-16809F0C3E8F",
  "response": {
    "requestId": "TBFC01FCF-6439-4530-ADBC-16809F0C3E8F",
    "subnetId": "914862014017316658"
  }
}
```

{% 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                                                            |
| ---------------- | ----------------------------------------------------------- | ---------------------------------------------------------------------- |
| 500              | CREATE\_SUBNET\_FAILED                                      | Creating failed.                                                       |
| 400              | UNSUPPORTED\_OPERATION\_SUBNET\_BIND\_NETWORK\_COUNT\_LIMIT | Subnet quantity is limited.                                            |
| 400              | UNSUPPORTED\_OPERATION\_CIDR\_BLOCK\_IS\_EXIST              | Overlapped IP ranges. Please check whether the same CIDR block exists. |
| 400              | INVALID\_CIDR\_BLOCK\_FORMAT                                | CIDR block format error. Please note whether it is IP/netmask format.  |
| 400              | INVALID\_CIDR\_BLOCK\_NETMASK                               | Invalid CIDR netmask.                                                  |
| 400              | INVALID\_CIDR\_BLOCK\_NOT\_LAN\_IP                          | CIDR block is not a private CIDR.                                      |
| 400              | INVALID\_CIDR\_BLOCK\_INVALID\_INTERNAL\_IP                 | Invalid private CIDR block.                                            |
| 400              | INVALID\_REGION\_NOT\_ON\_SALE                              | Not for sale in the zone.                                              |
