Getting Started with Google Colab

Learn the fundamentals of Google Colab, a free cloud-based Jupyter Notebook environment, to write, run, and share Python code in your browser without any setup or installation.

Christian Mills


May 14, 2023


In this tutorial, I’ll introduce you to Google Colab, its features, and how to use it to run your code. Google Colab provides a free, cloud-based Jupyter Notebook environment that allows you to write, run, and share Python code in your browser without any setup or installation. A Jupyter Notebook is an interactive web-based tool for creating and sharing documents that contain live code, visualizations, and narrative text, often used in data analysis, visualization, and education.

Access Google Colab

To access Google Colab, follow these steps:

  1. Go to
  2. Sign in with your Google account. If you don’t have a Google account, create one here.


The Notebook Selection Window

After signing in, the Notebook Selection window will pop up. This window displays a list of your recent notebooks, allowing you to access and open them. If this is your first time using Google Colab, you will only see the “Welcome to Colaboratory” notebook listed. The Notebook Selection window also allows you to import Jupyter Notebooks from Google Drive and GitHub or upload a notebook from your computer.


The “Welcome to Colaboratory” notebook is already open behind the Notebook Selection window, so we’ll work with that one. Click the cancel button in the bottom right corner of the popup window to view the welcome notebook.


Understanding the Notebook Interface

A notebook consists of a list of cells. Google Colab notebooks have two main types of cells: code cells and text cells. Code cells allow you to write and run Python code, while text cells let you add formatted text, images, and equations using Markdown. The first few cells in the welcome notebook are text cells.


Text Cells

You can view and edit the Markdown source of a text cell by double-clicking it. In editor mode, Google Colab will show the Markdown source and the rendered version side-by-side.


We can edit the Markdown source, and the rendered version will update in real time.


You can exit the editor mode by pressing Shift+Enter, clicking the Close Markdown Editor icon in the top-right corner of the text cell, or clicking another cell.


To create a new text cell, click the + Text button in the toolbar.


Google Colab will add the new Markdown cell below the currently selected cell.


Code Cells

To create a new code cell, click the + Code button in the toolbar at the top of the notebook or press Ctrl+M B.


Google Colab will add the new code cell below the currently selected cell.


You can write Python code in the code cell and execute it by pressing Shift + Enter or clicking the Play button on the left side of the cell. Any output from the code will appear directly below the code cell.


We can also use code cells to access the command line by adding an exclamation point at the start of the cell. We can use this ability to install Python packages via the pip package installer.


Working with Data

Google Colab allows you to upload and download files to and from your computer and connect notebooks to your Google Drive.

Uploading Files

You can upload files from your local machine to use in your Google Colab notebook by following these steps:

  1. Click the Files icon in the left sidebar to open the file browser.

  1. Click the Upload button.

  1. Go to the file location on your local machine, select it, and click Open to upload it to your Google Colab workspace.

  1. Colab will display a warning that the runtime’s files get deleted when it terminates. Click OK in the bottom-right corner of the popup window.

  1. The uploaded file will appear in the file browser, and you can access it in your notebook.

  1. We can view the file by double-clicking it in the file browser or loading it in the notebook via Python.


Downloading Files

To download a file from your Google Colab workspace to your local machine, follow these steps:

  1. Locate the file in the file browser.
  2. Right-click the file and select Download.


The file will download to your local machine.

Connecting to Google Drive

Google Colab notebooks can connect to Google Drive to access, store, and manage your files. To do this, follow these steps:

  1. Click the Mount Drive button in the file browser.

  1. Google Colab will create a new code cell containing the following code:

    from google.colab import drive

  1. Run the code cell by pressing Shift + Enter or clicking the Play button on the left side of the cell. A popup window will appear, prompting you to authorize access to your Google Drive.

  1. Click the Connect to Google Drive button to open the authorization page.

  1. Sign in with your Google account, and click Allow to grant access.

  1. Return to your Google Colab notebook. The code cell should have printed a message indicating your Google Drive is now mounted.

  1. Click the Refresh button in the file browser to update the contents.


