By explaining and asking, then writing it down. Before any prescription, test or referral the doctor tells you what it is for, the main risks and side effects, the realistic alternatives including doing nothing, and what happens if you decline. For most things, telling the doctor you agree is enough; your agreement, and anything you decline, is recorded in your clinical record. You can withdraw consent at any time, and doing so never affects the care you are offered in future.
A child under 16 is seen with a parent or someone with parental responsibility present, who consents on the child's behalf, unless the doctor judges the young person able to understand and decide for themselves. From 16, young people consent for themselves. If an adult may not be able to make a particular decision, the doctor follows the Mental Capacity Act 2005 and acts in their best interests, involving the people they would want involved. Our Consent page explains it all.