NOTE: I don't take credit for these, these are a summary of what's out there!
So getting the ID can be done a number of ways - first, using the "API" (if using SharePoint Online, authenticate to the site first):
Next using on premise PowerShell:
$site = Get-SPSite http://<site & port>
$web = $site.AllWebs["<name of site>"]
In SharePoint Online using the SharePoint Online Management Shell:
Connect-SPOService -URL https://<org>-admin.sharepoint.com
Enter your credentials, then enter:
Get-SPOSite -Identity https://<site>.SharePoint.com
Next connect to the site:
Connect-SPOSite -Url "https://<site>.sharepoint.com/" -Credential "<email@example.com>"
If you omit -Credential, you will be prompted (the credential is your EMAIL address <firstname.lastname@example.org>, not the AD account domain\account) but better to use this:
$username = "<email@example.com>"
$password = "<password>"
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $(ConvertTo-SecureString $password -AsPlainText -Force)
Connect-SPOSite -Url "https://<site>.sharepoint.com/" -Credential $cred
Then finally for the top level web:
Get-SPOWeb -Identity "/"
For a subsite, use the name:
Get-SPOWeb -Identity "News"
Get-SPOWeb will list out details of the web - just look for the "Id" column.
Note - if using a Subsite under /Sites/, you have to connect to that site collection (instead of https://<site>.SharePoint.com, you use https://<site>.SharePoint.com/sites/subcollection".
Another way is through the URL. Open the site/web you want and open Site Settings. Click either the Site Content and Structure or Content and Structure Logs link. Click on the web in question and select the drop down then select General Settings - cut and paste the URL into notepad - you will find the ID in the query string after SPWeb (%3A = : - see here http://www.degraeve.com/reference/urlencoding.php). Here's snip of the URL where the SPWeb can be found:
Yet another is using jQuery - found on the MSDN site: