This principle is based on the techniques used for the migration of molecules, this process is performed in a kind of box which has a charge with a positive end on one side and a negative charge on the other side, when placed inside a charged molecule, it moves following a specific pattern, that is, if the molecules have negative charge they will migrate to the positive charge, but on the contrary if it is positively charged as it will move to the negative side.
When you analyze the proteins in a gel you take the whole protein to see how big it is, meeting the next principle that the shorter, the more they migrate into the gel, so that the small proteins will end up at the bottom of the gel, because they’ve gone further, and the larger ones will end up staying at the top. But in the case of DNA, we work with a very long molecule, so scientists opt to cut DNA with things like restriction enzymes, making DNA more manageable into smaller pieces, then depending on how big they are, they migrate more or less through the gel and end up higher or lower.