A switch breaks up collision domains and is a single broadcast domain. So how about breaking the single broadcast domains into multiple ones? VLAN (Virtual LAN) makes this possible and on a single switch we can have multiple broadcast domains. But once you create multiple VLANs on a switch, it becomes tedious to replicate the same configuration on all the other switches. This is where VTP (VLAN Trunking Protocol) comes in. So we have multiple switches with different VLANs and VTP, making management easier. But how do we make a device in one VLAN communicate with a device in another VLAN? We'll cover this in InterVLAN routing.
VLAN is a technology used to partition a single layer 2 network into multiple broadcast domains. This is done to restrict communication between devices that share the same broadcast medium. However, these devices can communicate with one another through a layer 3 device, such as a router. This is similar to connecting devices to different switches and then connecting them all to a router to separate broadcast traffic.
As more and more VLANs are created, it becomes tedious to replicate the configuration across all switches, which was why VTP was created.
We'll first learn about creating VLAN and assigning ports to it. VLAN 1 is created by default on all switches, and all ports reside in it. This VLAN is called the management VLAN.
To create a VLAN, use the following command:
Sw1(config)#vlan 2
The VLAN ID can be between 1 and 1001. The IDs 1002, 1003, 1004, and 1005 are reserved. Once this command has been entered, you are taken to the VLAN subconfiguration mode. This is the place where we can assign a name to the VLAN.
Sw1(config-vlan)#name finance
Assigning a name to a VLAN is optional; by default, the name is VLAN0002. Next, we will assign a few ports to this VLAN. To assign many ports to a single VLAN, the range command can be used, which then selects multiple interfaces.
Sw1(config)#interface range f0/10-20
To assign these ports to VLAN 2, use the following command:
Sw1(config-if-range)#switchport access vlan 2
Let's verify if the ports were indeed assigned to the correct VLAN.
Sw1#show vlan

Note that in the above example, some of the output has been omitted for brevity.
We will now create a topology with three switches to demonstrate VTP. VTP has three modes: server, client, and transparent.
The following topology will be used for demonstration:

VTP-Server(config)#interface Fa0/1 VTP-Server(config-if)#switchport mode trunk VTP-Transparent(config)#interface range Fa0/1-2 VTP-Transparent(config-if-range)#switchport mode trunk VTP-Client(config)#interface Fa0/1 VTP-Client(config-if)#switchport mode trunk
VTP-Server(config)#vtp domain My-Office Changing VTP domain name from NULL to My-Office VTP-Server(config)#vtp password s3cRet Setting device VLAN database password to s3cRet
VTP-Transparent(config)#vtp mode transparent
VTP-Client(config)#vtp mode client
VTP-Client(config)#vtp password s3cRet
The configuration is done; now, use the show vlan command on the VTP-Client switch to see the new VLANs. This example is only to demonstrate VTP. This topology won't allow normal communication between VTP-Server and VTP-Client, as the switch in the middle (VTP-Transparent) doesn't have any of the VLANs we configured.