When creating Inter-VLAN Routing environments via Router-on-a-Stick method, why do we have to encapsulate sub-interfaces with dot1q vlan-number? What does that dot1q do and why do we have to type the same number as VLAN number?
In order to have a router actually route anything, it should be connected to at least two network interfaces; so, without VLAN trunking, you would need a router with at least two Ethernet ports, connected to two switch ports assigned to different VLANs, in order to route traffic between them.
VLAN trunking is the practice of having Ethernet frames from two or more VLANs flowing through a single physical port and cable, thus allowing the router to talk to two or more VLANs without actually needing a physical port for each one of them.
DOT1Q (actual name 802.1q) is a protocol for transmitting VLAN informations together with Ethernet frames, which are then called "tagged" frames, because each frame brings a VLAN tag with it, telling the receiving device "this frame belongs to VLAN X"; there are other protocols which can do similar things, but DOT1Q is the most commonly used one.
On Cisco devices, this is handled through sub-interfaces: you have a single Ethernet interface, let's say
VLAN trunking is used whenever you need to carry several VLANs together on a single physical Ethernet connection; oher common uses are connections between switches or to virtualization hosts.