You can use masking tape to get a neat edge where different colours meet, such as at the junction of walls and ceilings, or where adjacent walls are different colours. But professionals use a technique called beading, which is not difficult, provided you have a steady hand. The adjacent colour must be dry before you start.
1. Load the brush with a little paint. Turn it edgeon and press it flat against the wall, a short way from the edge, so that the bristles are slightly splayed to create a bead of paint.
2. With a steady hand, draw the brush sideways or downwards along the surface, gradually working right to the edge to give a clearly defined line between the colours.