The entrance of a hive is vulnerable to attack by other bees intent on robbing honey or other insects on the look out for honey or bees to eat. As a result of this... Honey bees have developed a 'guarding' behaviour whereby a small number of bees 'police' the entrance and 'vet' would be entrants.
The numbers of bees involved in this activity varies from zero to a few dozen and is usually carried out by worker bees of between the fourteen and twenty days of age.
The 'guard' bees monitor the entrance and scrutinise any bees or other insects attempting entry. If they are 'recognised' by smell they are allowed to pass unhindered, but if they are deemed a threat they will be 'roughed up' by one or more guards. In cases where the colony bees are more defensive this may lead to stinging of the intruder.
The scuffle of a challenging encounter may impart enough of the smell from the guards to the would be entrant, so that it becomes recognisable and it then allowed entry.
The belligerence of the entrant has some bearing on the response that it is met with... i.e. a wasp may resist the initial roughing up and meet with a stinging response, whereas a straying worker from another colony may be more passive and thus allowed rapid acceptance.
The guarding activity may extend to a region of space surrounding the hive that can be termed a defensive area.
The position and size of the hive entrance can have a bearing on the way it is guarded and the ease of defence... See cold way or warm way.