usually the first part of the barcode tells the manufacturer, and the second part tells the SKU (stock keeping unit) the manufacturer's unique 'part number' for the thing being sold.
the grocer's computer system uses these to reference its own inventory code for the thing and its current price and inventory amount etc.
from Wikipedia for SKU: SKU can also refer to a unique identifier or code, sometimes represented via a barcode for scanning and tracking, which refers to the particular stock keeping unit. These identifiers are not regulated or standardized. When a company receives items from a vendor, it has a choice of maintaining the vendor's SKU or creating its own.[4] This makes them distinct from Global Trade Item Number (GTIN), which are standard, global tracking units. The Universal Product Code (UPC), European Article Number (EAN), and Australian Product Number (APN) are special cases of GTINs.
To put this into real-example terms, when you buy something like a box of name-brand cereal, that will have the same barcode everywhere it is sold in the country, because it's literally printed on the box from the factory, and it is unique by manufacturer so there is no reason to change it.
But when you buy a head of broccoli, the product has come from lots of different farms, and if it has a barcode at all it would be applied by the store themselves when it's prepared for sale. This means Safeway would probably have a different product code for broccoli than Walmart does, but all Safeway stores would use the same for broccoli as they belong to the same chain.
If it's anything like other, non-food distribution, then they'll have their own in-house barcode system that cross-references whatever barcode system was used by the shipper and/or manufacturers (or packers or w/e). It's kind of silly IMO that there's no uniform inventory control system for everything one could possibly buy, sell, exchange, or transfer.
But companies have spent decades putting these systems together piecemeal, often using stupidly expensive proprietary software that doesn't know how to talk to any other software. So they're sure as hell not going to back out on the sunk cost fallacy now and invest in a whole new significantly more efficient system that will save them more money down the road. After all, corporate executives don't plan on sticking around in any one position long enough to bother with long-term planning.
Just little off topic, but I had to look in to it few months ago and there are bunch of shitty resellers that sell individual codes.
It looks like good deal but when you need to put it on more than 10 unique products then it is better to register as manufacturer. The basic tear is ~40€/year and you can create 5000 codes.
And yes at least in EU they are managed by one company that then allocate them to countrys.
Edit: I refer to EAN specifically, shops usually requires them.
I know if I buy something on the international aisle at the grocery store my calorie counter app will read the new barcode label the store put on it, but it won't read the original one on the actual packaging. So I guess they're not worldwide