A system for invisible fencing for animals, that is a device mounted on animals. The device checks Global Navigation Satellite System (“GNSS”) position measurements against an area that is defined in the device. The area can be defined as a combination of several areas with different characteristics. An area may also be defined as dynamic. The system calculates the shortest distance to this area based on actual GNSS position. If position measurements show that the animal has a position that is outside the area, correction will be performed as a combination of audio signal and electric shock. The correction is made by increasing the audio frequency proportionally with the calculated distance to the area. When the audio frequency has reached an upper limit, one single electric shock is given, and possible further correction is resumed from the position where the electric shock was given.