Almost every election question gives the winner's share as a percentage and the winning margin as a number of votes. The trick is to express the margin as a percentage as well.
Margin % = winner's % − loser's % and Total = margin in votes ÷ margin %
With two candidates and only valid votes, the loser's share is 100% minus the winner's.
Worked example 1: two candidates
The winner gets 60% of the valid votes and wins by 1,200. The loser has 40%, so the margin is 20%. Valid votes = 1,200 ÷ 0.20 = 6,000.
Worked example 2: given the loser's share
A candidate polls 35% and loses by 9,000. The winner has 65%, a margin of 30%, so total votes = 9,000 ÷ 0.30 = 30,000.