Get Started with Google Colab for Free Python Notebooks

Run Python in your browser with free GPU access — no setup, no installs, just coding.

What is Google Colab?

Google Colaboratory (Colab) is a free, cloud-based Jupyter notebook environment that runs entirely in your browser. It requires zero setup — no Python installation, no package management, no configuration. Colab gives you free access to GPUs and TPUs for machine learning, data science, and general Python scripting. Notebooks are saved to Google Drive, so your work persists across sessions and can be shared like any Google Doc. Whether you're learning Python, prototyping a model, or analyzing a dataset, Colab is the fastest way to start coding.

Step 1. Open Colab

Getting into Colab takes seconds:

  • •Navigate to colab.research.google.com in any modern browser.
  • •Sign in with your Google account — this is required to save notebooks to your Google Drive.
  • •Click New Notebook in the bottom-right corner of the welcome dialog to create a blank notebook, or open an existing .ipynb file from your Drive.
  • •The notebook opens with a single empty code cell, ready for your first line of Python.

Step 2. The Notebook Interface

Colab's interface is built around two types of cells. Understanding them is key to working efficiently:

  • •Code cells: Where you write and execute Python. Each cell runs independently but shares variables, imports, and state with the rest of the notebook.
  • •Text cells: Markdown-formatted cells for headings, explanations, and documentation. Use them to narrate your analysis and keep notebooks readable.
  • •The Run button (play icon) executes the current cell. Each cell shows its output directly below — print statements, charts, data tables, and error messages all appear inline.
  • •The runtime indicator in the top-right shows connection status (Connected, Reconnecting, or Disconnected) and the current hardware (CPU, GPU, or TPU).

Step 3. Write and Run Python

Colab works like any Python REPL, but with persistent state across cells. Try these basics:

  • •Type print("Hello, world!") into the first code cell and press Shift+Enter to run it. The output appears below.
  • •Create variables and use them across cells — for example, define name = "StarCaller" in one cell and reference it in the next.
  • •Shift+Enter runs the current cell and moves to the next one. Ctrl+Enter (or Cmd+Enter on Mac) runs the cell and stays in place.
  • •The last expression in a cell is automatically printed — no need for print() when you just want to see a value.

# Run this in your first cell (press Shift+Enter) print("Hello, world!") name = "StarCaller" print(f"Welcome, {name}!") # In the next cell, the variable still exists print(f"Hello again, {name}!") # Output: Hello again, StarCaller!

Step 4. Install Packages

Colab comes with most popular Python libraries pre-installed, but you can install additional packages with pip — just prefix commands with !:

  • •The exclamation mark (!) tells Colab to run the command as a shell command rather than Python code.
  • •Install the data science essentials: !pip install pandas numpy matplotlib in a single cell.
  • •Use !pip list to see all currently installed packages and their versions.
  • •Note that installations don't persist across sessions — you'll need to re-install any non-default packages each time you reconnect to a runtime.

!pip install pandas numpy matplotlib seaborn scikit-learn

Step 5. Upload and Access Files

You'll often need to work with external data. Colab provides several ways to bring files into your notebook:

  • •Use the file upload button in the left sidebar (folder icon) to drag and drop files directly into the runtime. They appear in the /content/ directory.
  • •Mount Google Drive for persistent storage across sessions. Click the Drive icon in the sidebar or run the mount cell that Colab provides — your entire Drive appears under /content/drive/.
  • •Read a CSV file with pandas: import pandas as pd; df = pd.read_csv('/content/myfile.csv') — then use df.head() to preview.
  • •Download files from the web directly: !wget https://example.com/data.csv pulls files into the /content/ directory.

Step 6. Use a Free GPU

Colab's killer feature is free GPU access — perfect for machine learning, deep learning, and heavy number crunching:

  • •Go to Runtime → Change runtime type in the menu bar. Under "Hardware accelerator," select T4 GPU from the dropdown.
  • •Click Save — Colab will restart your runtime with GPU-enabled hardware. This takes only a few seconds.
  • •Verify the GPU is active by running !nvidia-smi in a code cell. You should see a Tesla T4 with its memory and driver details.
  • •Free GPU limits: Usage is subject to availability. Heavy users may experience slower allocations or temporarily fall back to CPU. Colab Pro offers priority access and better GPUs.

# Verify your GPU is active !nvidia-smi # Expected output shows Tesla T4 with ~15GB VRAM

Quick Tips

  • •Sessions timeout after ~90 minutes of idle time. If you step away for too long, the runtime disconnects and your in-memory state is lost. Save your work and reinstall packages when reconnecting.
  • •Mount Google Drive for persistence. Notebooks are auto-saved to Drive, but data files and model checkpoints should be written to your Drive mount (/content/drive/MyDrive/) to survive session restarts.
  • •Prefix shell commands with !. Any line starting with ! runs as a bash command — use this for !ls, !git clone, !wget, and more.

Visual Walkthrough

Slide 1
1 / 13

Need More Help?

Colab is just the beginning. Check out our guides on data science, machine learning, and Python programming to level up your skills.

Browse All Guides