The negative charge of its phosphate backbone moves the DNA towards the positively charged anode during electrophoresis. However, the migration of DNA molecules in solution, in the absence of a gel matrix, is independent of molecular weight during electrophoresis, i.e. there is no separation by size without a gel matrix. Hydrodynamic interaction between different parts of the DNA are cut off by streaming counterions moving in the opposite direction, so no mechanism exists to generate a dependence of velocity on length on a scale larger than screening length of about 10 nm. This makes it different from other processes such as sedimentation or diffusion where long-ranged hydrodynamic interaction are important.
The gel matrix is therefore responsible for the separation of DNA by size during electrophoresis, however the precise mechanism responsible the separation is not entirely clear.  A number of models exists for the mechanism of separation of biomolecules in gel matrix, a widely accepted one is the Ogston model which treats the polymer matrix as a sieve consisting of randomly distributed network of inter-connected pores. A globular protein or a random coil DNA moves through the connected pores large enough to accommodate its passage, and the movement of larger molecules is more likely to be impeded and slowed down by collisions with the gel matrix, and the molecules of different sizes can therefore be separated in this process of sieving.
The Ogston model however breaks down for large molecules whereby the pores are significantly smaller than size of the molecule.  For DNA molecules of size greater than 1 kb, a reptation model (or its variants) is most commonly used.  This model assumes that the DNA can crawl in a "snake-like" fashion (hence "reptation") through the pores as an elongated molecule.  At higher electric field strength, this turned into a biased reptation model, whereby the leading end of the molecule become strongly biased in the forward direction, and this leading edge pulls the rest of the molecule along.  In the fully biased mode, the mobility reached a saturation point and DNA beyond a certain size cannot be separated.  Perfect parallel alignment of the chain with the field however is not observed in practice as that would mean the same mobility for long and short molecules. Further refinement of the biased reptation model takes into account of the internal fluctuations of the chain.
The biased reptation model has also been used to explain the mobility of DNA in PFGE.  The orientation of the DNA is progressively built up by reptation after the onset of a field, and the time it reached the steady state velocity is dependent on the size of the molecule.  When the field is changed, larger molecules take longer to reorientate, it is therefore possible to discriminate between the long chains that cannot reach its steady state velocity from the short ones that travel most of the time in steady velocity.  Other models, however, also exist.
Real-time fluorescence microscopy of stained molecules showed more subtle dynamics during electrophoresis, with the DNA showing considerable elasticity as it alternately stretching in the direction of the applied field and then contracting into a ball, or becoming hooked into a U-shape when it gets caught on the polymer fibres.  This observation  may be termed the "caterpillar" model. Other model proposes that the DNA gets entangled with the polymer matrix, and the larger the molecule, the more likely it is to become entangled and its movement impeded.