It’s known as ‘lane splitting’ and is illegal in some US states and in some other countries, so check before you ride there. It’s legal in the UK and known as ‘filtering’.
However it is illegal to use the hard shoulder on a dual carriageway or motorway. It is recognised as hazardous, and you should only filter in slow moving or stationary traffic at no more than 10 mph.
Filtering also means overtaking a single line of slow moving or stationary traffic, and is also hazardous and also needs to be done with great care.
You need to be aware that some drivers can react aggressively and try and block your progress, and most will not be aware of you until you are past.