The extraction buffer contains salts and detergents. The detergents (e.g SDS) solubilise the plasma membrane and other membranous organelles, releasing nucleic acids; and, the salts act as buffering agents to stabilise the pH and osmolarity of the resulting lysate solution.
There are many ways to extract nucleic acids. An example is phenol-chloroform extractions, however these extractions have less pure DNA, take ages and are more prone to contamination since you're transferring your sample through multiple tubes. Also Phenol is a horrendous chemical, it smells so bad (trust me, personal experience as well) and is very toxic - personally i'd avoid! Worth mentioning though that this method is usually the cheapest. Another example is using magnetic beads - where the beads bind the DNA and the tube is placed on a magnetic rack to pellet the bead-bound DNA allowing you to wash the DNA of other contaminants. Only issue, beads are very expensive.
My favourite one tends to be spin-column extractions, these typically have the best yields and are pretty simple and easy to do. Essentially, the columns contain a filter housing silica and salts which can disrupt the hydrogen bonding in the DNA (chaotropic salts). The columns are placed inside normal tubes to allow solutions to 'filter' through. When the lysate is added, the salts disrupt the hydrogen bonds in the DNA (making it hydrophobic) and the DNA binds to the silica. This allows you to then add wash buffers and ethanol to the column to remove ('wash through') any excess salts and other contaminants. Each wash through is done by centrifuging the tubes to force the solution through the filter and into the tube. After each wash, you remove the flow through from the collection tube. Afterwards, you add an aqueous solution to the filter (e.g. nuclease-free water or Tris-EDTA buffer) which rehydrates the DNA, then centrifuge to elute the DNA from the column into the tube. Note: You can get variations of these kits that can bind either DNA or RNA, or both - zymo research and qiagen kits are the ones i've used with the best results.
There's also Chelex extractions, but i've never done them before and they result in ssDNA, usually for PCRs. This is not good for long-term storage.