Perhaps the easiest way to learn how and when to use the preposition off is to understand it as the opposite of on. While on shows a connection, off instead expresses a disconnection. For example, in the picture below, there is a cat visible, in contact with, and being supported by a tree. Therefore the cat is on the tree. Now, if that cat were to jump, it would no longer have any connection to the tree, therefore it would be off it:
This concept of disconnection, or the idea of someone or something being removed or separated from another thing, is the recurring theme in the various uses of off. For example, if you were opening a jar, you would need to take the lid off, or in other words, separate the lid from the jar.
If there was a sale in your favourite store, you might see a sign saying, "£50 off!" That means that £50 has been removed from the original price.
If you were sick, you might say, "I took ten days off work." That means you had ten days in which you were disconnected or separated from work.
If you turned on something like a light switch, or a computer, that means you used a switch or button to establish a connection with the light or computer. Turning them off disconnects you from them. See how these two prepositions relate to this flashlight:
If you were exiting a train, you would be removing yourself from it: therefore you would be getting off the train. In this context, it is important to note that we use on when referring to travelling on something large enough to be shared with other people, such as a bus, train or plane; and so off is applied to describe exiting them. However, we use in when referring to travelling in something smaller and more personal, such as a car; and so in that case we would say, "I got out of the car", rather than off it - as out is the opposite of in.