Summary:
Once you or another civ have discovered Writing, you can enter into an Open Borders agreement with that civ. (City-States can't make Open Borders agreements.) While an Open Borders agreement is in effect, the other civ's units can enter your territory without automatically triggering war. If the agreement is mutual, either civ's units can enter the other's territory freely; however it doesn't have to be mutual: one civ can grant another Open Borders without automatically receiving it in return.
An Open Borders agreement lasts for 30 turns (on standard speed). When 30 turns have passed, the agreement must be renegotiated or it lapses.