A restriction enzyme is a protein that recognizes a specific, short nucleotide sequence and cuts the DNA only at that specific site, which is known as restriction site or target sequence.
More than 400 restriction enzymes have been isolated from the bacteria that manufacture them. In live bacteria, restriction enzymes function to defend the cell against invading viral bacteriophages. Restrictions sites in the viral genome (a "happy accident" of nature, as far as the bacteria are concerned, since they don't appear to have any specific function in the virus) are cleaved by the bacterium's restriction enzymes, fragmenting and destroying the DNA of invading bacteriophages before it can incorporate into the host's genome and take over the cell.
A bacterium is immune to its own restriction enzymes, even if it has the target sequences ordinarily targeted by them. This is because the bacterial restriction sites are highly methylated, making them unrecognizable to the restriction enzyme.
Isn't evolution fantastic?
By cutting open vector DNA with the same with restriction enzymes used to cleave the target DNA, complementary "sticky ends" are created. This fosters the insertion of the target DNA into the vector:
Here's another artist's conception of how this works. (Notice the "sticky ends.")