Gerrymandering has its foundations in the arrangement of voting districts by local and State legislative bodies. For clarity, I'll limit this discussion to the example of elections within a State for the members in the State legislature.
Obviously, the everyone eligible to cast a vote within a State do not, as a body, vote for each and every member of the legislature. Each member of a State legislature is elected by and, ideally, represents the voters within a district - a portion - of the State. As such, States are subdivided, for the purpose of elections, into districts, each of which sends one or more representatives to serve in the State legislature.
Although there are exceptions, in most of the fifty States it is the State legislature that determines the boundaries of the voting districts. Boundaries are usually re-drawn after a new census of the population has been taken (this is because the results of a new census usually reflect changes in the composition of the population within a State's voting districts).
Gerrymandering is the drawing of the boundaries of a State's voting districts in such a way that it favors a particular political party. To give a simple example of Gerrymandering, lets say that in a particular State, sixty percent of the registered voters are members of the Democratic party, while forty percent of the registered voters are members of the Republican Party. Under these circumstances, without Gerrymandering, sixty percent of the elected representatives in the legislature of the State in question should be members of the Democratic Party, while forty percent of the legislature's members should be Republicans. In other words, because the majority of voters in the State are registered Democrats, the majority of the members of the State legislature are also Democrats, so that Democrats, as the majority party, pass legislation favored by Democrats (majority rule).
However, lets say the majority of the elected representatives in the legislature of the State in question are Republicans. With control over the State legislature, the Republican members have control over the drawing of the boundaries of the State's voting districts. With the majority of registered voters in the State set to vote to elect Democrats to the State legislature, the Republicans are practically guaranteed to loose control of the State legislature in the next election.
However, if the Republican majority in the State legislature draw the boundaries of the voting districts in such a way that most or all of the State's Democratic voters are contained in a small number of districts - lets say ten, compared with the State's Republican voters, who are contained in a larger number of districts - lets say twenty districts - and each of these districts will elect one representative to serve in the State legislature, then the Republican party will have ensured its continuing majority in the State legislature (and, thus, its continuing control over the redrawing of the boundaries of voting districts). Even though sixty percent of the registered voters in the State in question are registered Democrats - in other word, registered Democrats outnumber registered Republicans - only ten Democratic representatives will be elected to the State legislature under the circumstances I've described, while twenty Republican representatives will be elected to the State legislature, so that Republicans will have a two-to-one majority in the legislature.
Of course, the example I've outlined is a simple illustration, intentionally crude for the purposes of clarity. Actual examples of gerrymandering are usually far more subtle. Needless to say, gerrymandering is a means of subverting one of the basic features of democracy itself, majority rule. As such, gerrymandering is fundamentally anti-democratic.