The American system of representative democracy rests primarily on the concept of equal representation in legislative bodies. This means using some mechanism that ensures that each member of such lawmaking bodies represents approximately the same number of people.
On the national level, equal representation is required only for the House of Representatives (every state is apportioned exactly two seats in the U.S. Senate). Additionally, all of the state legislatures require that the seats are apportioned to districts having roughly the same population.
How do we ensure equality of representation? We do this by counting periodically every ten years in the decennial census of the population all of the people in every state, in every county, and on every street. Then we (rather, our elected representatives in the state legislatures) redraw the lines of the congressional and the state legislative districts within each state.
Of course, the state legislatures must follow all of the rules established by the U.S. Constitution and their respective state constitutions regarding how such districts can be drawn. The problem is that there aren't very many rules that must be followed. And the ones that do exist aren't very detailed. This opens the door to considerable, let us say, creativity (some call it gerrymandering) when drawing the shapes of congressional and state legislative districts.