How does the hepatitis B vaccine protect you against getting hepatitis B?

How does the hepatitis B vaccine protect you against getting hepatitis B?