To get Salesforce.com Organization ID, Go to Administration Setup –> Company Profile –> Company Information — > Salesforce.com Organization ID.

In Formula Field:

In Apex Class:
UserInfo.getOrganizationId();
In Visualforce page:
{!$Organization.Id}