To separate the proteins according to their size, it needs an artifice which involves associating them with molecules of a charged ionic detergent: sodium dodecyl sulfate (or SDS). Via its long hydrocarbon chain, this detergent forms hydrophobic interactions with the peptide chain of the protein and binds at about one molecule of SDS for two amino acids.
The protein-detergent complex thus formed is highly charged, the numerous negative charges of SDS sulfate groups outweighing the few charges carried by the protein. This gives a complex whose total charge is approximately proportional to the length of the peptide chain and thus the electrostatic force exerted during migration in the presence of SDS becomes proportional to the size of the protein.