Junction boxes are used any time multiple wires need to be connected. It is against the National Electric Code to simply use wire nuts and leave the junction exposed. Junction boxes vary in size and shape for different uses, but the overall project is the same.
Determine the size of box you need based on the wire size you wish to join. Junction boxes sold at any home improvement retailer work for home projects.
Mount the box in place with the fasteners provided with it.
Pull the wires into the box leaving 6 inches of each wire hanging out of the box, and then cut off the excess.
Cut away all of the cabling's outer jacket that is visible inside the junction box.
Bring the exposed copper wires together, twist their ends together in a clockwise motion then cover then ends with a wire nut.
Strip away 1 inch of the white wires insulation and then twist and cover with a wire nut. Repeat this process with each color of wire.
Push all of the wires back inside the junction box and seal it with a junction box cover.
Check your local electrical codes to know how many wires you are allowed to join in one junction box. If working with a metal junction box, affix a ground tail to it and then connect this to the other exposed ground wires so the box itself is grounded.
Ensure that the power is off to the area where you are working by switching off the breaker. Not doing this can result in serious injury or death to you and anyone in the building. It is also a good idea to use a voltmeter to check that the power is off before working near any exposed wires. Visually verify that all of the wires are the same gauge before proceeding. Attaching wires of different gauges is a fire hazard.