Done correctly, freediving can be a safe activity. Done wrongly, it can be fatal. Below are the most important rules of freediving safety.
Never dive alone
The first rule of freediving safety is to dive with a buddy, aka, never dive alone. Don't practice breath-holding in bodies of water, such as a pool, alone.
Don't hyperventilate before you dive
Hyperventilation has many undesirable physiological effects for freediving and greatly increases the risk of blackout. When getting ready for a dive, just breathe to relax.
After each freedive take 3 recovery breaths
A recovery breath consists of a passive exhale, a short full inhale, and a brief hold. Repeat this 3 times. Make it a habit even on easy dives, so that you have the muscle memory for it when you need it.
Don't wear too much weight
A quick test of this is the "exhale test": if you exhale on the surface, do you sink or still float? If you sink, take off some weight.
Don't exhale before you reach the surface
Sometimes in scuba diving it is appropriate to exhale while ascending. Exhaling can also very temporarily relieve the discomfort of carbon dioxide in the lungs. But your one breath contains precious oxygen, and also contributes to your buoyancy, so hold it until you return to the surface.
Take your snorkel out of your mouth before you dive
Your snorkel will prevent you from taking quick, full recovery breaths, and can also allow water into your mouth in the event of a blackout.
Wear a lanyard
When diving on a line, deep or in low visibility, it is safest to clip yourself onto the line via a lanyard. Just like in rockclimbing, this lanyard prevents you from falling away from the line if you black out.
Reading these rules is not a substitute for taking a freediving class from a certified instructor.