I not sure whether you check this wiki site before ... but its giving a very clear view on how DP its elected.
its help me last time while me myself also lost on this concept, hope now its help you as well.
Refer to below link for backup port and Alternate port defination.
keep in mind "backup port = using shared connection (HUB)" "Alternate port = using P2P connection (switch)"
The port is going to be elected if it has the lowest cost to the root bridge. If all paths cost the same (gigethernet) then the tie will be broken by the switch with the lowest MAC address. I.E. 1111.1111.11111 will win over 1111.1111.1112, this usually is the oldest switch between the two and may not be the one you want to win so you must manually change it.
Thought I would add.
Most of the manuals and guides say that the DP will be the port that has the lowest cost to the root and if there are equal costs, then the lowest bridge id.
But they do not go onto how this is actually achieved.
All the switches blast BPDU's onto the segment every 2 seconds the BPDUs contain the accumulated root cost for the port.
So every port that recieves a superior BPDU on the segment will know that it is not the best and block. This will leave one switch that did not receive a superior BPDU in the forwarding state.
If you look at the BPDU frame format you will see that
Root path cost, bridge id, port id are all grouped together to make one giant 14 byte number (in order of significance). Which ever switch has the lowest binary value of this agregrate number is the winner and the DP. Each switch will block its port in response to a higher value that it has itsself.
Wendel Odom wrote in ICND2:
(3) Many switches can attach to the same Ethernet segment. The switch with the lowest administrative cost from itself to the root bridge, as compared with the other switches attached to the same segment, is placed in Forwarding State. The lowest-cost switch on each segment is called the designated bridge, and that bridge’s interface, attached to that segment, is called the designated port (DP).
Richard Deal wrote (CCNA, ch 14, Osborne, 2008):
The third step in running STP is to elect a designated port on a single switch for each segment in the network. The switch (and its port) that is chosen should have the best path to the root switch. Here are the steps taken by switches in determining which port on which switch will be chosen as the designated port for a particular LAN segment.
1. The connected switch on the segment with the lowest accumulated path cost to the root switch will be used.
2. If there is a tie in accumulated path costs between two switches, the switch with the lowest switch ID will be chosen.
3. If it happens that it is the same switch, but with two separate connections to the LAN segment, the switch port with the lowest priority is chosen.
4. If there is still a tie (the priorities of the ports on this switch are the same), the physically lowest numbered port on the switch is chosen.