Restriction enzymes function like a primitive immune system. Bacteria use these enzymes to cut DNA from foreign sources, like the viruses that infect them (called bacteriophage). The cut DNA can't be used to make new bacteriophage, so while the virus may kill one bacterial cell, the culture of bacteria as a whole will be spared. Bacteria refrain from cutting their own DNA by modifying it, usually by methylating it, so that it is not a substrate for the restriction enzymes.
Molecular biologists use restriction endonucleases (the term endonuclease means that the enzyme cuts nucleic acids in the middle of a molecule rather than from one end) to cleave DNAs because these enzymes cut only DNA, and more importantly, only at particular short sequences in the double helix. The most useful enzymes are the so‐called Type II restriction enzymes that cut double‐stranded DNA at short palindromic sequences ( palindromes are sequences that read the same in the 5′ to 3′ direction). For example, the enzyme EcoRI (from certain strains of the bacterium E. coli) cleaves DNAs at the sequence 5′ GAATTC 3′, which is the same when read on the opposite strand. EcoRI endonuclease cuts this sequence on both strands, between the G and the first A (the phosphate of the phosphodiester bond goes to the 5′ position of the A). After the two pieces of DNA separate, the 5′ pAATT portion of each piece is single‐stranded. These single‐stranded tails are called cohesive ends. Other Type II restriction enzymes generate blunt ends by cutting in the middle of the palindrome. For example, the enzyme SmaI (from the bacterium Serratia marcescans) cuts DNA in the middle of the sequence 5′ CCCGGG leaving two strands with blunt ends.
Bacteria defend themselves from their own restriction enzymes by methylating their DNA. For example, the EcoRI methylase adds a single methyl group to the amino group of the second adenine of the recognition sequence. Methyladenine at this site on either one of the DNA strands is sufficient to prevent the cleavage of the DNA at this site by the EcoRI endonuclease.