When a switch generates a Bridge Protocol Data Unit (BPDU) out of its interfaces, the total path cost only includes the path to the root excluding the interface that the BPDU is advertised out of. It is the switch that receives that BPDU that adds the cost associated with the receiving interface to the total cost of the BPDU
The receiving interface normally has an automated reference cost based on the interface speed, but this can be modified on an individual interface with the interface level command
spanning-tree cost X or on a interface VLAN level with
spanning-tree vlan Y cost X
Costs are important when it comes to deciding which ports are the best path to root and blocked – tweaking them allows these decisions in the topology to be influenced.