How does pre-clearance for traveling to the US work and what is required?

How does pre-clearance for traveling to the US work and what is required?