This article is from the Star Trek Tech FAQ, by Joshua Bell inexorabletash@hotmail.com with numerous contributions by others.
Replicators are based on transporter technology. A sample object is
first "scanned" into the memory of a computer. Because even a simple
object takes up an enormous amount of memory, the object is only
resolved at a molecular level, not a quantum level. Further, the data
must be compressed using a lossy algorithm, meaning that small,
undetectable approximations are made to the data. This gives the
computer a pattern to create a duplicate of the original. (TNG TM)
Starships have a small supply of bulk material that is constantly
recycled into needed materials and items. When a request is made at a
replicator terminal, the wave-guide conduit system on the ship relays
a small amount of bulk material to the replicator, which uses it to
create the materials called for in the pattern. The object is then
beamed in at the terminal.
 
Continue to: