Second the original wires removed from the old box will not be long enough to connect directly to the recessed fixture so you will have to install a junction box inside the ceiling.
Install recessed lighting junction box.
Run nm b cable from the power source to a switch box and then to the first hole allowing at least 18 inches of extra cable to make wiring easy.
If you have an existing light fixture that you are replacing disconnect it before you begin the process of how to wire recessed lights.
Take care to avoid damaging wires which can sometimes have a short span making it more challenging to install a new housing.
It is often necessary to use a saw to cut the junction from the joist to which it is attached.
This rule is demonstrated nicely by wall switches receptacles and standard light fixtures all of.
Remove the old light fixture and then remove the junction box in the ceiling above it.