# Create a VPC and subnets

Create a VPC with the CLI, add subnets to it, and choose whether instances launched into each subnet get a public IPv4 address automatically.

Create your own VPC when you want to choose its address range or control which subnets reach the internet. A new VPC comes with a first subnet, so you add subnets only when you need more than one.

## Before you begin [#before-you-begin]

<BeforeYouBegin>

- The `origin` CLI, signed in. See [CLI access](/docs/platform/access/cli).
- The URN of the project to create the VPC in.
- If you want your own IPv4 range, a private range between `/16` and `/28`. See [VPC and subnet addressing](/docs/network/vpcs/addressing) for how the range sets the subnet size.

</BeforeYouBegin>

Creating VPCs and subnets doesn’t require a payment method.

## Create the VPC [#create-the-vpc]

1. Create the VPC. Pass `--ipv4-cidr` to choose the IPv4 range, or leave it out to get a random `/16` from `172.16.0.0/12`.

   ```sh
   origin network create-vpc --project-urn <project-urn> \
     --ipv4-cidr 10.0.0.0/16
   ```

1. Note the VPC’s URN from the output, and find its first subnet:

   ```sh
   origin network list-subnets --project-urn <project-urn>
   ```

1. Verify the VPC with `get-vpc`. Its `ipv4Network` shows the range and the subnet size.

   ```sh
   origin network get-vpc --vpc-urn <vpc-urn>
   ```

The VPC has no Internet Gateway. To give it internet access, see [Internet access](/docs/network/internet-access).

## Add a subnet [#add-a-subnet]

1. Create the subnet. `--auto-assign-public-ip` is required: `true` gives every instance launched into the subnet a Floating IP automatically, `false` doesn’t.

   ```sh
   origin network create-subnet --vpc-urn <vpc-urn> \
     --auto-assign-public-ip false
   ```

   The platform picks the subnet’s ranges from the VPC. If the VPC has no room left, the command is refused; see [When address space runs out](/docs/network/vpcs/addressing#when-address-space-runs-out).

1. Verify the subnet. Its `ipv4Network`, `ipv4Router` and `ipv4DnsServers` show its range, gateway and resolver.

   ```sh
   origin network get-subnet --subnet-urn <subnet-urn>
   ```

An automatic public IP is only useful if the VPC has an Internet Gateway. For how auto-assigned addresses behave, see [Default VPC](/docs/network/vpcs/default-vpc).

## Change a subnet’s auto-assign setting [#change-a-subnets-auto-assign-setting]

1. Set the new value with `true` or `false`:

   ```sh
   origin network update-subnet-auto-assign-public-ip \
     --subnet-urn <subnet-urn> --auto-assign-public-ip true
   ```

1. Verify that the subnet’s `autoAssignPublicIp` field shows the new value:

   ```sh
   origin network get-subnet --subnet-urn <subnet-urn>
   ```

The change applies only to instances launched afterwards. To give a running instance a public address, associate a Floating IP with its interface; see [Floating IPs](/docs/network/internet-access/floating-ips).

## Next steps [#next-steps]

- [Launch an instance](/docs/compute/instances/launch) into the subnet with `--subnet-urn`
- [Attach and detach an Internet Gateway](/docs/network/internet-access/internet-gateways)

## Related [#related]

- [`create-vpc` reference](/docs/network/reference/cli#create-vpc)
- [`create-subnet` reference](/docs/network/reference/cli#create-subnet)
- [`update-subnet-auto-assign-public-ip` reference](/docs/network/reference/cli#update-subnet-auto-assign-public-ip)

