Airplane lavatories can be a bit tricky to use if you're not used to them. You may also find one of the many videos on YouTube on this topic, such as this one, helpful.
First, the door usually has an indicator, which tells you if it is locked. If it is green and says "vacant" (or the equivalent in a foreign language), the door is unlocked and you may enter. If it is red and says "occupied" (or something with that meaning), the door is locked. The lavatory will be locked when it is in use and may be locked by the crew during takeoff and landing when it is not permitted to be used.
There are two main types of lavatory doors you encounter on typical commercial aircraft:
Free-swinging doors, where one side has hinges and you push or pull on the non-hinged side just like typical home doors. Example (on the left, the door straight ahead is the cockpit). Such doors often have levers: pull the lever all the way down (there is usually an arrow) to unlatch it and it will start to swing, then push or pull the door as directed. Sometimes, you'll find a round knob instead of a lever, as shown in this video; for these, turn the knob all the way to either side to unlatch the door, then push/pull as indicated.
Accordion-style/bi-fold doors. Example 1, Example 2, Example 3. These take up less space, since they don't require a big swinging door, but are a bit more tricky to use. Once you've ensured the door is unlocked, face the door and push or pull on the handle in the middle. It's normally a push to get in from the outside and a pull to exit, but it will be marked with a sign. It may take some force, but the door will collapse in on itself. Once the door has folded inwards, you may push it on the open edge to get a large enough opening to pass through. See this video and the below picture:
When you pull on the indicated area, the door will fold in on itself along the middle hinge, leaving an opening on the right side. To enlarge the opening, place your hand on the now exposed right edge of the door and push the entire door left, further collapsing the door.
Once you're inside, close the door by pushing or pulling it the opposite way you used to open it. Make sure it is pressed all the way shut. Then slide the locking lever (marked with a sign reading "Please Lock Door") as indicated by the arrow. Be sure to slide it all the way. Once you've done so, the lights will become brighter, which is your signal that the door is locked. If you find that you cannot slide the lock, ensure that the door is closed securely and give it a little jiggle--you may need to open and close it again--or ask for help.
When you're inside, do not squat on the toilet. While this is common practice in some cultures, most airplane toilets are not built for that, and you run the risk of breaking something. If you're sitting down, there are often covers (see here, in the wall immediately to the right of the toilet lid) you can place over the seat first.
The toilet lid will have two pieces: a seat and a lid. For those with male anatomy who choose to stand and urinate into the toilet, lift both up. For sitting down, lift just the lid and sit on the seat. When you're done, you might close both. As mts notes in comments, our existing question on How to Use Toilet Paper will help with that operation. We also have a question on How to adapt to Western Toilets from Indian-style toilets?
When you're done, you'll need to flush. There are a few styles of flush mechanisms you may encounter; several are shown in this image, and they were discussed in this blog post. They are normally either a lever that you push down, a button that you press, or occasionally, infrared sensor you wave your hand in front of. Do that, and it will make a pretty loud wooshing noise as it flushes.
There will also likely be a sink. One style has three buttons: hot, cold, and drain. Use the hot/cold buttons to obtain water, then hold down the drain button so it can flow away. You might also find an automatic style where a sensor detects the presence of your hands underneath. For this style, use the buttons to adjust the water temperature as desired. It is courteous to wipe up any water with the towels provided; push them into the trash container--never throw towels or anything besides waste and toilet paper down the toilet.
Other amenities you may find include a diaper changing table, normally above the toilet, towels and tissues, soap, and perhaps a supply of airsickness bags. There will likely be an ashtray built into the door in compliance with safety regulations, but you should never smoke in an airplane lavatory; not only it is a dangerous fire hazard, there are smoke detectors, and you will be caught and may be arrested or fined.
When you're all done, slide the locking lever back the opposite way from when you came in, and reverse the steps to open the door.
Finally, don't be afraid to ask for help. You will not be the first person with these questions and the crew should be happy to help you.
Even more finally, the lavatory will have a call button inside. If you do find yourself stuck in there or in need of assistance, just press the button and a member of the crew will be dispatched to help.