You can leave the container at the port (after discharge from the vessel) for up to 5 free days and then you get charged demurrage.
You can have the container for up to 3 free days detention before you have to return it to the terminal.
The detention time starts as soon as the container leaves the terminal, even if you remove before the 5 free demurrage days have passed.
Please let me know if you have any questions.