The short answer: You probably don't need a visa to enter Hong Kong. If you're from the UK, you can stay for 180 days visa-free. If you are from the US, EU, Australia and a whole list of other countries you can stay for 90 days visa-free.
Hong Kong Visas Explained
In long, Hong Kong maintains a separate and independent immigration system from mainland China. You'll also need a separate visa to go to Macau. There are border checks when traveling between mainland China and Hong Kong, and also between Hong Kong and Macau.
It's much easier to go to Hong Kong since you don't have to apply for a visa ahead of time but if you are planning a trip to enter Hong Kong from mainland China, then re-enter mainland China, make sure you have a multiple-entry Chinese visa.
You should know that all visitors (regardless of whether visa-free or not) may be required to show evidence of a confirmed onward booking. Basically, just make sure you have a departure ticket, whether by plane, train, or boat.
Once You Arrive in Hong Kong What Happens?
As you arrive in Hong Kong (probably by plane) all visitors must complete an arrival card to clear immigration.
Also know, your passport/travel document will not be stamped on arrival or on departure. Instead, you will receive a landing slip when you clear immigration control. It states the last date and the conditions of your permitted stay in Hong Kong. DO NOT LOSE THIS. You need it to leave.
You should keep this landing slip during your stay in Hong Kong as proof that you are staying legally. Again, I was told not to lose this slip (hence the all caps warning) as you need to it leave, but I wasn't asked for it upon exit.
How to Obtain a Visa For Travel to Mainland China
In the Hong Kong Airport, you can find the China Travel Services HK (CTS) office in the arrivals area. They can process visas to China on the spot. A photograph will be required.
Another way to obtain a visa, and often times the cheapest way is to apply for one at the Commissioner's Office of the Chinese Foreign Ministry in Hong Kong. A single-entry visa costs HKD200 (around $25) and a double-entry visa costs HKD300 (around $38). Do be aware that it takes 4 working days to be issued.
Visiting Macau While in Hong Kong
Macau is only 60 kilometers away and makes an excellent side trip while in Hong Kong. They do run under a different visa system so there are some things you should know.
If you are a resident of the EU, UK, US, or Canada the process is extremely similar to entering Hong Kong. There is no stamp but you will receive a landing slip. Don't lose it. Tourist visas last a period of 30-180 days depending on which country your passport is from.
Also, even though the money is different (Macau uses Macanese Patacas) you can use Hong Kong Dollars virtually everywhere. You will also receive change in HK Dollars making visits quite simple.
Can You Overstay Your Visa to Hong Kong?
NO. Don't do it. Seriously no.
Overstaying is a serious offense - you can be fined up to $50,000 and/or imprisoned for up to three years.
One last thing... even though researching ahead of time is great, I definitely recommend bringing a guidebook along with you.
Lonely Planet Pocket Guides are my absolute favorite because, as the name suggests, they are tiny enough to fit in a pocket or a small bag while still giving you a ton of information. But, here are some other books I recommend as well...
And of course, if you have any questions DO NOT hesitate to reach out to me via Instagram, Twitter, or just shoot me an email (firstname.lastname@example.org).