What HSN and SAC codes are
HSN, the Harmonised System of Nomenclature, is the international system that classifies goods. SAC, the Services Accounting Code, classifies services under GST. The code decides which GST rate applies to what you sell, and it must appear on your tax invoices and in your GST registration.
How many digits to use
Businesses with turnover up to ₹5 crore generally show four digits of the HSN code on business-to-business invoices, and those above ₹5 crore show six. Exports and imports use eight digits. Check the current notification for your case.
Where the list comes from
The codes come from the HSN and SAC master list published on the GST portal, through the open gst-master-data project (MIT licence). It gives codes and descriptions, not tax rates.