Undertaking is the act of passing a slower-moving vehicle on the left hand side or an inside lane, depending on the type of road you are travelling on. As you're supposed to overtake on the right, an undertake carries a significantly higher risk to both pedestrians and unsuspecting drivers.
The most common instance of undertaking is on the motorway due to the frustration caused by middle-lane hogging, though you may also see undertaking performed by impatient motorists on dual carriageways or even more dangerously, residential streets. Some instances of overtaking are perfectly acceptable, such as undertaking if the vehicle in front of you is signalling to turn right, but undertaking is mostly synonymous with road rage or impatience.
This is split in to two separate categories in the Highway Code, varying on the type of road that you are using.
The highway code states two exceptions for undertaking on standard roads:
As for motorways, there are two rules:
Whilst the Highway Code instructs motorists not to undertake, you do have to pay close attention to the wording. Whenever the Highway Code refers to something legislative, the wording "must" and "must not" is used to indicate that you are legally obligated to follow a particular rule.
Looking at the rules stated above, the wording "Do not" is used to describe the act of undertaking, which indicates that undertaking in itself is not illegal, but that doesn't mean that performing an undertake cannot contribute to a prosecution for an offence such as dangerous driving or driving without due care and attention, so in a round-about way, undertaking is technically illegal.
It's rare that a cyclist would undertake a moving vehicle whilst both are travelling at speed, however when a cyclist passes a vehicle, this is described as filtering. Ideally, filtering is only done when traffic is stopped, otherwise it's generally advised that they overtake cars on the right, but cyclists are hesitant to do this due to the increased risk in manoeuvring. Another hazard cyclists must be wary of when undertaking / filtering is being crushed by HGVs, which typically happens when setting off after a traffic light change.