How Many Spaces in a Tab? Defaults for Code, Word and Vim

November 11, 2026 · 10 min read

How Many Spaces in a Tab? Defaults in Code, Word and Editors

A tab is one character that jumps to the next tab stop, so it has no fixed width. That's why how many spaces in a tab depends on the program that displays it. Terminals put stops every 8 columns, most code editors use 4, and Word uses half an inch. Below are the defaults and the settings to change them.

How Many Spaces in a Tab? One Character, Many Widths

A tab is a single character, U+0009 (CHARACTER TABULATION), stored as one byte in ASCII and UTF-8. It doesn't contain spaces. When a program displays it, the cursor moves to the next tab stop, and the gap you see is whatever's left to reach that stop. For the characters that really are spaces, see the full list of Unicode space characters.

That's why the same tab looks wide in one place and narrow in another. Run this in a terminal:

printf 'a\tb\nabcdef\tb\n'

It prints:

a       b
abcdef  b

Both b characters land in column 9. The first tab fills 7 columns because it starts after one letter. The second fills only 2 because abcdef already used 6. Same character, different width.

So the honest answer to "how many spaces is a tab" is: as many as it takes to reach the next stop. Change the stop interval and every tab in the file redraws.

What Is Normal Tab Spacing? Defaults by Tool

Each program picks its own tab stop interval, and some also decide whether pressing Tab writes a tab character or spaces. Here are the defaults you'll meet most often:

Where you see the tabDefault tab widthWhat the Tab key writes
Unix terminal, POSIX expand8 columnsA tab character
Vim8 (tabstop)A tab character (expandtab off)
VS Code44 spaces
Sublime Text4 (tab_size)A tab, unless the file already uses spaces
Visual Studio4 (tab size and indent size)Spaces or tabs, set per language
Web browsers (CSS tab-size)8Not applicable
GitHub file viewYour tab size preference, or the repo's .editorconfigNot applicable
Microsoft WordA stop every 0.5 inchA tab character
CommonMark block structure4Not applicable

Eight is the traditional Unix default. The POSIX spec for expand says tabs sit 8 columns apart unless you pass -t, and Vim's tabstop also defaults to 8.

To swap a file's tabs for spaces in a terminal, run expand -t 4 notes.txt > notes-spaces.txt, and unexpand goes the other way.

Browsers use 8 too: the initial value of the CSS tab-size property is 8. Normal HTML collapses whitespace, so you only see it where tabs are kept, as in pre blocks or with white-space: pre-wrap. Our guide to NBSP and HTML whitespace shows exactly what gets collapsed.

Editors built for code moved to 4. VS Code's docs say it inserts spaces and uses 4 spaces per Tab keypress by default. Visual Studio's tab size and indent size both default to 4 as well.

Tab Width, Indent Size and Insert Spaces Are Three Settings

Most confusion comes from treating three separate settings as one. Editors name them differently, but most code editors expose all three:

  • Tab width is how wide a tab character displays. It changes nothing in the file.
  • Indent size is how far one Tab keypress, or one indent level, moves the cursor.
  • Insert spaces decides whether that keypress writes U+0009 or a run of spaces.

When indent size and tab width differ and the editor keeps tabs, the file ends up with both characters. Visual Studio's Keep tabs mode fills an indent with as many tab characters as fit, then pads with spaces. Vim maps the same three ideas onto tabstop, shiftwidth and expandtab.

This is the usual cause of code that looks fine in your editor and ragged on GitHub. You wrote a mix of tabs and spaces at width 4, and the viewer redrew the tabs at 8. Pick spaces or tabs per project, and the problem goes away.

How Do I Change the Default Tab Size in VS Code?

Open the Command Palette, run Preferences: Open User Settings (JSON), and add:

{
  "editor.tabSize": 2,
  "editor.insertSpaces": true,
  "editor.detectIndentation": false,
  "[python]": {
    "editor.tabSize": 4
  }
}

This makes every Tab keypress insert 2 spaces, except in Python files, which get 4. The bracketed [python] key is VS Code's per-language override, and you can add one for any language ID.

The third line matters more than it looks. With editor.detectIndentation on (the default), VS Code reads each file and uses whatever indentation it finds, which overrides your editor.tabSize. The docs note detection only recognises 2, 4, 6 or 8 spaces, so a 3-space codebase needs detection off.

To change indentation in a file you already have, click the Spaces: 4 or Tab Size: 4 label in the status bar. It opens a menu with Indent Using Spaces, Indent Using Tabs, Convert Indentation to Spaces and Convert Indentation to Tabs. The same commands are in the Command Palette.

