The word "gerrymander" was first used in the Boston Gazette on March 26th, 1812. It referred originally to the procedure by which electoral districts are redrawn to benefit the party in charge of the redistricting. Governor Elbridge Gerry of Massachusetts signed a bill that altered the district boundaries for the state senate election to the benefit of his own party. One of the districts had such a contorted shape that it was said to resemble a salamander. The paper christened it a "Gerry-mander." The hyphen was later dropped, and the word came to be used both as a noun and a verb.
There are two principal ways of altering boundaries to make elections unrepresentative of overall support. One is called "cracking," and involves setting boundaries that give one side a modest majority in every district. Thus, an area with 10 districts, where support is split 60-40, can be gerrymandered so that the larger party wins every seat by a similar margin, leaving the 40% without any seats at all.
The second is called "packing," and involves arranging it so that all of the minority party is concentrated in one district. They could win this with a huge majority, but lose all the other seats. In both cases the boundaries are set so that large numbers of opposing votes are wasted. California redrew its district lines to favour incumbents, so that only one seat changed hands in 10 years. A 2010 referendum entrusted an independent body called the California Citizens Redistricting Commission to redraw the boundaries more fairly. The result has been to give California several 'swing' districts in which the incumbent might be defeated. For the US as a whole, though, the proportion of incumbents returned to the House rarely dips below 90% and is often 98%.
Although gerrymandering originally referred to redistricting malpractice, the word has broadened to include other types of electoral fixing that, although legal, are designed to deprive some electors of representation. In the UK there is an independent review of Westminster constituencies that tries to keep roughly the same number of voters per constituency, with exceptions made for the more lightly populated areas of Scotland and Wales. While a party cannot set boundaries, it can vote not to implement a review before an election if it thinks it will lose out. The last review, which recommended cutting the Commons from 650 to 600 seats, has yet to be implemented because the Labour and Liberal-Democrat parties voted to postpone it, standing to lose more seats than the Tories.
The basic lesson to be learned from all of this is that politicians will gerrymander to their advantage if they can, and that independent bodies set outside the political process should be the arbiters of what are fair and reasonable constituency boundaries, and what count as legitimate tactics. Even this is no guarantee, however, as the UK’s Electoral Commission has shown. Charged with ensuring a fair vote in the 2016 EU referendum, it has been visibly and heavily biased towards the Remain side, pursuing alleged breaches of spending rules by the Leave side, while ignoring or glossing over those committed by the Remain campaigners. The behaviour of this supposedly impartial body could be interpreted under the broad definition as gerrymandering.