Your Google Drive should now be mounted and accessible from the file browser.


You can read, write, and manage your Google Drive files directly from your Google Colab notebook. To access the files, use the path /content/drive/MyDrive/ followed by the file or folder name.

Using Hardware Acceleration

Google Colab offers free access to GPUs and TPUs to accelerate your code. To enable GPU or TPU acceleration:

  1. Click the “Runtime” menu at the top of the notebook.

  1. Select “Change runtime type.”

  1. Choose “GPU” from the “Hardware accelerator” drop-down menu.

  1. Click “Save.”

  1. Changing the hardware accelerator requires loading a new runtime. Loading a new runtime will delete any files we added and disconnect Google Drive. Google Colab will show a popup window asking you to confirm you want to delete the current runtime. Click “OK” to confirm.

  1. Verify the notebook has GPU access by running the following code in a code cell:



Your notebook will now use the selected hardware accelerator. Note that free GPU and TPU usage is time-limited. You can run notebooks on the free tier for at most 12 hours at a time (usually less). If you exceed the time allotment, you must wait until it resets (typically about 12 hours). Therefore, only enable hardware acceleration when needed and disable it when you don’t. To disable hardware acceleration, select None from the Hardware Accelerator drop-down menu.


Create a New Notebook

To create a new notebook:

  1. Open the File menu in the top-left corner and select New notebook.


A new notebook will open in a separate tab. The runtime for the previous notebook is still active.


You can rename the notebook by clicking the notebook name at the top of the page. For now, we can name it “My First Notebook.”


Save Your Notebook

Google Colab automatically saves your notebooks to a “Colab Notebooks” folder in Google Drive.


Note the “Welcome to Colaboratory” notebook is not in the folder. Since we did not create that notebook, we must save our copy manually. Switch to that notebook’s tab and click the “Copy to Drive” button.


Google Colab will open our new copy of the notebook in a separate tab.


If we check the “Colab Notebooks” folder in Google Drive, we should now see our copy of the welcome notebook.


Sharing Notebooks

You can share your Google Colab notebook with others, similar to other Google Drive documents. To share your notebook:

  1. Click the “Share” button in the top-right corner of the notebook.

  1. In the sharing settings dialog box, enter the email address of the person you want to share the notebook with.

  1. Select their permission level: “Viewer,” “Commenter,” or “Editor.”


Alternatively, you can create a shareable link with specific access settings (view, comment, or edit). You can share this link with others, and they can access the notebook according to the chosen permission level.

  1. Open the drop-down menu under General Access and select the “Anyone with a link” option.

  1. Set the permission level: “Viewer,” “Commenter,” or “Editor.”

  1. Click “Copy link” to copy the shareable link.


Version Control with GitHub

Google Colab can save and load notebooks from GitHub repositories, enabling seamless collaboration and tracking of changes in your code.

Saving a notebook to a GitHub repository:

  1. Open the File menu in the top-left corner and select Save a copy in GitHub.

  1. If you haven’t connected your GitHub account yet, follow the prompts to authorize Google Colab to access your repositories.

  1. Choose a repository, branch, and file path for your notebook. You can also update the commit message.

  1. Click OK to save the notebook to the specified GitHub repository.


Loading a notebook from a GitHub repository:

  1. Go to the Google Colab website.


  1. Click the GitHub tab in the Notebook Selection window.

  1. Enter the URL for the GitHub repository containing the notebook you want to open. You can also search for one by entering a username or organization and repository name.

  1. Select the notebook you want to open, and it will open in a new tab.


You’ve now learned the fundamentals of Google Colab. This tutorial covered creating and editing cells, working with data, hardware acceleration, and saving and sharing notebooks via Google Drive and GitHub. Keep exploring Google Colab to uncover more features that can enhance your projects.

Next Steps
  • Feel free to post questions or problems related to this tutorial in the comments below. I try to make time to address them on Thursdays and Fridays.
  • If you would like to explore my services for your project, you can reach out via email at [email protected]