Setting Tab Width in Vim and Sublime Text

In Vim, put this in your .vimrc:

set tabstop=4 shiftwidth=4 softtabstop=4 expandtab
autocmd FileType make setlocal noexpandtab

The first line displays tabs at 4 columns, indents by 4, makes Tab and Backspace move 4 columns, and writes spaces. The second line keeps real tabs in Makefiles. To convert an existing file to your new settings, run :retab, and use :set list to see where tabs are (Vim shows them as ^I).

In Sublime Text, open Preferences > Settings and add these keys to the user file on the right:

{
  "tab_size": 4,
  "translate_tabs_to_spaces": true,
  "detect_indentation": false
}

Like VS Code, Sublime guesses indentation from each file it opens, so turn detect_indentation off if you want your values to win. The View > Indentation menu sets tab width for the current file and converts its indentation between tabs and spaces.

One .editorconfig File for Every Editor

Editor settings only apply on your machine. An .editorconfig file in the repository root applies the same rules for everyone who opens the project:

root = true

[*]
indent_style = space
indent_size = 4

[*.{js,json,yml,yaml}]
indent_size = 2

[Makefile]
indent_style = tab
tab_width = 8

Every file gets 4-space indents, JavaScript, JSON and YAML files get 2, and Makefiles keep real tabs displayed at 8 columns. The EditorConfig spec says tab_width defaults to indent_size, so you only set it when the two should differ. root = true stops the search for parent config files.

Per editorconfig.org, Visual Studio, Vim, Neovim and GitHub read the file natively, while VS Code and Sublime Text need the EditorConfig plugin. In Vim, add packadd! editorconfig to your .vimrc to switch on the bundled package. GitHub uses the file when it draws tabs in its code view.

We prefer spaces plus an .editorconfig in every repo, with tabs only where a format demands them. Spaces look the same in every viewer, and the config file settles the 2 versus 4 question once instead of in every code review. For Markdown files, a Markdown formatter such as Prettier can normalise list indentation along with the rest of the layout.

When the File Format Picks for You: Python, Go, Make and YAML

Some formats don't leave the choice to you.

  • Python: PEP 8 asks for 4 spaces per indentation level and calls spaces the preferred method. Python 3 raises TabError when a file mixes tabs and spaces inconsistently.
  • Go: Effective Go says Go uses tabs for indentation and gofmt emits them by default, so running it settles the question for you.
  • Make: the GNU make manual says each recipe line must start with a tab, or the character set in .RECIPEPREFIX. Spaces there cause the classic missing separator error.
  • YAML: the YAML 1.2.2 spec forbids tab characters in indentation, so YAML files must use spaces.

A tab in Markdown also counts. The CommonMark spec treats a leading tab as reaching a tab stop of 4 when working out block structure, so one tab can start an indented code block. Our guide to how tabs behave in Markdown indentation covers lists and nesting, and the Markdown code block guide compares indented and fenced blocks.

Many teams ban hard tabs in Markdown altogether with the MD010 rule, which our Markdown style guide explains. The Markdown linter runs that same markdownlint rule set in your browser.

How Many Spaces Is a Tab in Word and Google Docs?

In Word, a tab isn't measured in characters at all. In US versions, default tab stops sit every 0.5 inch, and pressing Tab moves to the next one. To change the interval, open the Paragraph dialog from the Home tab, click Tabs, and edit Default tab stops. That change applies to the current document unless you also save it in the Normal template.

You can still estimate the count. Half an inch is 36 points. In 12 pt Times New Roman, a space is exactly a quarter of an em, or 3 points, so a default tab spans about 12 spaces. In 12 pt Arial the space is slightly wider, which gives about 11.

That's also why lining up text with the space bar fails in a word processor. Proportional fonts give characters different widths, so columns drift. Use real tab stops, or a table.

Google Docs works the same way: tabs jump to stops, not to a number of characters. Turn on View > Show ruler and click the ruler to add your own left, center or right stop. For a school paper, MLA's half-inch first-line indent belongs in the paragraph indent setting, not in typed spaces.

Quick Answers on Tab Spacing

So how many spaces in a tab comes down to which program draws it. Expect 8 in terminals, Vim and browsers, 4 in most code editors, and half an inch in Word. Set the width you want in your editor, commit an .editorconfig, and let formats like Make and YAML decide where they must. To check how an indented block renders in Markdown, paste it into the editor and watch the live preview.